[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grub: eval vars for linux command / write config agnostic to other disks

From: Toerless Eckert
Subject: grub: eval vars for linux command / write config agnostic to other disks
Date: Sat, 28 Mar 2020 17:56:33 +0100
User-agent: Mutt/1.10.1 (2018-07-13)

I would like to have a grub config that will work even
if the disk is re-plugged into a different SATA port
and independent of whether other disks are plugged in.

Lets say i today have this config:

 set root='hd5,gpt2'
 search --no-floppy --fs-uuid --set=root 4bdb3675-62ff-499f-9fc4-e5fd8c7ba777
 linux   /vmlinuz root=/dev/sdf5 ro

The problem really is the "root=/dev/sdf5" when starting linux.
When the disk is plugged into a different slot, or if one of
the prior disks is removed, then /dev/sdf5 will be wrong.

I know, ideally inux should be able to solve the problem itself,
but it seemingly can't: LABEL=<label> or similar are not available
when choosing the root partition.

Is there a way to evaluate grub2 variables being passed to a
command like the linux command ?

E.g.: something like:

   set root='hd5,gpt2'
   search --no-floppy --fs-uuid --set=root 4bdb3675-62ff-499f-9fc4-e5fd8c7ba777
   set linuxroot="/dev/sdf2"
   if [ "x$root" = "hd4,gpt2" ]; then
       set linuxroot="/dev/sde5"
   if [ "x$root" = "hd0,gpt2" ]; then
       set linuxroot="/dev/sda5"
   linux   /vmlinuz root="$linuxroot" ro

Of course, if grub supports shell style 'case' statement,
the string mapping would be easier, but the main question
is really if there is a way to pass the value of $linuxroot
to the linux command somehow.

Alas, couldn't figure out the ansewer to this question from
the grub2 manual ;-(

Thank you so much

reply via email to

[Prev in Thread] Current Thread [Next in Thread]