Question about grub2

Hi guys. I’m learning some basics about boot loading process.
I 'm confused with the “set root” and “–set=root” and “root=UUID” expressions in the grub config.
for example here is a portion of my grub.cfg.
Would anybody describe these different expressions for me please? What are they used for exactly?

menuentry 'openSUSE 13.1' --class 'opensuse-13-1' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-94bcb121-da47-4f18-be45-2e7e7ac28066' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos6'
    if  x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 --hint='hd0,msdos6'  94bcb121-da47-4f18-be45-2e7e7ac28066
    else
      search --no-floppy --fs-uuid --set=root 94bcb121-da47-4f18-be45-2e7e7ac28066
    fi
    echo    'Loading Linux 3.14.4-31.g0de0f93-desktop ...'
    linux    /boot/vmlinuz-3.14.4-31.g0de0f93-desktop root=UUID=94bcb121-da47-4f18-be45-2e7e7ac28066   video=1366x768 resume=/dev/disk/by-id/ata-TOSHIBA_MQ01ABD075_Z2MESL9CS-part5 splash=silent quiet showopts acpi_osi=Linux acpi_backlight=vendor
    echo    'Loading initial ramdisk ...'
    initrd    /boot/initrd-3.14.4-31.g0de0f93-desktop
}

The line

set root='hd0,msdos6'

sets root to partition 6 on disk 0. The “msdos6” means that the disk uses traditional MBR partitioning, otherwise known as “msdos” partitioning.

The line

search --no-floppy --fs-uuid --set=root 94bcb121-da47-4f18-be45-2e7e7ac28066

searches all disks for a partition with the indicated UUID, and then sets that partition to root.

The other line looks also at other details, such as where the disk is plugged in.

The first of the two lines sets a default. The other line that I quoted will override that default if it finds a different partition.

Which disk is hd0 can depend on BIOS settings, whether there is a USB plugged in etc. So the UUID search is more accurate when it works.

It searches all disks and partitions for a file system with indicated UUID. Distinction is important because e.g. GPT partitions have own GUID as well; grub2 so far does not support them. So “partition with indicated UUID” is a bit ambiguous here.

And could you please tell me what do this parameter do in kernel parameters? “root=UUID=94bcb121-da47-4f18-be45-2e7e7ac28066”

 linux    /boot/vmlinuz-3.14.4-31.g0de0f93-desktop root=UUID=94bcb121-da47-4f18-be45-2e7e7ac28066   video=1366x768 resume=/dev/disk/by-id/ata-TOSHIBA_MQ01ABD075_Z2MESL9CS-part5 splash=silent quiet showopts acpi_osi=Linux acpi_backlight=vendor

And another question is what does all these three root means in here?Which is root partition and which is grub root?
Is there any “grub root” parameter anyway? Because i was told root here means grub root for “grub.cfg” file ,but if it’s true if the grub menues are loaded and is displayed to the users, what’s it use?

It tells the kernel to use that partition as root filesystem, i.e. /.

And another question is what does all these three root means in here?Which is root partition and which is grub root?

grub’s root is the partition where grub looks for the files if it is not explicitely specified.
F.e.:

linux /boot/vmlinuz-3.14.4-31.g0de0f93-desktop

will load the kernel from “grub’s root”/boot/vmlinuz-3.14.4-31.g0de0f93-desktop.
You could of course specify the partition from where to load it from by using something like:

linux (hd0,msdos1)/boot/vmlinuz-3.14.4-31.g0de0f93-desktop

Then grub’s root wouldn’t matter for this.

The main thing to differentiate here in terms of “root” is grub’s root (i.e. the place where grub looks for files by default) and the kernel’s root (i.e. what gets mounted as / during boot, specified via root=xxx on the kernel command line).

Is there any “grub root” parameter anyway? Because i was told root here means grub root for “grub.cfg” file ,but if it’s true if the grub menues are loaded and is displayed to the users, what’s it use?

What do you mean with that?
grub.cfg is loaded before the root is set in grub.cfg, obviously.
The root has to be set in grub.cfg so that grub finds the kernel and initrd files.

Where it loads grub.cfg from is determined at the time you install the boot loader (I think). You could specify that as parameter when calling grub2-install.

Please take a look here:

You mean this?

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.

Ok, but if there is a “set root=…” inside of grub.cfg it’s obviously too late for “telling grub where to look for grub.cfg”, as grub already have to have read grub.cfg to see this command in that case… :wink:
And I don’t think grub2 will re-read grub.cfg when it encounters a “set root=…” command.

It has effect on the other things it loads though, like the kernel and initrd f.e. as I already wrote above.

I think like you. You are right.
Thanks everybody.

Absolutely correct.

The BIOS reads the MBR, and looks for a recognizable boot pattern there. If Grub is installed in the MBR (or another boot pattern, such as a DOS or Windows boot), it uses that. If there is none there, it looks in the Active or Boot partition … which is why, if you install Grub to the root partition, you have to make certain you set the Boot flag on that partition.

(That is not the only reason the BIOS reads the MBR. Another reason is to obtain the disk layout geometry.)

What you write here is true of course, but that’s only about the boot loader code itself.
It’s totally unrelated to where grub.cfg or the rest of grub2’s files are read from.

F.e. you can install grub2 to the MBR or the root partition, and still have it read grub.cfg and the rest from a separate /boot/ partition…

Again, absolutely correct.