grub 2 - when / why I need both in grub.cfg ; set root= and search ... --set=root ...
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The first one (set root=...) tells GRUB where to look for grub.cfg, the second one tells GRUB where (and how) to look for the root file system for the specific OS you're loading.
See info grub2 for more details. (If you've installed the info files - IIRC, Ubuntu and some other distributions do not install them by default.)
The first one (set root=...) tells GRUB where to look for grub.cfg, the second one tells GRUB where (and how) to look for the root file system for the specific OS you're loading.
See info grub2 for more details. (If you've installed the info files - IIRC, Ubuntu and some other distributions do not install them by default.)
Precisely - set prefix (depends on set root=) tells to grub where to look for grub.cfg.
But WHY in grub.cfg each menuentry contains (I know that does not have to) set root= (in ubuntu generated) if grub.cfg is already loaded (when I am in grub shell prompt in edit mode I mean) ?
The "root file system for the OS" is not the GRUB2 "root." It is the location, usually "/", that the kernel needs to know in order to start the OS running. On a system with a single OS, those locations are often the same, but not always.
Here's an excerpt from my grub.cfg where you can see that (for that OS) it's on a different drive from the grub.cfg file. (Added comments in red.)
Code:
menuentry 'Fedora 17 (/dev/md127)' --class fedora --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-207d8262-a705-4237-8cc6-f527fb3e34cc' {
savedefault
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod btrfs
set root='hd1,msdos6' #This is where the MBR installed by GRUB2 was told to look for load.cfg
# And the next block is, essentially, a double-check that the root specified has the correct UUID, but it's
# possible you might want to have load.cfg and grub.cfg on different partitions.
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos6 --hint-efi=hd1,msdos6 --hint-baremetal=ahci1,msdos6 f52a4cdd-befe-4197-82dc-18a34eacf783
else
search --no-floppy --fs-uuid --set=root f52a4cdd-befe-4197-82dc-18a34eacf783
fi
echo 'Loading Linux 3.4.4-3.fc17.x86_64 ...'
# But note here that this OS is booted using a boot image from a different boot directory and UUID
linux /bootM/vmlinuz-3.4.4-3.fc17.x86_64 root=UUID=207d8262-a705-4237-8cc6-f527fb3e34cc ro quiet
echo 'Loading initial ramdisk ...'
initrd /bootM/initramfs-3.4.4-3.fc17.x86_64.img
}
(If you're interested, /dev/md127 is a software RAID-1 drive, and /dev/sdb6 is a btrfs partition from which I usually boot. Since btrfs is still somewhat experimental, I can also boot from a USB stick, but that's a different issue.)
The point of all the above is that the GRUB designers wanted to support as many different booting scenarios as possible, so they tried to make as few assumptions as they could. (The "U" in "GRUB" stands for "unified," not "universal," but they wanted to be as "universal" as the technology available would let them be.)
The "root file system for the OS" is not the GRUB2 "root." It is the location, usually "/", that the kernel needs to know in order to start the OS running. On a system with a single OS, those locations are often the same, but not always.
Here's an excerpt from my grub.cfg where you can see that (for that OS) it's on a different drive from the grub.cfg file. (Added comments in red.)
Code:
menuentry 'Fedora 17 (/dev/md127)' --class fedora --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-207d8262-a705-4237-8cc6-f527fb3e34cc' {
savedefault
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod btrfs
set root='hd1,msdos6' #This is where the MBR installed by GRUB2 was told to look for load.cfg
# And the next block is, essentially, a double-check that the root specified has the correct UUID, but it's
# possible you might want to have load.cfg and grub.cfg on different partitions.
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos6 --hint-efi=hd1,msdos6 --hint-baremetal=ahci1,msdos6 f52a4cdd-befe-4197-82dc-18a34eacf783
else
search --no-floppy --fs-uuid --set=root f52a4cdd-befe-4197-82dc-18a34eacf783
fi
echo 'Loading Linux 3.4.4-3.fc17.x86_64 ...'
# But note here that this OS is booted using a boot image from a different boot directory and UUID
linux /bootM/vmlinuz-3.4.4-3.fc17.x86_64 root=UUID=207d8262-a705-4237-8cc6-f527fb3e34cc ro quiet
echo 'Loading initial ramdisk ...'
initrd /bootM/initramfs-3.4.4-3.fc17.x86_64.img
}
(If you're interested, /dev/md127 is a software RAID-1 drive, and /dev/sdb6 is a btrfs partition from which I usually boot. Since btrfs is still somewhat experimental, I can also boot from a USB stick, but that's a different issue.)
The point of all the above is that the GRUB designers wanted to support as many different booting scenarios as possible, so they tried to make as few assumptions as they could. (The "U" in "GRUB" stands for "unified," not "universal," but they wanted to be as "universal" as the technology available would let them be.)
Hi,
Thanks a lot for explanation and patience - but I am not clear about it :-( and I did not find any load.cfg (or similar to it) file on my ubuntu instance.
In my case I am using similar menuentry for ocz hard drive because proprietary company does not support linux at all - so kernel module does not exist - disk is not recognized in grub - and for that reason I cannot boot my raid0 from grub (not generating by update-grub at all) by "usual way" , but like following:
so ,grub is taken from different disk - MBR than OS instance - GPT is running from.
(But in some cases I do not need to have set root=() - which I prefer - reason:it is more independent when reordering /dev/sdXY - which happened to me very often. - especially boot from external usb hard disk / usb pendrive, mc card , ...)
(I have never seen --hint-bios and --hint-efi - something new :-) - is it for fedora grub specific ?
Not exactly. Fedora 17 uses GRUB 2.0.0.37.beta6; Ubuntu uses GRUB 1.99.21ubuntu3.1 (in my Ubuntu 12.04 virtual system, updated today). I suspect that the beta version of the 2.0 release is at least slightly different from the older 1.99 version that Ubuntu modified for their last release. (And I have no idea what the Ubuntu developers might have modified in the pre-release version 1.99 of GRUB 2 for their system. I suppose I could look at the source code, but I don't feel like doing that.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.