16

I'm looking at the official GRUB2 docs for the search command, as found on http://www.gnu.org/software/grub/manual/grub.html#index-search

Command: search [--file|--label|--fs-uuid] [--set [var]] [--no-floppy] name

Search devices by file (-f, --file), filesystem label (-l, --label),
or filesystem UUID (-u, --fs-uuid).

If the --set option is used, the first device found is set as the
value of environment variable var. The default variable is ‘root’.

The --no-floppy option prevents searching floppy devices, which can be slow.

The ‘search.file’, ‘search.fs_label’, and ‘search.fs_uuid’ commands are aliases
for ‘search --file’, ‘search --label’, and ‘search --fs-uuid’ respectively.

In section 5.3 there are many examples along

menuentry "FreeBSD" {
      insmod zfs
      search --set=root --label freepool --hint hd0,msdos7
      ...
}

It appears the --hint option is undocumented other than as an example. What does it do exactly? What is the exact format of the argument?

Jens
  • 1,752
  • 4
  • 18
  • 36

2 Answers2

11

--hint is used to select which partition to select when there are multiple matched partition. By default the 1st matched one is selected.

Suppose there are 2 storage device with label boot as follows

hd0,msdos1
hd1,msdos7

then the command :

search --set=root --label freepool --hint hd1,msdos7

will select hd1,msdos7 instead of hd0,msdos1

GAD3R
  • 66,769
totti
  • 1,484
5

This is not described in the GRUB Manual but there is documentation to be found in GRUB itself (search --help on the GRUB shell):

--hint
    First try the device HINT.
    If HINT ends in comma, also try subpartitions

--hint-ieee1275
    First try the device HINT if currently running on IEEE1275.
    If HINT ends in comma, also try subpartitions

--hint-bios
    First try the device HINT if currently running on BIOS.
    If HINT ends in comma, also try subpartitions

--hint-baremetal
    First try the device HINT if direct hardware access is supported.
    If HINT ends in comma, also try subpartitions

--hint-efi
    First try the device HINT if currently running on EFI.
    If HINT ends in comma, also try subpartitions

--hint-arc
    First try the device HINT if currently running on ARC.
    If HINT ends in comma, also try subpartitions

Now what is the point of "First try device"?

You have to understand that search is a potentially slow operation.

Maybe you have 50 drives, each with 100 partitions, and now search has to go through all of these ... until it finally finds the UUID you were looking for in the 2356th attempt.

Or maybe you have a very slow device and checking for its UUID causes search to be stuck for a while. There's --no-floppy to avoid the most common case, I guess - but other devices can also be slow.

With --hint, you set a device to check first. Provided the hint was correct, you skip the otherwise potentially lengthy search operation altogether. So this is a speed optimization. (Probably won't be noticable with just one drive, three partitions)

The effect described in @totti's answer of giving preference to a specific device when there are two with the same LABEL or UUID, that should merely be a side effect.

Sure, if you check one device first, a duplicate on another device should not be found. Even so, it would make more sense to not have such duplicates in the first place. As duplicate UUIDs (or LABELs) can be considered a configuration error, and in case the --hint turned out to be wrong, it might still return the wrong device.

frostschutz
  • 48,978