* [PATCH] grub-setup: make it possible to specify the root device
@ 2012-09-04 14:32 Arnout Vandecappelle (Essensium/Mind)
2012-09-04 16:51 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 5+ messages in thread
From: Arnout Vandecappelle (Essensium/Mind) @ 2012-09-04 14:32 UTC (permalink / raw)
To: grub-devel; +Cc: Arnout Vandecappelle (Essensium/Mind)
From: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>
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) <arnout@mind.be>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] grub-setup: make it possible to specify the root device
2012-09-04 14:32 [PATCH] grub-setup: make it possible to specify the root device Arnout Vandecappelle (Essensium/Mind)
@ 2012-09-04 16:51 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-09-04 18:44 ` Arnout Vandecappelle
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-09-04 16:51 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 712 bytes --]
On 04.09.2012 16:32, Arnout Vandecappelle (Essensium/Mind) wrote:
> From: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>
>
> 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.
Looks like you just do it wrong. Correct way is to create a loopback and
then use kpartx to discover partitions, not use loopback with offset.
This "root device" is purely technical information and it should be
discovered automatically from the information we already have (we have a
directory)
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] grub-setup: make it possible to specify the root device
2012-09-04 16:51 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-09-04 18:44 ` Arnout Vandecappelle
2012-09-05 5:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 5+ messages in thread
From: Arnout Vandecappelle @ 2012-09-04 18:44 UTC (permalink / raw)
To: The development of GNU GRUB
Cc: Vladimir 'φ-coder/phcoder' Serbinenko
On 09/04/12 18:51, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 04.09.2012 16:32, Arnout Vandecappelle (Essensium/Mind) wrote:
>
>> From: "Arnout Vandecappelle (Essensium/Mind)"<arnout@mind.be>
>>
>> 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.
>
>
> Looks like you just do it wrong. Correct way is to create a loopback and
> then use kpartx to discover partitions, not use loopback with offset.
> This "root device" is purely technical information and it should be
> discovered automatically from the information we already have (we have a
> directory)
I want to create an image file without superuser access. So I can't mount
a loopback device, so the grub directory is not actually inside the image:
it's the directory from which the target filesystem is created.
If there's another way to do that, I'd be glad to hear it.
By the way, I'm also thinking about patching the build infrastructure
to support building a cross-installer (e.g. grub-mkimage as an x86 executable
but cross-compiling lib/grub/powerpc-ieee1275/*). Is there an interest for
that?
Regards,
Arnout
--
Arnout Vandecappelle arnout dot vandecappelle at essensium dot com
Senior Embedded Software Architect . . +32-16-286540 . +32-478-010353 (mobile)
Essensium, Mind division . . . . . . . . . . . . . . . . . http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium . . . . . . . . BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 31BB CF53 8660 6F88 345D 54CC A836 5879 20D7 CF43
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] grub-setup: make it possible to specify the root device
2012-09-04 18:44 ` Arnout Vandecappelle
@ 2012-09-05 5:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-09-06 17:42 ` Arnout Vandecappelle
0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-09-05 5:04 UTC (permalink / raw)
To: Arnout Vandecappelle; +Cc: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 1530 bytes --]
On 04.09.2012 20:44, Arnout Vandecappelle wrote:
> On 09/04/12 18:51, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>> On 04.09.2012 16:32, Arnout Vandecappelle (Essensium/Mind) wrote:
>>
>>> From: "Arnout Vandecappelle (Essensium/Mind)"<arnout@mind.be>
>>>
>>> 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.
>>
>>
>> Looks like you just do it wrong. Correct way is to create a loopback and
>> then use kpartx to discover partitions, not use loopback with offset.
>> This "root device" is purely technical information and it should be
>> discovered automatically from the information we already have (we have a
>> directory)
>
> I want to create an image file without superuser access. So I can't mount
> a loopback device, so the grub directory is not actually inside the image:
> it's the directory from which the target filesystem is created.
>
> If there's another way to do that, I'd be glad to hear it.
>
grub-mkrescue
>
> By the way, I'm also thinking about patching the build infrastructure
> to support building a cross-installer (e.g. grub-mkimage as an x86
> executable
> but cross-compiling lib/grub/powerpc-ieee1275/*). Is there an interest for
> that?
Long since done. It's also use for automated tests.
>
>
> Regards,
> Arnout
>
g
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] grub-setup: make it possible to specify the root device
2012-09-05 5:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-09-06 17:42 ` Arnout Vandecappelle
0 siblings, 0 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2012-09-06 17:42 UTC (permalink / raw)
To: Vladimir 'φ-coder/phcoder' Serbinenko
Cc: The development of GNU GRUB
On 09/05/12 07:04, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 04.09.2012 20:44, Arnout Vandecappelle wrote:
>
[snip]
>> I want to create an image file without superuser access. So I can't mount
>> a loopback device, so the grub directory is not actually inside the image:
>> it's the directory from which the target filesystem is created.
>>
>> If there's another way to do that, I'd be glad to hear it.
>>
>
> grub-mkrescue
Sorry, I should have set: I want to create an *ext4* image file. grub-mkrescue
only makes an iso image and doesn't let me choose a partitioning. I did look
at patching grub-mkrescue first, but that just relies on xorriso to do the
heavy lifting so that doesn't help.
Granted, I could just dd the grub image into the mbr, but I wasn't entirely sure
how to do that and this patch was simpler.
>> By the way, I'm also thinking about patching the build infrastructure
>> to support building a cross-installer (e.g. grub-mkimage as an x86
>> executable
>> but cross-compiling lib/grub/powerpc-ieee1275/*). Is there an interest for
>> that?
>
> Long since done. It's also use for automated tests.
Yeah, cool! I didn't know I had to supply TARGET_CC - some other configures
use CC_FOR_BUILD - hence the confusion. Thanks!
Regards,
Arnout
--
Arnout Vandecappelle arnout dot vandecappelle at essensium dot com
Senior Embedded Software Architect . . +32-16-286540 . +32-478-010353 (mobile)
Essensium, Mind division . . . . . . . . . . . . . . . . . http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium . . . . . . . . BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 31BB CF53 8660 6F88 345D 54CC A836 5879 20D7 CF43
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-07 7:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-04 14:32 [PATCH] grub-setup: make it possible to specify the root device Arnout Vandecappelle (Essensium/Mind)
2012-09-04 16:51 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-09-04 18:44 ` Arnout Vandecappelle
2012-09-05 5:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-09-06 17:42 ` Arnout Vandecappelle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.