LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grub 2 - when / why I need both in grub.cfg ; set root= and search ... --set=root ... (https://www.linuxquestions.org/questions/linux-newbie-8/grub-2-when-why-i-need-both-in-grub-cfg-%3B-set-root%3D-and-search-set%3Droot-4175416157/)

masuch 07-11-2012 11:41 AM

grub 2 - when / why I need both in grub.cfg ; set root= and search ... --set=root ...
 
Hi,

Could please somebody explain me what is the difference between commands ?
Quote:

set root=(hdX,gptY)
and
search ... --set=root someuuid
when and why I need to present both commands in the grub.cfg ?

thank you,
kind regards,
M.

PTrenholme 07-11-2012 12:18 PM

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.)

masuch 07-11-2012 04:11 PM

Quote:

Originally Posted by PTrenholme (Post 4725207)
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) ?

(I went through https://wiki.archlinux.org/index.php/GRUB2 manual.) I am looking for more information.

PTrenholme 07-12-2012 03:53 PM

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.)

masuch 07-17-2012 04:22 PM

Quote:

Originally Posted by PTrenholme (Post 4726377)
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:

menuentry " ... exp ... Ubuntu 3.2.0-27 rlraid0ocz[PCEUBU1:raid0ocz] apparmor" --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
gfxmode $linux_gfx_mode
insmod part_gpt
insmod gzio
insmod part_msdos
insmod ext2
insmod raid # fixes software raid boot problem
insmod mdraid
insmod mdraid1x
insmod mdraid09
set root='(hd2,msdos5)'
#set root='(hd1,gpt6)'
#set root='(/dev/md/PCEUBU1:raid0ocz)'
search --no-floppy --fs-uuid --set=root ff504cbf-0446-4de6-a61b-65cc066dd9b7
#search --no-floppy --fs-uuid --set=root /dev/md/PCEUBU1:raid0ocz
linux /boot/vmlinuz-3.2.0-27-generic root=UUID=20b7653b-199d-4565-821e-dda9ac0383e2 ro vga=799 $vt_handoff apparmor=1 security=apparmor crashkernel=384M-2G:64M,2G-:128M initcall_debug printk.time=y bootchart=disable verbose elevator=noop
#init=/sbin/bootchartd rdinitrd=/sbin/bootchartd
initrd /boot/initrd.img-3.2.0-27-generic
}

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 ?

Regards,

PTrenholme 07-19-2012 03:41 PM

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.)


All times are GMT -5. The time now is 04:13 AM.