From: Barry Jackson <zen25000@zen.co.uk>
To: grub-devel@gnu.org
Cc: Andrey Borzenkov <arvidjaar@mail.ru>
Subject: Labels in grub2
Date: Tue, 02 Nov 2010 23:57:08 +0000 [thread overview]
Message-ID: <4CD0A554.5060404@zen.co.uk> (raw)
[-- 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 ###
next reply other threads:[~2010-11-02 23:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-02 23:57 Barry Jackson [this message]
2010-11-04 10:40 ` Labels in grub2 Frombenny
2010-11-04 12:12 ` Andrey Borzenkov
2010-11-04 19:27 ` Barry Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CD0A554.5060404@zen.co.uk \
--to=zen25000@zen.co.uk \
--cc=arvidjaar@mail.ru \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.