Labels in grub2
Hello,
I spoke to Colin Watson on IRC recently and asked if the use of labels could be made an option in grub2 in the future.
He suggested I mention it on this list.
In the meantime I have made some patches to demonstrate this idea in grub 1.98 which I have attached.
They work fine for me, with GRUB_USE_LABEL="true" set in /etc/default/grub in my Mandriva-Linux systems.
A grub.cfg produced with a patched grub2 is attached also.
I am not a professional programmer, so I would appreciate any constructive criticism, and your comments in general on this idea.
Thanks,
Barry Jackson
10_linux renamed from etc/grub.d/10_linux +7 -2
@@ -42,11 +42,17 @@ ;; esac +# If device has no uuid OR GRUB_DISABLE_LINUX_UUID is true OR search for dev with uuid fails (bcj) if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then LINUX_ROOT_DEVICE=${GRUB_DEVICE} else - LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} +# If A label exists and GRUB_USE_LABEL=true is in /etc/default/grub (bcj) + if [ "x${GRUB_DEVICE_LABEL}" != "x" ] && [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then + LINUX_ROOT_DEVICE=LABEL=${GRUB_DEVICE_LABEL} + else + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} + fi fi linux_entry ()
@@ -111,7 +117,6 @@ version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` alt_version=`echo $version | sed -e "s,\.old$,,g"` linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" - initrd= for i in "initrd.img-${version}" "initrd-${version}.img" \ "initrd-${version}" "initrd.img-${alt_version}" \
grub2-mkconfig renamed from usr/sbin/grub2-mkconfig +9 -0
@@ -122,6 +122,11 @@ GRUB_DEVICE="`${grub_probe} --target=device /`" GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true +# In grub 1.98 "grub-probe --target=fs_label" is not supported so using blkid (bcj) +if blkid ${GRUB_DEVICE}| grep -q "LABEL=";then +GRUB_DEVICE_LABEL=$(blkid ${GRUB_DEVICE}| grep "LABEL=" |tr -s 'LABEL=' '*' | cut -d* -f2 | cut -d'"' -f2) +fi + # Device containing our /boot partition. Usually the same as GRUB_DEVICE. GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
@@ -199,6 +204,8 @@ # override them. export GRUB_DEVICE \ GRUB_DEVICE_UUID \ + GRUB_DEVICE_LABEL \ + GRUB_USE_LABEL \ GRUB_DEVICE_BOOT \ GRUB_DEVICE_BOOT_UUID \ GRUB_FS \
@@ -226,6 +233,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT + + if test "x${grub_cfg}" != "x"; then rm -f ${grub_cfg}.new exec > ${grub_cfg}.new
grub-mkconfig_lib renamed from usr/lib/grub/grub-mkconfig_lib +5 -0
@@ -120,10 +120,15 @@ # If there's a filesystem UUID that GRUB is capable of identifying, use it; # otherwise set root as per value in device.map. +# If a label is available and GRUB_USE_LABEL=true then use label (bcj) +if [ "x${GRUB_DEVICE_LABEL}" != "x" ] && [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then + echo "search --no-floppy --label --set ${GRUB_DEVICE_LABEL}" +else echo "set root='`${grub_probe} --device ${device} --target=drive`'" if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then echo "search --no-floppy --fs-uuid --set ${fs_uuid}" fi +fi } grub_file_is_not_garbage ()
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by /usr/sbin/grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub #
### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
load_env
fi
set default="0"
if [ ${prev_saved_entry} ]; then
set saved_entry=${prev_saved_entry}
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z ${boot_once} ]; then
saved_entry=${chosen}
save_env saved_entry fi
}
insmod ext2
search --no-floppy --label --set 2010_1_64_root
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=auto
insmod gfxterm
insmod vbe
if terminal_output gfxterm ; then true ; else
# For backward compatibility with versions of terminal.mod that don't # understand terminal_output
terminal gfxterm
fi
fi
insmod ext2
search --no-floppy --label --set 2010_1_64_root
set locale_dir=($root)/boot/grub2/locale
set lang=en
insmod gettext
set timeout=5
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/10_linux ###
menuentry "Mandriva GNU/Linux, with Linux 2.6.33.7-desktop-69mib" --class mandriva --class gnu-linux --class gnu --class os {
set gfxpayload=keep
insmod ext2
search --no-floppy --label --set 2010_1_64_root
echo Loading Linux 2.6.33.7-desktop-69mib ...
linux /boot/vmlinuz-2.6.33.7-desktop-69mib root=LABEL=2010_1_64_root ro splash=verbose
echo Loading initial ramdisk ...
initrd /boot/initrd-2.6.33.7-desktop-69mib.img
}
menuentry "Mandriva GNU/Linux, with Linux 2.6.33.7-desktop-2mnb" --class mandriva --class gnu-linux --class gnu --class os {
set gfxpayload=keep
insmod ext2
search --no-floppy --label --set 2010_1_64_root
echo Loading Linux 2.6.33.7-desktop-2mnb ...
linux /boot/vmlinuz-2.6.33.7-desktop-2mnb root=LABEL=2010_1_64_root ro splash=verbose
echo Loading initial ramdisk ...
initrd /boot/initrd-2.6.33.7-desktop-2mnb.img
}
menuentry "Mandriva GNU/Linux, with Linux 2.6.33.7-desktop-1mnb" --class mandriva --class gnu-linux --class gnu --class os {
set gfxpayload=keep
insmod ext2
search --no-floppy --label --set 2010_1_64_root
echo Loading Linux 2.6.33.7-desktop-1mnb ...
linux /boot/vmlinuz-2.6.33.7-desktop-1mnb root=LABEL=2010_1_64_root ro splash=verbose
echo Loading initial ramdisk ...
initrd /boot/initrd-2.6.33.7-desktop-1mnb.img
}menuentry "Mandriva GNU/Linux, with Linux desktop" --class mandriva --class gnu-linux --class gnu --class os {
insmod ext2
search --no-floppy --label --set 2010_1_64_root
echo Loading Linux desktop ...
linux /boot/vmlinuz-desktop root=LABEL=2010_1_64_root ro splash=verbose
echo Loading initial ramdisk ...
initrd /boot/initrd-desktop.img
}
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change # the 'exec tail' line above. ### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/90_persistent ###
### END /etc/grub.d/90_persistent ###
Good idea because UUID aren't easy to read and the order of the disks hd(0,1)/(1,1) or sda/sdb can be sorted differently by the system when an USB Key is plugged.
Quoted 23 lines · Barry Jackson
Hello,
I spoke to Colin Watson on IRC recently and asked if the use of labels could be made an option in grub2 in the future.
He suggested I mention it on this list.
In the meantime I have made some patches to demonstrate this idea in grub 1.98 which I have attached.
They work fine for me, with GRUB_USE_LABEL="true" set in
/etc/default/grubin my Mandriva-Linux systems.A grub.cfg produced with a patched grub2 is attached also.
I am not a professional programmer, so I would appreciate any constructive criticism, and your comments in general on this idea.
Thanks,
Barry Jackson
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 4 lines · Barry Jackson
In the meantime I have made some patches to demonstrate this idea in grub 1.98 which I have attached.
gmail does not make it easy to quote patches :(
grub2-mkconfig line 127
Quoted 3 lines
grub2-mkconfig renamed from usr/sbin/grub2-mkconfig +1
-0+GRUB_DEVICE_LABEL=$(blkid ${GRUB_DEVICE}| grep "LABEL=" |tr -s 'LABEL=' '*' | cut -d* -f2 | cut -d'"' -f2)
This is very elaborate way to implement
GRUB_DEVICE_LABEL="$(blkid -s LABEL -o value ${GRUB_DEVICE})"
:)
And you have to check whether blkid exists ...
grub2-mkconfig line 238
Quoted 7 lines
grub2-mkconfig renamed from usr/sbin/grub2-mkconfig +2
-0@@ -226,6 +233,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT + + if test "x${grub_cfg}" != "x"; then
You probably should not introduce unrelated formatting changes.
10_linux line 44
Quoted 6 lines
10_linux renamed from etc/grub.d/10_linux +3
-0@@ -42,11 +42,17 @@ +# If A label exists and GRUB_USE_LABEL=true is in /etc/default/grub (bcj) + if [ "x${GRUB_DEVICE_LABEL}" != "x" ] && [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then + LINUX_ROOT_DEVICE=LABEL=${GRUB_DEVICE_LABEL}
Label may contain spaces as opposed to UUID, I think. Although I guess in real life label with spaces will cause much more problem elsewhere.
Same in grub-mkconfig_lib patch BTW
Quoted 7 lines
They work fine for me, with GRUB_USE_LABEL="true" set in
/etc/default/grubin my Mandriva-Linux systems.A grub.cfg produced with a patched grub2 is attached also.
I am not a professional programmer, so I would appreciate any constructive criticism, and your comments in general on this idea.
I think it is fine as option as long as it is not default. Labels have much more chances to duplicate than UUIDs.
Quoted 14 lines · Andrey Borzenkov
Quoted 4 lines · Barry Jackson
In the meantime I have made some patches to demonstrate this idea in grub 1.98 which I have attached.
gmail does not make it easy to quote patches :(
grub2-mkconfig line 127
Quoted 3 lines
grub2-mkconfig renamed from usr/sbin/grub2-mkconfig +1
-0+GRUB_DEVICE_LABEL=$(blkid ${GRUB_DEVICE}| grep "LABEL=" |tr -s 'LABEL=' '*' | cut -d* -f2 | cut -d'"' -f2)This is very elaborate way to implement
Quoted 4 lines
GRUB_DEVICE_LABEL="$(blkid -s LABEL -o value ${GRUB_DEVICE})"
:)
Neat thanks, I forgot that the latest blkid has that feature :-( In the latest beta grub, grub-probe can be used instead of blkid for this.
Quoted 1 line
And you have to check whether blkid exists ...
Yes. I suppose it's possible that it may not be available. I was only thinking of Mandriva.
Quoted 10 lines
grub2-mkconfig line 238
Quoted 8 lines
grub2-mkconfig renamed from usr/sbin/grub2-mkconfig +2
-0@@ -226,6 +233,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT + + if test "x${grub_cfg}" != "x"; thenYou probably should not introduce unrelated formatting changes.
I don't understand what you mean by that. Ah - those blank lines? OK, yes, that was accidental. Must be more careful.
Quoted 12 lines
10_linux line 44
Quoted 7 lines
10_linux renamed from etc/grub.d/10_linux +3
-0@@ -42,11 +42,17 @@ +# If A label exists and GRUB_USE_LABEL=true is in /etc/default/grub (bcj) + if [ "x${GRUB_DEVICE_LABEL}" != "x" ]&& [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then + LINUX_ROOT_DEVICE=LABEL=${GRUB_DEVICE_LABEL}Label may contain spaces as opposed to UUID, I think. Although I guess in real life label with spaces will cause much more problem elsewhere.
Same in grub-mkconfig_lib patch BTW
Yes labels can have spaces, but it's a bad idea and yes things do break, maybe LINUX_ROOT_DEVICE=LABEL="${GRUB_DEVICE_LABEL}" would be enough. Or maybe detect labels with spaces and exit 1 would be safer. I will do more testing.
Quoted 9 lines
Quoted 7 lines
They work fine for me, with GRUB_USE_LABEL="true" set in
/etc/default/grubin my Mandriva-Linux systems.A grub.cfg produced with a patched grub2 is attached also.
I am not a professional programmer, so I would appreciate any constructive criticism, and your comments in general on this idea.
I think it is fine as option as long as it is not default
I agree
Quoted 3 lines
Labels have
much more chances to duplicate than UUIDs.
If users can't think of unique labels then it's time to give up :-(
I really hope that the grub developers pick up this idea and run with it.
Thanks for your input.
Barry
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel