* Labels in grub2
@ 2010-11-02 23:57 Barry Jackson
2010-11-04 10:40 ` Frombenny
2010-11-04 12:12 ` Andrey Borzenkov
0 siblings, 2 replies; 4+ messages in thread
From: Barry Jackson @ 2010-11-02 23:57 UTC (permalink / raw)
To: grub-devel; +Cc: Andrey Borzenkov
[-- Attachment #1: Type: text/plain, Size: 595 bytes --]
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
[-- Attachment #2: 10_linux.patch --]
[-- Type: text/plain, Size: 1099 bytes --]
--- /etc/grub.d/10_linux 2010-11-02 22:25:19.849508548 +0000
+++ 10_linux 2010-11-02 22:05:31.000000000 +0000
@@ -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}" \
[-- Attachment #3: grub2-mkconfig.patch --]
[-- Type: text/plain, Size: 1122 bytes --]
--- /usr/sbin/grub2-mkconfig 2010-11-02 22:38:20.610505816 +0000
+++ grub2-mkconfig 2010-11-02 22:35:32.000000000 +0000
@@ -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
[-- Attachment #4: grub-mkconfig_lib.patch --]
[-- Type: text/plain, Size: 771 bytes --]
--- /usr/lib/grub/grub-mkconfig_lib 2010-10-23 15:16:16.000000000 +0100
+++ grub-mkconfig_lib 2010-11-02 22:31:03.000000000 +0000
@@ -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 ()
[-- Attachment #5: grub.cfg --]
[-- Type: text/plain, Size: 3167 bytes --]
#
# 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 ###
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Labels in grub2
2010-11-02 23:57 Labels in grub2 Barry Jackson
@ 2010-11-04 10:40 ` Frombenny
2010-11-04 12:12 ` Andrey Borzenkov
1 sibling, 0 replies; 4+ messages in thread
From: Frombenny @ 2010-11-04 10:40 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 992 bytes --]
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.
Le 03/11/2010 00:57, Barry Jackson a écrit :
> 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
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
[-- Attachment #2: Type: text/html, Size: 1812 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Labels in grub2
2010-11-02 23:57 Labels in grub2 Barry Jackson
2010-11-04 10:40 ` Frombenny
@ 2010-11-04 12:12 ` Andrey Borzenkov
2010-11-04 19:27 ` Barry Jackson
1 sibling, 1 reply; 4+ messages in thread
From: Andrey Borzenkov @ 2010-11-04 12:12 UTC (permalink / raw)
To: The development of GNU GRUB
On Wed, Nov 3, 2010 at 2:57 AM, Barry Jackson <zen25000@zen.co.uk> wrote:
>
> 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 :(
> --- /usr/sbin/grub2-mkconfig 2010-11-02 22:38:20.610505816 +0000
> +++ grub2-mkconfig 2010-11-02 22:35:32.000000000 +0000
> +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 ...
> @@ -226,6 +233,8 @@
> GRUB_INIT_TUNE \
> GRUB_SAVEDEFAULT
>
> +
> +
> if test "x${grub_cfg}" != "x"; then
You probably should not introduce unrelated formatting changes.
> --- /etc/grub.d/10_linux 2010-11-02 22:25:19.849508548 +0000
> +++ 10_linux 2010-11-02 22:05:31.000000000 +0000
> @@ -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
> 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.
I think it is fine as option as long as it is not default. Labels have
much more chances to duplicate than UUIDs.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Labels in grub2
2010-11-04 12:12 ` Andrey Borzenkov
@ 2010-11-04 19:27 ` Barry Jackson
0 siblings, 0 replies; 4+ messages in thread
From: Barry Jackson @ 2010-11-04 19:27 UTC (permalink / raw)
To: grub-devel
On 04/11/10 12:12, Andrey Borzenkov wrote:
> On Wed, Nov 3, 2010 at 2:57 AM, Barry Jackson<zen25000@zen.co.uk> wrote:
>>
>> 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 :(
>
>> --- /usr/sbin/grub2-mkconfig 2010-11-02 22:38:20.610505816 +0000
>> +++ grub2-mkconfig 2010-11-02 22:35:32.000000000 +0000
>> +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})"
>
> :)
>
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.
> 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.
>
>> @@ -226,6 +233,8 @@
>> GRUB_INIT_TUNE \
>> GRUB_SAVEDEFAULT
>>
>> +
>> +
>> if test "x${grub_cfg}" != "x"; then
>
> You 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.
>
>> --- /etc/grub.d/10_linux 2010-11-02 22:25:19.849508548 +0000
>> +++ 10_linux 2010-11-02 22:05:31.000000000 +0000
>> @@ -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.
>> 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.
>
> I think it is fine as option as long as it is not default
I agree
> 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
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-11-04 19:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-02 23:57 Labels in grub2 Barry Jackson
2010-11-04 10:40 ` Frombenny
2010-11-04 12:12 ` Andrey Borzenkov
2010-11-04 19:27 ` Barry Jackson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).