Changing OS Name in Grub 2 Menu
Since upgrading Boon to Ubuntu 10.04, I’ve been running the new Grub 2 boot loader. It looks much like the old grub, but the configuration is very different. On installation, it found all the operating systems installed on Boon, including the Gateway recovery partition, which is labeled “Windows Vista (loader) (on /dev/sdb1)”. Unfortunately, the Vista installation was labeled “Windows Vista (loader) (on /dev/sdb2)”. Since sdb1 was listed first, my wife chose this and ended up very much not where she wanted to be.
With Grub 1 (a.k.a. Grub Legacy), I’d have edited the menu entry title in /boot/grub/menu.lst
and been done with it. Now the configuration file is named /boot/grub/grub.cfg
and warns “DO NOT EDIT THIS FILE.” No problem, but where am I supposed to make the change?
I started with the Ubuntu Wiki Grub 2 instructions. From there, I found out how grub.cfg
is created and how to exclude entries or add custom ones, but nothing specifically about how to change the title of a menu entry. I suppose I could edit /etc/grub.d/30_os-prober
manually, but with all this talk of Grub 2’s increased flexibility, I suspect there’s a better way.
Next, I checked out the Grub 2 Community Ubuntu Documentation. Not much there. Maybe I’m too optimistic, but I don’t see the average user editing shell scripts to change his boot menu. But it seems that’s what I have to do.
I want to preserve the original script and work with a copy:
sudo cp /etc/grub.d/30_os-prober /etc/grub.d/31_os-prober-custom
sudo chmod -x /etc/grub.d/30_os-prober
The mode change prevents the original from running and producing duplicate entries. Next, edit /etc/grub.d/31_os-prober-custom
:
Find
case ${BOOT} in chain)
and change the lines after that from:
cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF
to:
case ${DEVICE} in /dev/sdb1) cat << EOF menuentry "Gateway Recovery (on ${DEVICE})" { EOF ;; *) cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { EOF ;; esac
Of course, this is specific to my installation. What the code change does is alter the label for anything on /dev/sdb1
to "Gateway Recovery". Since there can be only one OS per partition and I'm not moving the recovery partition, this is fine.
To make the changes stick, run sudo update-grub
.
BTW, if you're using an editor such as Emacs that makes backup copies, don't worry about the backups. update-grub
is smart enough to exclude them. I mention this only because this was a problem with a script from an older distribution that handled events on my Laptop. Since the original script and the backup got run, closing the laptop lid caused two instances of the event to run. The laptop would hibernate, then when the lid was opened, it would wake up and immediately hibernate again.