Received: from list by lists.gnu.org with archive (Exim 4.71) id 1T8uBw-0006Ai-5O for mharc-grub-devel@gnu.org; Tue, 04 Sep 2012 10:33:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8uBq-0005td-GM for grub-devel@gnu.org; Tue, 04 Sep 2012 10:33:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8uBc-0005it-4N for grub-devel@gnu.org; Tue, 04 Sep 2012 10:33:17 -0400 Received: from 132.79-246-81.adsl-static.isp.belgacom.be ([81.246.79.132]:60534 helo=viper.mind.be) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8uBb-0005gZ-QT for grub-devel@gnu.org; Tue, 04 Sep 2012 10:33:04 -0400 Received: from [172.16.2.6] (helo=vandecaa-laptop) by viper.mind.be with esmtp (Exim 4.69) (envelope-from ) id 1T8uBR-0002rC-OD; Tue, 04 Sep 2012 16:32:56 +0200 Received: from arnout by vandecaa-laptop with local (Exim 4.80) (envelope-from ) id 1T8uBS-0007KD-Kb; Tue, 04 Sep 2012 16:32:54 +0200 From: "Arnout Vandecappelle (Essensium/Mind)" To: grub-devel@gnu.org Subject: [PATCH] grub-setup: make it possible to specify the root device Date: Tue, 4 Sep 2012 16:32:48 +0200 Message-Id: <1346769168-28089-1-git-send-email-arnout@mind.be> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 81.246.79.132 Cc: "Arnout Vandecappelle \(Essensium/Mind\)" X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2012 14:33:23 -0000 From: "Arnout Vandecappelle (Essensium/Mind)" When creating a bootable disk image in a file rather than on a physical device, it is not possible to guess the root partition. Therefore, allow the root partition to be specified on the command line. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) --- If I'm violating patch submission policy somewhere, please let me know and I'll try to correct it. I tried to work with a bzr branch but the initial checkout failed (possibly due to an evil corporate firewall). Note that a big part of the patch is just an indentation change. --- util/grub-setup.c | 108 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 43 deletions(-) diff --git a/util/grub-setup.c b/util/grub-setup.c index 085e8df..ee1b367 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -141,7 +141,7 @@ write_rootdev (char *core_img, grub_device_t root_dev, static void setup (const char *dir, const char *boot_file, const char *core_file, - const char *dest, int force, + const char *dest, const char* rootarg, int force, int fs_probe, int allow_floppy) { char *boot_path, *core_path, *core_path_dev, *core_path_dev_full; @@ -253,50 +253,61 @@ setup (const char *dir, core_dev = dest_dev; - { - char **root_devices = grub_guess_root_devices (dir); - char **cur; - int found = 0; + if (rootarg && *rootarg) + { + /* Verify if the supplied root is valid */ + root_dev = grub_device_open (rootarg); + if (root_dev) + root = xstrdup(rootarg); + else + grub_util_error ("supplied root device `%s' is invalid, because of `%s'", + rootarg, grub_errmsg); + } + else + { + char **root_devices = grub_guess_root_devices (dir); + char **cur; + int found = 0; - for (cur = root_devices; *cur; cur++) - { - char *drive; - grub_device_t try_dev; - - drive = grub_util_get_grub_dev (*cur); - if (!drive) - continue; - try_dev = grub_device_open (drive); - if (! try_dev) - continue; - if (!found && try_dev->disk->id == dest_dev->disk->id - && try_dev->disk->dev->id == dest_dev->disk->dev->id) - { - if (root_dev) - grub_device_close (root_dev); - free (root); - root_dev = try_dev; - root = drive; - found = 1; + for (cur = root_devices; *cur; cur++) + { + char *drive; + grub_device_t try_dev; + + drive = grub_util_get_grub_dev (*cur); + if (!drive) continue; - } - if (!root_dev) - { - root_dev = try_dev; - root = drive; + try_dev = grub_device_open (drive); + if (! try_dev) continue; - } - grub_device_close (try_dev); - free (drive); - } - if (!root_dev) - { - grub_util_error ("guessing the root device failed, because of `%s'", - grub_errmsg); - } - grub_util_info ("guessed root_dev `%s' from " - "dir `%s'", root_dev->disk->name, dir); - } + if (!found && try_dev->disk->id == dest_dev->disk->id + && try_dev->disk->dev->id == dest_dev->disk->dev->id) + { + if (root_dev) + grub_device_close (root_dev); + free (root); + root_dev = try_dev; + root = drive; + found = 1; + continue; + } + if (!root_dev) + { + root_dev = try_dev; + root = drive; + continue; + } + grub_device_close (try_dev); + free (drive); + } + if (!root_dev) + { + grub_util_error ("guessing the root device failed, because of `%s'", + grub_errmsg); + } + grub_util_info ("guessed root_dev `%s' from " + "dir `%s'", root_dev->disk->name, dir); + } grub_util_info ("setting the root device to `%s'", root); if (grub_env_set ("root", root) != GRUB_ERR_NONE) @@ -952,6 +963,8 @@ static struct argp_option options[] = { N_("use GRUB files in the directory DIR [default=%s]"), 0}, {"device-map", 'm', N_("FILE"), 0, N_("use FILE as the device map [default=%s]"), 0}, + {"root-partition", 'r', N_("DEV"), 0, + N_("use grub device DEV as the root partition within DEVICE [default=probed]"), 0}, {"force", 'f', 0, 0, N_("install even if problems are detected"), 0}, {"skip-fs-probe",'s',0, 0, @@ -993,6 +1006,7 @@ struct arguments char *core_file; char *dir; char *dev_map; + char *root; int force; int fs_probe; int allow_floppy; @@ -1040,6 +1054,13 @@ argp_parser (int key, char *arg, struct argp_state *state) arguments->dev_map = xstrdup (arg); break; + case 'r': + if (arguments->root) + free (arguments->root); + + arguments->root = xstrdup (arg); + break; + case 'f': arguments->force = 1; break; @@ -1172,7 +1193,7 @@ main (int argc, char *argv[]) setup (arguments.dir ? : DEFAULT_DIRECTORY, arguments.boot_file ? : DEFAULT_BOOT_FILE, arguments.core_file ? : DEFAULT_CORE_FILE, - dest_dev, arguments.force, + dest_dev, arguments.root, arguments.force, arguments.fs_probe, arguments.allow_floppy); /* Free resources. */ @@ -1184,6 +1205,7 @@ main (int argc, char *argv[]) free (arguments.dir); free (arguments.dev_map); free (arguments.device); + free (arguments.root); free (root_dev); free (dest_dev); -- 1.7.10.4