From c6c180757e8597c5782ebc6465c3896157e5fec4 Mon Sep 17 00:00:00 2001 From: okuji Date: Mon, 25 Sep 2000 16:05:47 +0000 Subject: [PATCH] add --prefix into the command setup, and add separate boot partition support into grub-install. --- ChangeLog | 21 +++++++++++ NEWS | 7 ++++ stage2/builtins.c | 89 +++++++++++++++++++++++++++++++++----------- util/grub-install.in | 16 +++++++- 4 files changed, 110 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b3853dca..df2c51fd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2000-09-26 OKUJI Yoshinori + + * util/grub-install.in (bootdir_device): New variable. If + $bootdir_device is not the same as $root_device, set root_device + and grubdir to $bootdir_device and "/grub", respectively. + Add --prefix=$grubdir into the command "setup". + +2000-09-26 OKUJI Yoshinori + + Add --prefix=DIR to the command "setup". + + * stage2/builtins.c (setup_func): New nested function, + check_file checks if the file FILE exists. + Remove the prefix "/boot/grub" in STAGE1_5_MAP. + Don't hardcode "/boot/grub/stage1", "/boot/grub/stage2", or + "/boot/grub/menu.lst". Instead, check if ARG contains + "--prefix=", and if specified, set PREFIX to the value. + If not specified, check "/boot/grub/stage1" and, if not found, + check "/grub/stage1". If a stage1 was found, set PREFIX to the + directory which contains the stage1. + 2000-09-12 OKUJI Yoshinori Add additional magic to avoid a bug in Linux. *sigh* diff --git a/NEWS b/NEWS index b1c39698e..affebe0d9 100644 --- a/NEWS +++ b/NEWS @@ -35,6 +35,13 @@ New in 0.5.96 - XXXX-XX-XX: * New command, "savedefault". Now you can save current entry number to your disk with this command and then you can set the default boot entry to it by the command "default saved". +* Add a new option `--prefix' into the command "setup", so that you can + specify the name of a directory which contains GRUB images. And, the + behavior of this command changed slightly, that is, this command now + searchs stage1 automatically under "/boot/grub" and "/grub", unless + you specify the option `--prefix'. +* The utility `grub-install' recognizes a separate boot partition + automatically. New in 0.5.95 - 2000-06-27: * NetBSD ELF kernel support is added. You have to specify the new option diff --git a/stage2/builtins.c b/stage2/builtins.c index a11bf8ece..1ef295a4c 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -3124,8 +3124,28 @@ setup_func (char *arg, int flags) char *buffer = (char *) RAW_ADDR (0x100000); int is_force_lba = 0; char *stage2_arg = 0; + char *prefix = 0; + + auto int check_file (char *file); + auto void sprint_device (int drive, int partition); - static void sprint_device (int drive, int partition) + /* Check if the file FILE exists like Autoconf. */ + int check_file (char *file) + { + int ret; + + grub_printf (" Checking if \"%s\" exists... ", file); + ret = grub_open (file); + if (ret) + grub_printf ("yes\n"); + else + grub_printf ("no\n"); + + return ret; + } + + /* Construct a device name in DEVICE. */ + void sprint_device (int drive, int partition) { grub_sprintf (device, "(%cd%d", (drive & 0x80) ? 'h' : 'f', @@ -3151,18 +3171,13 @@ setup_func (char *arg, int flags) }; struct stage1_5_map stage1_5_map[] = { - {"ext2fs", "/boot/grub/e2fs_stage1_5"}, - {"ffs", "/boot/grub/ffs_stage1_5"}, - {"fat", "/boot/grub/fat_stage1_5"}, - {"minix", "/boot/grub/minix_stage1_5"}, - {"reiserfs", "/boot/grub/reiserfs_stage1_5"} + {"ext2fs", "/e2fs_stage1_5"}, + {"ffs", "/ffs_stage1_5"}, + {"fat", "/fat_stage1_5"}, + {"minix", "/minix_stage1_5"}, + {"reiserfs", "/reiserfs_stage1_5"} }; - /* Initialize some strings. */ - grub_strcpy (stage1, "/boot/grub/stage1"); - grub_strcpy (stage2, "/boot/grub/stage2"); - grub_strcpy (config_filename, "/boot/grub/menu.lst"); - tmp_drive = saved_drive; tmp_partition = saved_partition; @@ -3174,6 +3189,12 @@ setup_func (char *arg, int flags) is_force_lba = 1; arg = skip_to (0, arg); } + else if (grub_memcmp ("--prefix=", arg, sizeof ("--prefix=") - 1) == 0) + { + prefix = arg + sizeof ("--prefix=") - 1; + arg = skip_to (0, arg); + nul_terminate (prefix); + } #ifdef GRUB_UTIL else if (grub_memcmp ("--stage2=", arg, sizeof ("--stage2=") - 1) == 0) { @@ -3219,15 +3240,38 @@ setup_func (char *arg, int flags) /* Open it. */ if (! open_device ()) goto fail; - - /* Check for stage1 and stage2. We hardcode the filenames, so - if the user installed GRUB in a uncommon directory, this never - succeed. */ - if (! grub_open (stage1)) - goto fail; + + /* Check if stage1 exists. If the user doesn't specify the option + `--prefix', attempt /boot/grub and /grub. */ + /* NOTE: It is dangerous to run this command without `--prefix' in the + grub shell, since that affects `--stage2'. */ + if (! prefix) + { + prefix = "/boot/grub"; + grub_sprintf (stage1, "%s%s", prefix, "/stage1"); + if (! check_file (stage1)) + { + errnum = ERR_NONE; + prefix = "/grub"; + grub_sprintf (stage1, "%s%s", prefix, "/stage1"); + if (! check_file (stage1)) + goto fail; + } + } + else + { + grub_sprintf (stage1, "%s%s", prefix, "/stage1"); + if (! check_file (stage1)) + goto fail; + } grub_close (); - if (! grub_open (stage2)) + /* The prefix was determined. */ + grub_sprintf (stage2, "%s%s", prefix, "/stage2"); + grub_sprintf (config_filename, "%s%s", prefix, "/menu.lst"); + + /* Check if stage2 exists. */ + if (! check_file (stage2)) goto fail; grub_close (); @@ -3244,13 +3288,16 @@ setup_func (char *arg, int flags) if (grub_strcmp (fsys, stage1_5_map[i].fsys) == 0) { /* OK, check if the Stage 1.5 exists. */ - if (grub_open (stage1_5_map[i].name)) + char stage1_5[64]; + + grub_sprintf (stage1_5, "%s%s", prefix, stage1_5_map[i].name); + if (check_file (stage1_5)) { int blocksize = (filemax + SECTOR_SIZE - 1) >> SECTOR_BITS; grub_close (); grub_strcpy (config_filename, stage2); - grub_strcpy (stage2, stage1_5_map[i].name); + grub_strcpy (stage2, stage1_5); if (installed_partition == 0xFFFFFF) { @@ -3344,7 +3391,7 @@ static struct builtin builtin_setup = "setup", setup_func, BUILTIN_CMDLINE, - "setup [--stage2=STAGE2_FILE] [--force-lba] INSTALL_DEVICE [IMAGE_DEVICE]", + "setup [--prefix=DIR] [--stage2=STAGE2_FILE] [--force-lba] INSTALL_DEVICE [IMAGE_DEVICE]", "Set up the installation of GRUB automatically. This command uses" " the more flexible command \"install\" in the backend and installs" " GRUB into the device INSTALL_DEVICE. If IMAGE_DEVICE is specified," diff --git a/util/grub-install.in b/util/grub-install.in index 49850a352..cf782cb0d 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -228,7 +228,19 @@ esac # Get the root drive. # For now, this uses the program `df' to get the device name, but is # this really portable? -root_device=`df ${rootdir}/ | grep /dev/ | sed 's%.*\(/dev/[a-z0-9]*\).*%\1%'` +root_device=`df ${rootdir}/ | grep /dev/ \ + | sed 's%.*\(/dev/[a-z0-9]*\).*%\1%'` +bootdir_device=`df ${bootdir} | grep /dev/ \ + | sed 's%.*\(/dev/[a-z0-9]*\).*%\1%'` + +# Check if the boot directory is in the same device as the root directory. +if test "x$root_device" != "x$bootdir_device"; then + # Perhaps the user has a separate boot partition. + root_device=$bootdir_device + grubdir="/grub" +fi + +# Convert the root device to a GRUB drive. root_drive=`convert "$root_device"` if test "x$root_drive" = x; then exit 1 @@ -262,7 +274,7 @@ test -x /bin/tempfile && log_file=`tempfile --prefix=grub` # Now perform the installation. $grub_shell --batch --device-map=$device_map <$log_file root $root_drive -setup $force_lba --stage2=$grubdir/stage2 $install_drive +setup $force_lba --stage2=$grubdir/stage2 --prefix=$grubdir $install_drive quit EOF