Scan root device dynamically at startup
PATCH 1/1 Scan root device dynamically at startup
Hi,
For normal boot, the root device is passed to core.img in preloader. However, if we load grub2 using linux header, there is no way to know the root device. This patch add a new module findroot that can be used to scan the root directory at startup.
One important usage is to create a grub2 boot file for vista boot loader:
mkimage -o g2ntfs.img pc ntfs biosdisk findroot
cat lnxboot.img g2ntfs.img > g2ntfs.mbr
The result g2ntfs.mbr is within 32K, which can be loaded by vista in one pass, no need to use the g2ldr.mbr anymore. The findroot modules ensure that prefix is set properly before switching to normal mode.
If findroot is not used to create core.img, the original booting method remains.
Signature · 1 line
Bean
conf/i386-pc.rmk +6 -1
@@ -155,7 +155,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod + aout.mod _bsd.mod bsd.mod findroot.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -322,4 +322,9 @@ bsd_mod_SOURCES = loader/i386/bsd_normal.c bsd_mod_CFLAGS = $(COMMON_CFLAGS) bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For findroot.mod. +findroot_mod_SOURCES = kern/findroot.c +findroot_mod_CFLAGS = $(COMMON_CFLAGS) +findroot_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/i386/pc/kernel.h +1 -1
@@ -68,7 +68,7 @@ extern grub_int32_t grub_memdisk_image_size;/* The prefix which points to the directory where GRUB modules and its configuration file are located. */ -extern char grub_prefix[]; +extern char EXPORT_VAR (grub_prefix ) [];/* The boot BIOS drive number. */ extern grub_int32_t EXPORT_VAR (grub_boot_drive );
kern/findroot.c new file +77 -0
77 lines not on this page · raw message
kern/main.c +3 -1
@@ -124,7 +124,9 @@ grub_main (void)/* It is better to set the root device as soon as possible, for convenience. */ -grub_machine_set_prefix (); +if (!grub_env_get ("prefix" )) +grub_machine_set_prefix (); +grub_set_root_dev ();/* Load the normal mode module. */
Quoted 9 lines · Bean
Hi,
For normal boot, the root device is passed to core.img in preloader. However, if we load grub2 using linux header, there is no way to know the root device. This patch add a new module findroot that can be used to scan the root directory at startup.
One important usage is to create a grub2 boot file for vista boot loader:
Quoted 8 lines
mkimage -o g2ntfs.img pc ntfs biosdisk findroot
cat lnxboot.img g2ntfs.img > g2ntfs.mbrThe result g2ntfs.mbr is within 32K, which can be loaded by vista in one pass, no need to use the g2ldr.mbr anymore. The findroot modules ensure that prefix is set properly before switching to normal mode.
If findroot is not used to create core.img, the original booting method remains.
The module is called findroot, but it initialises $prefix rather than $root. Shouldn't it be findprefix or so?
Also, what this module is doing looks very similar to "search --set". Did you check if search command can be used for what you want? (or otherwise adapted)
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 13 lines · Robert Millan
Quoted 12 lines · Bean
Hi,
For normal boot, the root device is passed to core.img in preloader. However, if we load grub2 using linux header, there is no way to know the root device. This patch add a new module findroot that can be used to scan the root directory at startup.
One important usage is to create a grub2 boot file for vista boot loader:
mkimage -o g2ntfs.img pc ntfs biosdisk findroot
cat lnxboot.img g2ntfs.img > g2ntfs.mbr
Quoted 9 lines
Quoted 5 lines
The result g2ntfs.mbr is within 32K, which can be loaded by vista in one pass, no need to use the g2ldr.mbr anymore. The findroot modules ensure that prefix is set properly before switching to normal mode.
If findroot is not used to create core.img, the original booting method remains.
The module is called findroot, but it initialises $prefix rather than $root. Shouldn't it be findprefix or so?
In function grub_set_root_dev (main.c), it uses prefix to calculated root, so setting prefix is sufficient.
About the name, well, findprefix works for me too.
Quoted 3 lines
Also, what this module is doing looks very similar to "search --set". Did you check if search command can be used for what you want? (or otherwise adapted)
The findroot module is used to locate normal.mod. But search is a command, it can only be used after normal.mod has been loaded.
Signature · 1 line
Bean
Quoted 4 lines · Bean
In function
grub_set_root_dev(main.c), it uses prefix to calculated root, so setting prefix is sufficient.
Quoted 8 lines
About the name, well, findprefix works for me too.
Quoted 3 lines
Also, what this module is doing looks very similar to "search --set". Did you check if search command can be used for what you want? (or otherwise adapted)
The findroot module is used to locate normal.mod. But search is a command, it can only be used after normal.mod has been loaded.
I've been thinking a bit more about this, and my impression is that it the approach is quite ad-hoc. For example, some similar problems that this solution wouldn't solve, but that a very similar solution would:
a- normal.mod was built into grub.elf (perhaps because the firmware can load
big files). Then the problem is finding grub.cfg instead of normal.mod.
b- User has a disk liing around which happens to have a normal.mod from
an earlier version of grub (let's assume different ABI). Turns out this disk is used for something else and can't be supressed. A solution could be to use UUIDs for the search, but that can't always work since we need a "smart" install process that can probe for them (unlike in the situation you described -- I can't imagine doing fancy stuff in bare-bones Vista).
c- Search for normal.mod was ok, but then this particular port of grub can't
accept the prefix variable from your module, because it already got this variable from the firmware (OFW does this). And the variable from firmware happens to be completely unusable.
I think a solution that would fit well here is to use memdisk to embed a grub.cfg. Then in each situation we could have a different grub.cfg script that finds appropiate prefix using the search command.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 14 lines · Robert Millan
Quoted 4 lines · Bean
In function
grub_set_root_dev(main.c), it uses prefix to calculated root, so setting prefix is sufficient.Quoted 8 lines
About the name, well, findprefix works for me too.
Quoted 3 lines
Also, what this module is doing looks very similar to "search --set". Did you check if search command can be used for what you want? (or otherwise adapted)
The findroot module is used to locate normal.mod. But search is a command, it can only be used after normal.mod has been loaded.
Quoted 6 lines
I've been thinking a bit more about this, and my impression is that it the approach is quite ad-hoc. For example, some similar problems that this solution wouldn't solve, but that a very similar solution would:
a- normal.mod was built into grub.elf (perhaps because the firmware can load
big files). Then the problem is finding grub.cfg instead of normal.mod.
If the firmware support large image file, then it's no problem. For image ~ 64K, we can include normal and some basic command. But for image ~ 32K (like vista boot loader), it can only contain kernel and one of the file system driver.
Quoted 8 lines
b- User has a disk liing around which happens to have a normal.mod from
an earlier version of grub (let's assume different ABI). Turns out this disk is used for something else and can't be supressed. A solution could be to use UUIDs for the search, but that can't always work since we need a "smart" install process that can probe for them (unlike in the situation you described -- I can't imagine doing fancy stuff in bare-bones Vista).
I think this is the most convenient way of installing grub2 in vista. User don't need any customization. They just add the entry and copy /boot/grub to any supported partition. Besides, our driver currently don't support UUID, and some partition doesn't have UUID (like FAT).
Quoted 4 lines
c- Search for normal.mod was ok, but then this particular port of grub can't
accept the prefix variable from your module, because it already got this variable from the firmware (OFW does this). And the variable from firmware happens to be completely unusable.
The module initialization code is run in grub_load_modules (), It's before the platform code grub_machine_set_prefix (). If findroot has find the prefix, it won't use the firmware value anymore.
Quoted 3 lines
I think a solution that would fit well here is to use memdisk to embed a grub.cfg. Then in each situation we could have a different grub.cfg script that finds appropiate prefix using the search command.
memdisk is not so useful in such situation. grub.cfg need normal.mod for its script engine. So we need to embed normal.mod. and at least search.mod. Such image is well above 32K limit.
Signature · 1 line
Bean
Dne 29 Květen 2008, 12:46, Bean napsal(a):
Quoted 5 lines
I think this is the most convenient way of installing grub2 in vista. User don't need any customization. They just add the entry and copy
/boot/grubto any supported partition. Besides, our driver currently don't support UUID, and some partition doesn't have UUID (like FAT).
Every FAT has serial number, generated when first formating of partition, it is only 4 bytes, so it is not as unique as UUID but it suffices.
Other filesystems often have similar identifiers.
Signature · 2 lines
Tomas Ebenlendr
http://drak.ucw.cz/~ebikQuoted 9 lines · Tomáš Ebenlendr
Dne 29 Květen 2008, 12:46, Bean napsal(a):
Quoted 5 lines
I think this is the most convenient way of installing grub2 in vista. User don't need any customization. They just add the entry and copy
/boot/grubto any supported partition. Besides, our driver currently don't support UUID, and some partition doesn't have UUID (like FAT).
Quoted 4 lines
Every FAT has serial number, generated when first formating of partition, it is only 4 bytes, so it is not as unique as UUID but it suffices.
Other filesystems often have similar identifiers.
My point is not about FAT; that's just an example. What I mean is we can't always rely on UUID being usable; and in Bean's use case it isn't.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 5 lines · Tomáš Ebenlendr
Every FAT has serial number, generated when first formating of partition, it is only 4 bytes, so it is not as unique as UUID but it suffices.
Other filesystems often have similar identifiers.
Now that we have a framework for filesystem UUIDs, it should be simple to support FAT serial numbers like it is done in the ext2 driver.
If you're familiar with FAT, would you like to help us on this?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)
Quoted 11 lines · Robert Millan
Quoted 5 lines · Tomáš Ebenlendr
Every FAT has serial number, generated when first formating of partition, it is only 4 bytes, so it is not as unique as UUID but it suffices.
Other filesystems often have similar identifiers.
Now that we have a framework for filesystem UUIDs, it should be simple to support FAT serial numbers like it is done in the ext2 driver.
If you're familiar with FAT, would you like to help us on this?
Well, the FAT signature is the unsigned long value after the extended boot signature 0x29, I can add it later.
Signature · 1 line
Bean
Quoted 5 lines · Bean
Quoted 5 lines
I've been thinking a bit more about this, and my impression is that it the approach is quite ad-hoc. For example, some similar problems that this solution wouldn't solve, but that a very similar solution would:
Quoted 7 lines
Quoted 2 lines
a- normal.mod was built into grub.elf (perhaps because the firmware can load
big files). Then the problem is finding grub.cfg instead of normal.mod.If the firmware support large image file, then it's no problem. For image ~ 64K, we can include normal and some basic command. But for image ~ 32K (like vista boot loader), it can only contain kernel and one of the file system driver.
Yes. But then, how do you find grub.cfg? The grub.cfg that is generated by update-grub can't be part of grub.elf, and you need a way to find it.
Your proposed hack would work for that, simply by replacing "normal.mod" with "grub.cfg".
Quoted 10 lines
Quoted 7 lines
b- User has a disk liing around which happens to have a normal.mod from
an earlier version of grub (let's assume different ABI). Turns out this disk is used for something else and can't be supressed. A solution could be to use UUIDs for the search, but that can't always work since we need a "smart" install process that can probe for them (unlike in the situation you described -- I can't imagine doing fancy stuff in bare-bones Vista).I think this is the most convenient way of installing grub2 in vista. [...]
It probably is; what I'm describing is another situation in which the most convenient way is almost like that but not quite. Then we would need another module for that, which is a mess. That's why I think a generic solution would be best, if possible.
Quoted 8 lines
Quoted 4 lines
c- Search for normal.mod was ok, but then this particular port of grub can't
accept the prefix variable from your module, because it already got this variable from the firmware (OFW does this). And the variable from firmware happens to be completely unusable.The module initialization code is run in
grub_load_modules(), It's before the platform codegrub_machine_set_prefix(). If findroot has find the prefix, it won't use the firmware value anymore.
But it is run after grub_machine_init(), and it is permissible that grub_machine_init() already sets the prefix (ieee1275 does that).
Maybe your proposed module should override this setting, then?
Quoted 7 lines
Quoted 3 lines
I think a solution that would fit well here is to use memdisk to embed a grub.cfg. Then in each situation we could have a different grub.cfg script that finds appropiate prefix using the search command.
memdisk is not so useful in such situation. grub.cfg need normal.mod for its script engine. So we need to embed normal.mod. and at least search.mod. Such image is well above 32K limit.
That's unfortunate... do you think this approach could be extended/modified somehow to address the other situations?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What good is a phone call… if you are unable to speak? (as seen on /.)