Mailinglist Archive: opensuse (1470 mails)

< Previous Next >
Re: [opensuse] Am I doing this custom grub config correctly?
19.02.2016 22:19, Carlos E. R. пишет:
Hi,

I'm preparing a new 2 GB disk with GPT partitioning as boot disk on a
BIOS only machine, and installed Leap 42.1 on it, for testing.

I need grub2 on this system to be able to boot other systems. I could
let os-prober do its job, but I do not want to. For starters, it takes
long minutes thinking about it (there are six disks with up to 20
partitions), and I don't like the resulting menu, because it tries to
boot specific kernels.

Instead I want grub2 to chainload the grub instances on the other
partitions. So I edit /boot/grub2/custom.cfg like this:

menuentry '2:1 - 11.4' {
insmod part_msdos
insmod ext2
set root='hd2,msdos1'
chainloader +1
}

However, this means that as I insert or remove hard disks, the locations
of those disks may change (hd2 may become hd0, for instance). Instead, I
could refer to those other disks using the uuid. So I copied partly the
config initially generated by YaST2 and os-prober:


menuentry '2:1 - 11.4 uuid' {
insmod part_msdos
insmod ext2
set root='hd2,msdos1'

if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos1
--hint-efi=hd2,msdos1 --hint-baremetal=ahci2,msdos1
93f0311e-2a93-49ca-b836-d362ffc84486
else
search --no-floppy --fs-uuid --set=root
93f0311e-2a93-49ca-b836-d362ffc84486
fi

chainloader +1
}


grub-mkconfig generates code that looks so complicated because of
backward compatibility consideration and to cover different platforms.
You know that your grub version supports hints, so you do not need
feature check. Also you do not need hints for platforms you won't be
booting on anyway. Which reduces it to

search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos1
93f0311e-2a93-49ca-b836-d362ffc84486

And if you want hints to be useful - go into grub CLI and verify name
for each disk. grub-mkconfig lists them in order Linux enumerates them
which is not necessary the same as BIOS.

Both methods appear to work.

I wonder if I should skip completely the second line, «set
root='hd2,msdos1'». But grub2 uses that syntax.

Syntax?

What would happen if the
disk happens to change instead to, say, 'hd3,msdos1', would grub2 find
the new location correctly using the uuid just below?


Yes. This is just default. search won't modify variable it it fails
(cannot find search target), so this assignment simply defaults root to
the value guessed when grub-mkconfig was run. This is probably wrong
anyway (see above).

Am I doing it correctly, or should I do it some other way?


Well, it would be useful to check that search was successful and if not,
just echo this to inform user, instead of attempting to boot that will
likely hang anyway. Like

if search ... ; then
chainloader
else
echo Could not find this OS instance, will not boot
sleep 10
fi

You can even do search in toplevel grub.cfg and generate menu entries
only for those OS that are actually present.
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References