2N/A/* grub-setup.c - make GRUB usable */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
2N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <config.h>
2N/A#include <grub/types.h>
2N/A#include <grub/emu/misc.h>
2N/A#include <grub/util/misc.h>
2N/A#include <grub/device.h>
2N/A#include <grub/disk.h>
2N/A#include <grub/file.h>
2N/A#include <grub/fs.h>
2N/A#include <grub/partition.h>
2N/A#include <grub/env.h>
2N/A#include <grub/emu/hostdisk.h>
2N/A#include <grub/machine/boot.h>
2N/A#include <grub/machine/kernel.h>
2N/A#include <grub/term.h>
2N/A#include <grub/i18n.h>
2N/A#include <grub/util/lvm.h>
2N/A#ifdef GRUB_MACHINE_IEEE1275
2N/A#include <grub/util/ofpath.h>
2N/A#endif
2N/A
2N/A#include <stdio.h>
2N/A#include <unistd.h>
2N/A#include <string.h>
2N/A#include <stdlib.h>
2N/A#include <sys/types.h>
2N/A#include <sys/stat.h>
2N/A#include <dirent.h>
2N/A#include <assert.h>
2N/A#include <grub/emu/getroot.h>
2N/A#include "progname.h"
2N/A#include <grub/reed_solomon.h>
2N/A#include <grub/msdos_partition.h>
2N/A#include <include/grub/crypto.h>
2N/A#ifdef __sun__
2N/A#include <multiboot.h>
2N/A#endif
2N/A
2N/A#define _GNU_SOURCE 1
2N/A#include <argp.h>
2N/A
2N/A/* On SPARC this program fills in various fields inside of the 'boot' and 'core'
2N/A * image files.
2N/A *
2N/A * The 'boot' image needs to know the OBP path name of the root
2N/A * device. It also needs to know the initial block number of
2N/A * 'core' (which is 'diskboot' concatenated with 'kernel' and
2N/A * all the modules, this is created by grub-mkimage). This resulting
2N/A * 'boot' image is 512 bytes in size and is placed in the second block
2N/A * of a partition.
2N/A *
2N/A * The initial 'diskboot' block acts as a loader for the actual GRUB
2N/A * kernel. It contains the loading code and then a block list.
2N/A *
2N/A * The block list of 'core' starts at the end of the 'diskboot' image
2N/A * and works it's way backwards towards the end of the code of 'diskboot'.
2N/A *
2N/A * We patch up the images with the necessary values and write out the
2N/A * result.
2N/A */
2N/A
2N/A#define DEFAULT_BOOT_FILE "boot.img"
2N/A#define DEFAULT_CORE_FILE "core.img"
2N/A
2N/A#ifdef GRUB_MACHINE_SPARC64
2N/A#define grub_target_to_host16(x) grub_be_to_cpu16(x)
2N/A#define grub_target_to_host32(x) grub_be_to_cpu32(x)
2N/A#define grub_target_to_host64(x) grub_be_to_cpu64(x)
2N/A#define grub_host_to_target16(x) grub_cpu_to_be16(x)
2N/A#define grub_host_to_target32(x) grub_cpu_to_be32(x)
2N/A#define grub_host_to_target64(x) grub_cpu_to_be64(x)
2N/A#elif defined (GRUB_MACHINE_PCBIOS)
2N/A#define grub_target_to_host16(x) grub_le_to_cpu16(x)
2N/A#define grub_target_to_host32(x) grub_le_to_cpu32(x)
2N/A#define grub_target_to_host64(x) grub_le_to_cpu64(x)
2N/A#define grub_host_to_target16(x) grub_cpu_to_le16(x)
2N/A#define grub_host_to_target32(x) grub_cpu_to_le32(x)
2N/A#define grub_host_to_target64(x) grub_cpu_to_le64(x)
2N/A#else
2N/A#error Complete this
2N/A#endif
2N/A
2N/Aconst char *current_device;
2N/A
2N/Astatic void
2N/Awrite_rootdev (char *core_img, grub_device_t root_dev,
2N/A char *boot_img, grub_uint64_t first_sector)
2N/A{
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A {
2N/A grub_uint8_t *boot_drive;
2N/A grub_disk_addr_t *kernel_sector;
2N/A boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
2N/A kernel_sector = (grub_disk_addr_t *) (boot_img
2N/A + GRUB_BOOT_MACHINE_KERNEL_SECTOR);
2N/A
2N/A /* FIXME: can this be skipped? */
2N/A *boot_drive = 0xFF;
2N/A
2N/A *kernel_sector = grub_cpu_to_le64 (first_sector);
2N/A }
2N/A#endif
2N/A#ifdef GRUB_MACHINE_IEEE1275
2N/A {
2N/A grub_disk_addr_t *kernel_byte;
2N/A kernel_byte = (grub_disk_addr_t *) (boot_img
2N/A + GRUB_BOOT_AOUT_HEADER_SIZE
2N/A + GRUB_BOOT_MACHINE_KERNEL_BYTE);
2N/A *kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS);
2N/A }
2N/A#endif
2N/A}
2N/A
2N/A#ifdef GRUB_MACHINE_IEEE1275
2N/A#define BOOT_SECTOR 1
2N/A#else
2N/A#define BOOT_SECTOR 0
2N/A#endif
2N/A
2N/A#ifdef __sun__
2N/A#include "grub-solvers.c"
2N/A#endif
2N/A
2N/Astatic void
2N/Asetup (const char *dir,
2N/A const char *boot_file, const char *core_file,
2N/A const char *root, const char *dest, int must_embed, int force, int fs_probe,
2N/A int allow_floppy, int force_mbr, int dry_run
2N/A#ifdef __sun__
2N/A , char *version_spec
2N/A#endif
2N/A )
2N/A{
2N/A char *boot_path, *core_path, *core_path_dev, *core_path_dev_full;
2N/A char *boot_img, *core_img;
2N/A size_t boot_size, core_size;
2N/A grub_uint16_t core_sectors;
2N/A grub_device_t mbr_dev;
2N/A grub_device_t root_dev, dest_dev;
2N/A struct grub_boot_blocklist *first_block, *block;
2N/A char *tmp_img;
2N/A int i;
2N/A grub_disk_addr_t first_sector;
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A grub_uint16_t current_segment
2N/A = GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
2N/A#endif
2N/A grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
2N/A grub_file_t file;
2N/A FILE *fp;
2N/A#ifdef __sun__
2N/A int got_embed_region = 0;
2N/A#endif
2N/A
2N/A auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
2N/A unsigned offset,
2N/A unsigned length);
2N/A auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
2N/A unsigned offset,
2N/A unsigned length);
2N/A
2N/A void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector,
2N/A unsigned offset,
2N/A unsigned length)
2N/A {
2N/A grub_util_info ("the first sector is <%llu,%u,%u>",
2N/A sector, offset, length);
2N/A
2N/A if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("the first sector of the core file is not sector-aligned"));
2N/A
2N/A first_sector = sector;
2N/A }
2N/A
2N/A void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector,
2N/A unsigned offset,
2N/A unsigned length)
2N/A {
2N/A struct grub_boot_blocklist *prev = block + 1;
2N/A
2N/A grub_util_info ("saving <%llu,%u,%u>", sector, offset, length);
2N/A
2N/A if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("non-sector-aligned data is found in the core file"));
2N/A
2N/A if (block != first_block
2N/A && (grub_target_to_host64 (prev->start)
2N/A + grub_target_to_host16 (prev->len)) == sector)
2N/A prev->len = grub_host_to_target16 (grub_target_to_host16 (prev->len) + 1);
2N/A else
2N/A {
2N/A block->start = grub_host_to_target64 (sector);
2N/A block->len = grub_host_to_target16 (1);
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A block->segment = grub_host_to_target16 (current_segment);
2N/A#endif
2N/A
2N/A block--;
2N/A if (block->len)
2N/A grub_util_error (_("the sectors of the core file are too fragmented"));
2N/A }
2N/A
2N/A last_length = length;
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
2N/A#endif
2N/A }
2N/A
2N/A /* Read the boot image by the OS service. */
2N/A boot_path = grub_util_get_path (dir, boot_file);
2N/A boot_size = grub_util_get_image_size (boot_path);
2N/A if (boot_size != GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("the size of `%s' is not %u"),
2N/A boot_path, GRUB_DISK_SECTOR_SIZE);
2N/A boot_img = grub_util_read_image (boot_path);
2N/A free (boot_path);
2N/A
2N/A core_path = grub_util_get_path (dir, core_file);
2N/A core_size = grub_util_get_image_size (core_path);
2N/A core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
2N/A >> GRUB_DISK_SECTOR_BITS);
2N/A if (core_size < GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("the size of `%s' is too small"), core_path);
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("the size of `%s' is too large"), core_path);
2N/A#endif
2N/A
2N/A core_img = grub_util_read_image (core_path);
2N/A
2N/A /* Have FIRST_BLOCK to point to the first blocklist. */
2N/A first_block = (struct grub_boot_blocklist *) (core_img
2N/A + GRUB_DISK_SECTOR_SIZE
2N/A - sizeof (*block));
2N/A grub_util_info ("root is `%s', dest is `%s'", root, dest);
2N/A
2N/A /* Open the root device and the destination device. */
2N/A grub_util_info ("Opening root");
2N/A root_dev = grub_device_open (root);
2N/A if (! root_dev)
2N/A grub_util_error ("%s", _(grub_errmsg));
2N/A
2N/A grub_util_info ("Opening dest");
2N/A dest_dev = grub_device_open (dest);
2N/A if (! dest_dev)
2N/A grub_util_error ("%s", _(grub_errmsg));
2N/A
2N/A
2N/A grub_util_info ("setting the root device to `%s'", root);
2N/A if (grub_env_set ("root", root) != GRUB_ERR_NONE)
2N/A grub_util_error ("%s", _(grub_errmsg));
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A {
2N/A grub_partition_map_t dest_partmap = NULL;
2N/A grub_partition_t container = dest_dev->disk->partition;
2N/A int multiple_partmaps = 0;
2N/A grub_err_t err;
2N/A grub_disk_addr_t *sectors;
2N/A int i;
2N/A grub_fs_t fs;
2N/A unsigned int nsec;
2N/A
2N/A /* Unlike root_dev, with dest_dev we're interested in the partition map even
2N/A if dest_dev itself is a whole disk. */
2N/A auto int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk,
2N/A const grub_partition_t p);
2N/A int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
2N/A const grub_partition_t p)
2N/A {
2N/A if (p->parent != container)
2N/A return 0;
2N/A /* NetBSD and OpenBSD subpartitions have metadata inside a partition,
2N/A so they are safe to ignore.
2N/A */
2N/A if (grub_strcmp (p->partmap->name, "netbsd") == 0
2N/A || grub_strcmp (p->partmap->name, "openbsd") == 0)
2N/A return 0;
2N/A if (dest_partmap == NULL)
2N/A {
2N/A dest_partmap = p->partmap;
2N/A return 0;
2N/A }
2N/A if (dest_partmap == p->partmap)
2N/A return 0;
2N/A multiple_partmaps = 1;
2N/A return 1;
2N/A }
2N/A
2N/A#ifdef __sun__
2N/A if (version_spec)
2N/A core_sectors += 2; /* Add 2 extra sectors for versioning info */
2N/A#endif
2N/A nsec = core_sectors;
2N/A err = GRUB_ERR_NONE;
2N/A
2N/A#ifdef __sun__
2N/A if (dest_dev->disk->partition &&
2N/A strcmp(dest_dev->disk->partition->partmap->name, "sunpc") == 0)
2N/A {
2N/A if (dest_dev->disk->partition->parent &&
2N/A strcmp(dest_dev->disk->partition->parent->partmap->name, "msdos") == 0)
2N/A {
2N/A dest_partmap = dest_dev->disk->partition->partmap;
2N/A /*
2N/A * sunpc embed function will replace dest_dev->disk->partition with boot slice partition
2N/A * if boot slice is not given on command line
2N/A */
2N/A err = dest_partmap->embed (dest_dev->disk, &nsec, GRUB_EMBED_PCBIOS, &sectors);
2N/A got_embed_region = 1;
2N/A }
2N/A }
2N/A else if (dest_dev->disk->partition &&
2N/A strcmp(dest_dev->disk->partition->partmap->name, "msdos") == 0 &&
2N/A (dest_dev->disk->partition->msdostype == GRUB_PC_PARTITION_SUNIXOS
2N/A || dest_dev->disk->partition->msdostype == GRUB_PC_PARTITION_LEGACY_SUNIXOS))
2N/A {
2N/A struct grub_partition_map *partmap;
2N/A
2N/A FOR_PARTITION_MAPS(partmap)
2N/A if (grub_strcmp(partmap->name ,"sunpc") == 0)
2N/A dest_partmap = partmap;
2N/A
2N/A if (dest_partmap == NULL)
2N/A {
2N/A grub_util_warn ("%s", "could not find sunpc embed function");
2N/A grub_errno = GRUB_ERR_NONE;
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A /* sunpc embed function will replace dest_dev->disk->partition with boot slice partition */
2N/A err = dest_partmap->embed (dest_dev->disk, &nsec, GRUB_EMBED_PCBIOS, &sectors);
2N/A got_embed_region = 1;
2N/A }
2N/A if (got_embed_region)
2N/A {
2N/A if (err)
2N/A {
2N/A grub_util_warn ("%s", grub_errmsg);
2N/A grub_errno = GRUB_ERR_NONE;
2N/A goto unable_to_embed;
2N/A }
2N/A container = dest_dev->disk->partition;
2N/A
2N/A /* we don't have grandparent info */
2N/A if (dest_dev->disk->partition->parent->number > 3)
2N/A {
2N/A /* inside an extended partition. set force_mbr */
2N/A if (force_mbr == 0)
2N/A {
2N/A grub_util_warn("Installing GRUB2 into an extended partition... "
2N/A "forcing MBR update");
2N/A force_mbr = 1;
2N/A }
2N/A }
2N/A }
2N/A
2N/A if (dest_partmap == NULL)
2N/A#endif
2N/A grub_partition_iterate (dest_dev->disk, identify_partmap);
2N/A
2N/A if (container && grub_strcmp (container->partmap->name, "msdos") == 0
2N/A && dest_partmap
2N/A && (container->msdostype == GRUB_PC_PARTITION_TYPE_NETBSD
2N/A || container->msdostype == GRUB_PC_PARTITION_TYPE_OPENBSD))
2N/A {
2N/A grub_util_warn (_("Attempting to install GRUB to a disk with multiple partition labels or both partition label and filesystem. This is not supported yet."));
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A fs = grub_fs_probe (dest_dev);
2N/A if (!fs)
2N/A grub_errno = GRUB_ERR_NONE;
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A if (fs_probe)
2N/A {
2N/A if (!fs && !dest_partmap)
2N/A grub_util_error (_("unable to identify a filesystem in %s; safety check can't be performed"),
2N/A dest_dev->disk->name);
2N/A if (fs && !fs->reserved_first_sector)
2N/A grub_util_error (_("%s appears to contain a %s filesystem which isn't known to "
2N/A "reserve space for DOS-style boot. Installing GRUB there could "
2N/A "result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
2N/A "by grub-setup (--skip-fs-probe disables this "
2N/A "check, use at your own risk)"), dest_dev->disk->name, fs->name);
2N/A
2N/A if (dest_partmap && strcmp (dest_partmap->name, "msdos") != 0
2N/A && strcmp (dest_partmap->name, "gpt") != 0
2N/A && strcmp (dest_partmap->name, "bsd") != 0
2N/A && strcmp (dest_partmap->name, "netbsd") != 0
2N/A && strcmp (dest_partmap->name, "openbsd") != 0
2N/A && strcmp (dest_partmap->name, "sunpc") != 0)
2N/A grub_util_error (_("%s appears to contain a %s partition map which isn't known to "
2N/A "reserve space for DOS-style boot. Installing GRUB there could "
2N/A "result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
2N/A "by grub-setup (--skip-fs-probe disables this "
2N/A "check, use at your own risk)"), dest_dev->disk->name, dest_partmap->name);
2N/A }
2N/A#endif
2N/A
2N/A if (force_mbr)
2N/A {
2N/A char *mbr_dest = strdup(dest);
2N/A char *comma = strchr(mbr_dest, ',');
2N/A if (comma)
2N/A {
2N/A *comma = 0;
2N/A mbr_dev = grub_device_open(mbr_dest);
2N/A if (! mbr_dev)
2N/A grub_util_error ("%s", grub_errmsg);
2N/A }
2N/A else
2N/A mbr_dev = NULL;
2N/A }
2N/A else
2N/A mbr_dev = NULL;
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A /* Read the original sector from the disk. */
2N/A tmp_img = xmalloc (GRUB_DISK_SECTOR_SIZE);
2N/A if (grub_disk_read ((mbr_dev ? : dest_dev)->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
2N/A grub_util_error ("%s", grub_errmsg);
2N/A#endif
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A {
2N/A grub_uint16_t *boot_drive_check;
2N/A boot_drive_check = (grub_uint16_t *) (boot_img
2N/A + GRUB_BOOT_MACHINE_DRIVE_CHECK);
2N/A /* Copy the possible DOS BPB. */
2N/A memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
2N/A tmp_img + GRUB_BOOT_MACHINE_BPB_START,
2N/A GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
2N/A
2N/A /* If DEST_DRIVE is a hard disk, enable the workaround, which is
2N/A for buggy BIOSes which don't pass boot drive correctly. Instead,
2N/A they pass 0x00 or 0x01 even when booted from 0x80. */
2N/A if (!allow_floppy && !grub_util_biosdisk_is_floppy ((mbr_dev ? : dest_dev)->disk))
2N/A /* Replace the jmp (2 bytes) with double nop's. */
2N/A *boot_drive_check = 0x9090;
2N/A }
2N/A#endif
2N/A /* Copy the partition table. */
2N/A if (dest_partmap ||
2N/A (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk)))
2N/A memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
2N/A tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
2N/A GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
2N/A
2N/A free (tmp_img);
2N/A
2N/A if (! dest_partmap && ! fs)
2N/A {
2N/A grub_util_warn (_("Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea."));
2N/A goto unable_to_embed;
2N/A }
2N/A if (multiple_partmaps || (dest_partmap && fs))
2N/A {
2N/A grub_util_warn (_("A %s%sfilesystem was detected in %s"), fs->name ? : "", fs->name ? " " : "", current_device);
2N/A grub_util_warn (_("If this is unexpected, the device should be carefully erased to remove all traces of the filesystem before GRUB can be installed"));
2N/A grub_util_warn (_("Additionally, multiple partition schemes have been detected. This combination is not supported and GRUB cannot be installed"));
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A if (dest_partmap && !dest_partmap->embed)
2N/A {
2N/A grub_util_warn (_("Partition style '%s' doesn't support embeding"),
2N/A dest_partmap->name);
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A if (fs && !fs->embed)
2N/A {
2N/A grub_util_warn (_("File system '%s' doesn't support embeding"),
2N/A fs->name);
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A#ifdef __sun__
2N/A if (got_embed_region == 1)
2N/A {
2N/A err = 0;
2N/A }
2N/A else
2N/A#endif
2N/A {
2N/A if (dest_partmap)
2N/A err = dest_partmap->embed (dest_dev->disk, &nsec,
2N/A GRUB_EMBED_PCBIOS, &sectors);
2N/A else
2N/A err = fs->embed (dest_dev, &nsec,
2N/A GRUB_EMBED_PCBIOS, &sectors);
2N/A
2N/A if (!err && nsec < core_sectors)
2N/A {
2N/A err = grub_error (GRUB_ERR_OUT_OF_RANGE,
2N/A N_("Your embedding area is unusually small. "
2N/A "core.img won't fit in it."));
2N/A }
2N/A }
2N/A
2N/A
2N/A if (err)
2N/A {
2N/A grub_util_warn ("%s", _(grub_errmsg));
2N/A grub_errno = GRUB_ERR_NONE;
2N/A goto unable_to_embed;
2N/A }
2N/A
2N/A if (nsec > 2 * core_sectors)
2N/A nsec = 2 * core_sectors;
2N/A if (nsec > ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR)
2N/A >> GRUB_DISK_SECTOR_BITS))
2N/A nsec = ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR)
2N/A >> GRUB_DISK_SECTOR_BITS);
2N/A
2N/A /* Clean out the blocklists. */
2N/A block = first_block;
2N/A while (block->len)
2N/A {
2N/A grub_memset (block, 0, sizeof (block));
2N/A
2N/A block--;
2N/A
2N/A if ((char *) block <= core_img)
2N/A grub_util_error (_("No terminator in the core image"));
2N/A }
2N/A
2N/A save_first_sector (sectors[0] + grub_partition_get_start (container),
2N/A 0, GRUB_DISK_SECTOR_SIZE);
2N/A
2N/A block = first_block;
2N/A for (i = 1; i < nsec; i++)
2N/A save_blocklists (sectors[i] + grub_partition_get_start (container),
2N/A 0, GRUB_DISK_SECTOR_SIZE);
2N/A
2N/A write_rootdev (core_img, root_dev, boot_img, first_sector);
2N/A
2N/A core_img = realloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE);
2N/A first_block = (struct grub_boot_blocklist *) (core_img
2N/A + GRUB_DISK_SECTOR_SIZE
2N/A - sizeof (*block));
2N/A
2N/A size_t new_core_size = core_size;
2N/A
2N/A#ifdef __sun__
2N/A if (version_spec)
2N/A {
2N/A grub_uint32_t *ptr;
2N/A
2N/A grub_solaris_get_size_with_versioning(core_img, core_size,
2N/A nsec * GRUB_DISK_SECTOR_SIZE, version_spec, &new_core_size);
2N/A
2N/A /* Now update the multiboot header with the new size */
2N/A for (ptr = (grub_uint32_t *) core_img;
2N/A ptr < (grub_uint32_t *) (core_img + MULTIBOOT_SEARCH); ptr++)
2N/A {
2N/A if (*ptr == grub_host_to_target32 (MULTIBOOT_HEADER_MAGIC)
2N/A && (grub_target_to_host32 (ptr[0]) +
2N/A grub_target_to_host32 (ptr[1]) +
2N/A grub_target_to_host32 (ptr[2])) == 0)
2N/A {
2N/A struct multiboot_header *multiboot_hdr;
2N/A multiboot_hdr = (struct multiboot_header *)ptr;
2N/A multiboot_hdr->load_end_addr = multiboot_hdr->load_addr +
2N/A core_size;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A }
2N/A#endif
2N/A
2N/A#if 0
2N/A *(grub_uint32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
2N/A + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY)
2N/A = grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - new_core_size);
2N/A#endif
2N/A
2N/A#ifdef __sun__
2N/A if (version_spec)
2N/A {
2N/A grub_solaris_add_versioning_payload(core_img, core_size,
2N/A nsec * GRUB_DISK_SECTOR_SIZE, version_spec);
2N/A }
2N/A#endif
2N/A
2N/A#if 0
2N/A void *tmp = xmalloc (new_core_size);
2N/A grub_memcpy (tmp, core_img, new_core_size);
2N/A
2N/A grub_reed_solomon_add_redundancy (core_img + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART + GRUB_DISK_SECTOR_SIZE,
2N/A new_core_size - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART - GRUB_DISK_SECTOR_SIZE,
2N/A nsec * GRUB_DISK_SECTOR_SIZE
2N/A - new_core_size);
2N/A assert (grub_memcmp (tmp, core_img, new_core_size) == 0);
2N/A free (tmp);
2N/A#endif
2N/A
2N/A /* Make sure that the second blocklist is a terminator. */
2N/A block = first_block - 1;
2N/A block->start = 0;
2N/A block->len = 0;
2N/A block->segment = 0;
2N/A
2N/A /* Write the core image onto the disk. */
2N/A if (!dry_run)
2N/A {
2N/A for (i = 0; i < nsec; i++)
2N/A grub_disk_write (dest_dev->disk, sectors[i], 0,
2N/A GRUB_DISK_SECTOR_SIZE,
2N/A core_img + i * GRUB_DISK_SECTOR_SIZE);
2N/A }
2N/A
2N/A grub_free (sectors);
2N/A
2N/A goto finish;
2N/A }
2N/A#endif
2N/A
2N/Aunable_to_embed:
2N/A
2N/A if (must_embed)
2N/A grub_util_error (_("embedding is not possible, but this is required when "
2N/A "the root device is on a RAID array or LVM volume"));
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A if (dest_dev->disk->id != root_dev->disk->id)
2N/A grub_util_error (_("embedding is not possible, but this is required for "
2N/A "cross-disk install"));
2N/A#endif
2N/A
2N/A grub_util_warn (_("Embedding is not possible. GRUB can only be installed in this "
2N/A "setup by using blocklists. However, blocklists are UNRELIABLE and "
2N/A "their use is discouraged."));
2N/A if (! force)
2N/A grub_util_error (_("will not proceed with blocklists"));
2N/A
2N/A /* The core image must be put on a filesystem unfortunately. */
2N/A grub_util_info ("will leave the core image on the filesystem");
2N/A
2N/A /* Make sure that GRUB reads the identical image as the OS. */
2N/A tmp_img = xmalloc (core_size);
2N/A core_path_dev_full = grub_util_get_path (dir, core_file);
2N/A core_path_dev = grub_make_system_path_relative_to_its_root (core_path_dev_full);
2N/A free (core_path_dev_full);
2N/A
2N/A grub_util_biosdisk_flush (root_dev->disk);
2N/A
2N/A#define MAX_TRIES 5
2N/A
2N/A for (i = 0; i < MAX_TRIES; i++)
2N/A {
2N/A grub_util_info ((i == 0) ? _("attempting to read the core image `%s' from GRUB")
2N/A : _("attempting to read the core image `%s' from GRUB again"),
2N/A core_path_dev);
2N/A
2N/A grub_disk_cache_invalidate_all ();
2N/A
2N/A grub_file_filter_disable_compression ();
2N/A file = grub_file_open (core_path_dev);
2N/A if (file)
2N/A {
2N/A if (grub_file_size (file) != core_size)
2N/A grub_util_info ("succeeded in opening the core image but the size is different (%d != %d)",
2N/A (int) grub_file_size (file), (int) core_size);
2N/A else if (grub_file_read (file, tmp_img, core_size)
2N/A != (grub_ssize_t) core_size)
2N/A grub_util_info ("succeeded in opening the core image but cannot read %d bytes",
2N/A (int) core_size);
2N/A else if (memcmp (core_img, tmp_img, core_size) != 0)
2N/A {
2N/A#if 0
2N/A FILE *dump;
2N/A FILE *dump2;
2N/A
2N/A dump = fopen ("dump.img", "wb");
2N/A if (dump)
2N/A {
2N/A fwrite (tmp_img, 1, core_size, dump);
2N/A fclose (dump);
2N/A }
2N/A
2N/A dump2 = fopen ("dump2.img", "wb");
2N/A if (dump2)
2N/A {
2N/A fwrite (core_img, 1, core_size, dump2);
2N/A fclose (dump2);
2N/A }
2N/A
2N/A#endif
2N/A grub_util_info ("succeeded in opening the core image but the data is different");
2N/A }
2N/A else
2N/A {
2N/A grub_file_close (file);
2N/A break;
2N/A }
2N/A
2N/A grub_file_close (file);
2N/A }
2N/A else
2N/A grub_util_info ("couldn't open the core image");
2N/A
2N/A if (grub_errno)
2N/A grub_util_info ("error message = %s", grub_errmsg);
2N/A
2N/A grub_errno = GRUB_ERR_NONE;
2N/A grub_util_biosdisk_flush (root_dev->disk);
2N/A sleep (1);
2N/A }
2N/A
2N/A if (i == MAX_TRIES)
2N/A grub_util_error (_("cannot read `%s' correctly"), core_path_dev);
2N/A
2N/A /* Clean out the blocklists. */
2N/A block = first_block;
2N/A while (block->len)
2N/A {
2N/A block->start = 0;
2N/A block->len = 0;
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A block->segment = 0;
2N/A#endif
2N/A
2N/A block--;
2N/A
2N/A if ((char *) block <= core_img)
2N/A grub_util_error (_("no terminator in the core image"));
2N/A }
2N/A
2N/A /* Now read the core image to determine where the sectors are. */
2N/A grub_file_filter_disable_compression ();
2N/A file = grub_file_open (core_path_dev);
2N/A if (! file)
2N/A grub_util_error ("%s", _(grub_errmsg));
2N/A
2N/A file->read_hook = save_first_sector;
2N/A if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
2N/A != GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("failed to read the first sector of the core image"));
2N/A
2N/A block = first_block;
2N/A file->read_hook = save_blocklists;
2N/A if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
2N/A != (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
2N/A grub_util_error (_("failed to read the rest sectors of the core image"));
2N/A
2N/A#ifdef GRUB_MACHINE_IEEE1275
2N/A {
2N/A char *boot_devpath;
2N/A boot_devpath = (char *) (boot_img
2N/A + GRUB_BOOT_AOUT_HEADER_SIZE
2N/A + GRUB_BOOT_MACHINE_BOOT_DEVPATH);
2N/A if (file->device->disk->id != dest_dev->disk->id)
2N/A {
2N/A const char *dest_ofpath;
2N/A dest_ofpath
2N/A = grub_util_devname_to_ofpath (grub_util_biosdisk_get_osdev (file->device->disk));
2N/A grub_util_info ("dest_ofpath is `%s'", dest_ofpath);
2N/A strncpy (boot_devpath, dest_ofpath, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
2N/A - GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1);
2N/A boot_devpath[GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
2N/A - GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0;
2N/A }
2N/A else
2N/A {
2N/A grub_util_info ("non cross-disk install");
2N/A memset (boot_devpath, 0, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
2N/A - GRUB_BOOT_MACHINE_BOOT_DEVPATH);
2N/A }
2N/A grub_util_info ("boot device path %s", boot_devpath);
2N/A }
2N/A#endif
2N/A
2N/A grub_file_close (file);
2N/A
2N/A free (core_path_dev);
2N/A free (tmp_img);
2N/A
2N/A write_rootdev (core_img, root_dev, boot_img, first_sector);
2N/A
2N/A /* Write the first two sectors of the core image onto the disk. */
2N/A if (!dry_run)
2N/A {
2N/A grub_util_info ("opening the core image `%s'", core_path);
2N/A fp = fopen (core_path, "r+b");
2N/A if (! fp)
2N/A grub_util_error (_("cannot open `%s'"), core_path);
2N/A
2N/A grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
2N/A fclose (fp);
2N/A
2N/A }
2N/A
2N/A finish:
2N/A
2N/A if (!dry_run)
2N/A {
2N/A /* Write the boot image onto the disk. */
2N/A grub_util_info("writing boot image to %s", mbr_dev ? "mbr_dev": "dest_dev");
2N/A if (grub_disk_write ((mbr_dev ? : dest_dev)->disk, BOOT_SECTOR,
2N/A 0, GRUB_DISK_SECTOR_SIZE, boot_img))
2N/A grub_util_error ("%s", _(grub_errmsg));
2N/A }
2N/A
2N/A grub_util_biosdisk_flush (root_dev->disk);
2N/A grub_util_biosdisk_flush (dest_dev->disk);
2N/A
2N/A free (core_path);
2N/A free (core_img);
2N/A free (boot_img);
2N/A grub_device_close (dest_dev);
2N/A grub_device_close (root_dev);
2N/A if (mbr_dev)
2N/A grub_device_close (mbr_dev);
2N/A}
2N/A
2N/Astatic struct argp_option options[] = {
2N/A {"boot-image", 'b', N_("FILE"), 0,
2N/A N_("Use FILE as the boot image [default=%s]"), 0},
2N/A {"core-image", 'c', N_("FILE"), 0,
2N/A N_("Use FILE as the core image [default=%s]"), 0},
2N/A {"directory", 'd', N_("DIR"), 0,
2N/A N_("Use GRUB files in the directory DIR [default=%s]"), 0},
2N/A {"device-map", 'm', N_("FILE"), 0,
2N/A N_("Use FILE as the device map [default=%s]"), 0},
2N/A {"root-device", 'r', N_("DEV"), 0,
2N/A N_("Use DEV as the root device [default=guessed]"), 0},
2N/A {"force", 'f', 0, 0,
2N/A N_("Install even if problems are detected"), 0},
2N/A {"skip-fs-probe",'s',0, 0,
2N/A N_("Do not probe for filesystems in DEVICE"), 0},
2N/A {"verbose", 'v', 0, 0,
2N/A N_("Print verbose messages."), 0},
2N/A {"allow-floppy", 'a', 0, 0,
2N/A N_("Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0},
2N/A {"force-mbr", 'M', 0, 0,
2N/A N_("Write the GRUB2 first stage loader to the MBR regardless of the destination"), 0},
2N/A {"dry-run", 'n', 0, 0,
2N/A N_("Dry run. Do not modify any disks or files"), 0},
2N/A#ifdef __sun__
2N/A {"version-string", 'V', N_("STRING"), 0,
2N/A N_("Embed the specified version info after the image on disk"), 0},
2N/A#endif
2N/A { 0, 0, 0, 0, 0, 0 }
2N/A};
2N/A
2N/Astatic char *
2N/Ahelp_filter (int key, const char *text, void *input __attribute__ ((unused)))
2N/A{
2N/A switch (key)
2N/A {
2N/A case 'b':
2N/A return xasprintf (text, DEFAULT_BOOT_FILE);
2N/A
2N/A case 'c':
2N/A return xasprintf (text, DEFAULT_CORE_FILE);
2N/A
2N/A case 'd':
2N/A return xasprintf (text, DEFAULT_DIRECTORY);
2N/A
2N/A case 'm':
2N/A return xasprintf (text, DEFAULT_DEVICE_MAP);
2N/A
2N/A default:
2N/A return (char *) text;
2N/A }
2N/A}
2N/A
2N/Astruct arguments
2N/A{
2N/A char *boot_file;
2N/A char *core_file;
2N/A char *dir;
2N/A char *dev_map;
2N/A char *root_dev;
2N/A int force;
2N/A int fs_probe;
2N/A int allow_floppy;
2N/A char *device;
2N/A int force_mbr;
2N/A int dry_run;
2N/A#ifdef __sun__
2N/A char *version_spec;
2N/A#endif
2N/A};
2N/A
2N/A/* Print the version information. */
2N/Astatic void
2N/Aprint_version (FILE *stream, struct argp_state *state)
2N/A{
2N/A fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
2N/A}
2N/Avoid (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
2N/A
2N/A/* Set the bug report address */
2N/Aconst char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">";
2N/A
2N/Astatic error_t
2N/Aargp_parser (int key, char *arg, struct argp_state *state)
2N/A{
2N/A /* Get the input argument from argp_parse, which we
2N/A know is a pointer to our arguments structure. */
2N/A struct arguments *arguments = state->input;
2N/A
2N/A char *p;
2N/A
2N/A switch (key)
2N/A {
2N/A case 'a':
2N/A arguments->allow_floppy = 1;
2N/A break;
2N/A
2N/A case 'b':
2N/A if (arguments->boot_file)
2N/A free (arguments->boot_file);
2N/A
2N/A arguments->boot_file = xstrdup (arg);
2N/A break;
2N/A
2N/A case 'c':
2N/A if (arguments->core_file)
2N/A free (arguments->core_file);
2N/A
2N/A arguments->core_file = xstrdup (arg);
2N/A break;
2N/A
2N/A case 'd':
2N/A if (arguments->dir)
2N/A free (arguments->dir);
2N/A
2N/A arguments->dir = xstrdup (arg);
2N/A break;
2N/A
2N/A case 'm':
2N/A if (arguments->dev_map)
2N/A free (arguments->dev_map);
2N/A
2N/A arguments->dev_map = xstrdup (arg);
2N/A break;
2N/A
2N/A case 'M':
2N/A arguments->force_mbr = 1;
2N/A break;
2N/A
2N/A case 'n':
2N/A arguments->dry_run = 1;
2N/A break;
2N/A
2N/A case 'r':
2N/A if (arguments->root_dev)
2N/A free (arguments->root_dev);
2N/A
2N/A arguments->root_dev = xstrdup (arg);
2N/A break;
2N/A
2N/A case 'f':
2N/A arguments->force = 1;
2N/A break;
2N/A
2N/A case 's':
2N/A arguments->fs_probe = 0;
2N/A break;
2N/A
2N/A case 'v':
2N/A verbosity++;
2N/A break;
2N/A
2N/A#ifdef __sun__
2N/A case 'V':
2N/A if (arguments->version_spec)
2N/A free (arguments->version_spec);
2N/A
2N/A arguments->version_spec = xstrdup (arg);
2N/A break;
2N/A#endif
2N/A
2N/A case ARGP_KEY_ARG:
2N/A if (state->arg_num == 0)
2N/A arguments->device = xstrdup(arg);
2N/A else
2N/A {
2N/A /* Too many arguments. */
2N/A fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
2N/A argp_usage (state);
2N/A }
2N/A break;
2N/A
2N/A case ARGP_KEY_NO_ARGS:
2N/A fprintf (stderr, "%s", _("No device is specified.\n"));
2N/A argp_usage (state);
2N/A break;
2N/A
2N/A default:
2N/A return ARGP_ERR_UNKNOWN;
2N/A }
2N/A
2N/A return 0;
2N/A}
2N/A
2N/Astatic struct argp argp = {
2N/A options, argp_parser, N_("DEVICE"),
2N/A "\n"N_("\
2N/ASet up images to boot from DEVICE.\n\
2N/A\n\
2N/AYou should not normally run this program directly. Use grub-install instead.")
2N/A"\v"N_("\
2N/ADEVICE must be an OS device (e.g. /dev/sda)."),
2N/A NULL, help_filter, NULL
2N/A};
2N/A
2N/Astatic char *
2N/Aget_device_name (char *dev)
2N/A{
2N/A size_t len = strlen (dev);
2N/A
2N/A if (dev[0] != '(' || dev[len - 1] != ')')
2N/A return 0;
2N/A
2N/A dev[len - 1] = '\0';
2N/A return dev + 1;
2N/A}
2N/A
2N/Aint
2N/Amain (int argc, char *argv[])
2N/A{
2N/A char *root_dev = NULL;
2N/A char *dest_dev = NULL;
2N/A int must_embed = 0;
2N/A struct arguments arguments;
2N/A
2N/A set_program_name (argv[0]);
2N/A
2N/A grub_util_init_nls ();
2N/A
2N/A /* Default option values. */
2N/A memset (&arguments, 0, sizeof (struct arguments));
2N/A arguments.fs_probe = 1;
2N/A
2N/A /* Parse our arguments */
2N/A if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
2N/A {
2N/A fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
2N/A exit(1);
2N/A }
2N/A
2N/A#ifdef GRUB_MACHINE_IEEE1275
2N/A arguments.force = 1;
2N/A#endif
2N/A
2N/A if (verbosity > 1)
2N/A grub_env_set ("debug", "all");
2N/A
2N/A /* Initialize the emulated biosdisk driver. */
2N/A grub_util_biosdisk_init (arguments.dev_map ? : DEFAULT_DEVICE_MAP);
2N/A
2N/A /* Initialize all modules. */
2N/A grub_init_all ();
2N/A grub_gcry_init_all ();
2N/A
2N/A grub_lvm_fini ();
2N/A grub_mdraid09_fini ();
2N/A grub_mdraid1x_fini ();
2N/A grub_raid_fini ();
2N/A grub_raid_init ();
2N/A grub_mdraid09_init ();
2N/A grub_mdraid1x_init ();
2N/A grub_lvm_init ();
2N/A
2N/A dest_dev = get_device_name (arguments.device);
2N/A if (! dest_dev)
2N/A {
2N/A /* Possibly, the user specified an OS device file. */
2N/A dest_dev = grub_util_get_grub_dev (arguments.device);
2N/A if (! dest_dev)
2N/A {
2N/A char *program = xstrdup(program_name);
2N/A fprintf (stderr, _("Invalid device `%s'.\n"), arguments.device);
2N/A argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
2N/A free(program);
2N/A exit(1);
2N/A }
2N/A grub_util_info ("transformed OS device `%s' into GRUB device `%s'",
2N/A arguments.device, dest_dev);
2N/A }
2N/A else
2N/A {
2N/A /* For simplicity. */
2N/A dest_dev = xstrdup (dest_dev);
2N/A grub_util_info ("Using `%s' as GRUB device", dest_dev);
2N/A }
2N/A
2N/A if (arguments.root_dev)
2N/A {
2N/A root_dev = get_device_name (arguments.root_dev);
2N/A
2N/A if (! root_dev)
2N/A grub_util_error (_("invalid root device `%s'"), arguments.root_dev);
2N/A
2N/A root_dev = xstrdup (root_dev);
2N/A }
2N/A else
2N/A {
2N/A char *root_device =
2N/A grub_guess_root_device (arguments.dir ? : DEFAULT_DIRECTORY);
2N/A
2N/A root_dev = grub_util_get_grub_dev (root_device);
2N/A if (! root_dev)
2N/A {
2N/A grub_util_info ("guessing the root device failed, because of `%s'",
2N/A grub_errmsg);
2N/A grub_util_error (_("cannot guess the root device. Specify the option "
2N/A "`--root-device'"));
2N/A }
2N/A grub_util_info ("guessed root device `%s' and root_dev `%s' from "
2N/A "dir `%s'", root_device, root_dev,
2N/A arguments.dir ? : DEFAULT_DIRECTORY);
2N/A }
2N/A
2N/A#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
2N/A if (grub_util_lvm_isvolume (root_dev))
2N/A must_embed = 1;
2N/A#endif
2N/A
2N/A#ifdef __linux__
2N/A if (root_dev[0] == 'm' && root_dev[1] == 'd'
2N/A && ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/'))
2N/A {
2N/A /* FIXME: we can avoid this on RAID1. */
2N/A must_embed = 1;
2N/A }
2N/A
2N/A if (dest_dev[0] == 'm' && dest_dev[1] == 'd'
2N/A && ((dest_dev[2] >= '0' && dest_dev[2] <= '9') || dest_dev[2] == '/'))
2N/A {
2N/A char **devicelist;
2N/A int i;
2N/A
2N/A if (arguments.device[0] == '/')
2N/A devicelist = grub_util_raid_getmembers (arguments.device, 1);
2N/A else
2N/A {
2N/A char *devname;
2N/A devname = xasprintf ("/dev/%s", dest_dev);
2N/A devicelist = grub_util_raid_getmembers (dest_dev, 1);
2N/A free (devname);
2N/A }
2N/A
2N/A for (i = 0; devicelist[i]; i++)
2N/A {
2N/A current_device = devicelist[i];
2N/A setup (arguments.dir ? : DEFAULT_DIRECTORY,
2N/A arguments.boot_file ? : DEFAULT_BOOT_FILE,
2N/A arguments.core_file ? : DEFAULT_CORE_FILE,
2N/A root_dev, grub_util_get_grub_dev (devicelist[i]), 1,
2N/A arguments.force, arguments.fs_probe,
2N/A arguments.allow_floppy, arguments.force_mbr,
2N/A arguments.dry_run);
2N/A }
2N/A }
2N/A else
2N/A#endif
2N/A /* Do the real work. */
2N/A current_device = arguments.device;
2N/A setup (arguments.dir ? : DEFAULT_DIRECTORY,
2N/A arguments.boot_file ? : DEFAULT_BOOT_FILE,
2N/A arguments.core_file ? : DEFAULT_CORE_FILE,
2N/A root_dev, dest_dev, must_embed, arguments.force,
2N/A arguments.fs_probe, arguments.allow_floppy,
2N/A arguments.force_mbr, arguments.dry_run
2N/A#ifdef __sun__
2N/A , arguments.version_spec
2N/A#endif
2N/A );
2N/A
2N/A /* Free resources. */
2N/A grub_fini_all ();
2N/A grub_util_biosdisk_fini ();
2N/A
2N/A free (arguments.boot_file);
2N/A free (arguments.core_file);
2N/A free (arguments.dir);
2N/A free (arguments.root_dev);
2N/A free (arguments.dev_map);
2N/A free (arguments.device);
2N/A free (root_dev);
2N/A free (dest_dev);
2N/A
2N/A return 0;
2N/A}