Ask Your Question
0

how do I set grub2 to use labels versus UUID in search

asked 2013-07-31 09:30:05 -0500

kababbles gravatar image

updated 2013-08-01 05:47:00 -0500

FranciscoD_ gravatar image

After days of research, and many old posts, I am seeking guidance from the community on how to safely alter grub2 to force the grub.conf file to utilize device LABELS versus UUID's on boot. Our scenario is not that unique, however, we must create unique UUID's each and every time we copy an image file for KVM installation and use. We are easily doing that with kpartx. However, as one would expect, the grub.conf contains specific UUID's from the original install. Is there something I am missing, or is there actually a simple, pragmatic way to force grub to use LABELS instead of UUID in a way that will not break as I execute upgrades to the kernel and OS, on a base image file.

Thanks,

the code below is the target of my concern. This comes from /boot/grub.conf

BTW: I have added the following two lines in my /etc/default/grub file (over the course of my research), with no positive results.

GRUB_DISABLE_LINUX_UUID=true
GRUB_ENABLE_LINUX_LABEL=true

/boot/grub2/grub.conf file snippet:

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Fedora, with Linux 3.10.3-300.fc19.x86_64' --class fedora --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.10.3-300.fc19.x86_64-advanced-b5004d08-2f7c-40a8-81b6-4d971839e5fb' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy **--fs-uuid** --set=root --hint='hd0,msdos1'  a7a5ac1f-6a8f-4935-b368-1a6f2b8c0af0
        else
          search --no-floppy --fs-uuid --set=root a7a5ac1f-6a8f-4935-b368-1a6f2b8c0af0
        fi
edit retag flag offensive close merge delete

Comments

FWIW, using a kickstart file and installing Fedora to your VMs avoids this problem, can often be faster, and arguably provides a more predictable environment, since root filesystem UUIDs aren't the only supposedly-unique things on the system.

randomuser gravatar imagerandomuser ( 2014-10-05 02:23:14 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-10-04 08:55:22 -0500

I am using xubuntu, but the menu entries for grub looks too much alike to discount the possibility that the same script is used to generate them, namely: update-grub. It also uses /usr/share/grub/grub-mkconfig_lib to generate the hints line (where 'search' is and so is --fs-uuid)

So, I edited /etc/defaults/grub and uncommented the line:

GRUB_DISABLE_LINUX_UUID=true

Then, I edited grub-mkconfig_lib:

  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
  # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
   if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
     echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
     echo "else"
     echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
     echo "fi"
  fi
  IFS="$old_ifs"

and changed the following lines:

   if fs_uuid="`"${grub_probe}" --device $@ --target=fs_label 2> /dev/null`" ; then


     echo "  search --no-floppy --label --set=root ${hints} ${fs_uuid}"


     echo "  search --no-floppy --label --set=root ${fs_uuid}"

then run the script update-grub

edit flag offensive delete link more
0

answered 2013-11-11 16:45:34 -0500

p0tato gravatar image

I'm encountering a similar problem. However, instead of labels, we're trying to use raw disk partitions. (These are all cloned VM's, so they'll have identical disk layouts.)

What we've discovered so far:

  • Using GRUB_DISABLE_LINUX_UUID inside of /etc/default/grub will cause the linux entry of your generated /boot/grub2/grub.cfg file to contain a simple filesystem device, assuming you regenerate it with grub2-mkconfig.
  • Grub2 has specific search modules that are designed to help resolve something like a UUID or LABEL down to the raw device file at runtime. This is what the search segment of your grub.conf is trying to do with it's --fs-uuid parameter. In your case, I'm willing to bet --fs-label instead of --fs-uuid and the label you're looking for (instead of the disk UUID) at the end of the search statement will probably do what you want.

e.g.: search --no-floppy --fs-label --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' /

In our case, we removed the search stanza completely, by hand. Our grub.cfg comes in at kickstart, delivered from a web server. We've also done the same with /etc/fstab to use raw device names as well.

We spent a while trying to get Grub2 to do what we wanted, and discovered it was faster to hack it in place in %post than try and patch the grub2-tools package.

It's looking good now, and it's cloneable, so I hope this helps give you some direction on this.

On the other hand, if you solved it differently, please let me know how you did it.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-07-31 09:30:05 -0500

Seen: 17,224 times

Last updated: Oct 04 '14