Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried GRUB2 on different Ubuntu releases (12.04 and 13.04) on several machines and no matter what I do I can't get it to behave. It seems like a great idea (abstracting away configuration files through a CLI), but it really does not work for me.

Here's a simple example:

$ grub-set-default 'Ubuntu, with Linux 3.5.0-45-generic'
$ grub-editenv list
saved_entry=Ubuntu, with Linux 3.5.0-45-generic
$ update-grub && reboot
#.... wait for reboot....
$ uname -r

I've tried editing /etc/default/grub as well as grub-reboot, and adding GRUB_DEFAULT=saved but with zero success. I normally end up shuffling the order of configuration files in /etc/grub.d to do what I need. Obviously, editing a menu.lst was much preferred to this shenanigans.

Has anyone had any of these features work? Did it take any tricks? I find it hard to believe that this could be broken this horribly and I feel that I'm clearly missing something.

share|improve this question
Just use Syslinux... – jasonwryan Feb 3 '14 at 17:24
Is it possible to script (i.e. not using sed or perl) booting into different kernels using syslinux? I'm looking to switch back and forth from Xen programmatically. – zje Feb 3 '14 at 17:40
@jasonwryan Heresy! Use lilo – Elliott Frisch Feb 3 '14 at 18:03
@ElliottFrisch - I miss lilo, reminds me of my much simpler slackware days – zje Feb 3 '14 at 19:13
Have you tried using an integer (like 2 or something, whatever position your preferred menu entry has) as the default? Maybe the string matching with Ubuntu, with Linux 3.5.0-45-generic somehow doesn't work...? – Martin von Wittich Feb 3 '14 at 19:43
up vote 4 down vote accepted

I never had much luck with the abstracted configurations, mainly due to my lvm + mdadm setup and not updating my kernel the "distro way". Luckily, you can ditch all of that and roll your own grub.cfg very similar to how menu.lst worked.

A sample grub.cfg that is excerpted from mine is:

set timeout=15

menuentry 'Linux 3.10.17 (sde) kernel-3.10.17-g' {
  linux /boot/kernel-3.10.17-g domdadm dolvm root=/dev/md3
  initrd /boot/initrd-3.10.17-g

menuentry 'Linux 3.10.17 (sdf) kernel-3.10.17-g' {
  linux /boot/kernel-3.10.17-g domdadm dolvm root=/dev/md3
  initrd /boot/initrd-3.10.17-g

The biggest differences from grub-legacy is how root= is specified, the menuentry specification and the keyword change from kernel to linux to specify the kernel. If you have a menu.lst that works for you, you can easily adapt it to work as grub.cfg by addressing those changes. If you need any of the extra functionality of grub2 (loading grub modules, etc), you can grab relevant lines from the distro scripts and add them to your file.

share|improve this answer
Thanks! I'm now trying to find a way to incorporate this into /etc/grub.d as this is a shared machine and I don't want someone clobbering my config by updating the kernel, etc... – zje Feb 3 '14 at 19:18

@casey's answer inspired me to come up with this solution based on the empty /etc/grub.d/40_custom file (the only difference being that my file is prefixed to come first):

$ cat /etc/grub.d/06_zje
exec tail -n +3 $0
#Copied this idea from 40_custom
menuentry 'Ubuntu 12.04.3, with Linux 3.5.0-45-generic' --class ubuntu --class gnu-linux --class gnu --class os {
  gfxmode $linux_gfx_mode
  insmod gzio
  insmod part_msdos
  insmod ext2
  linux /boot/vmlinuz-3.5.0-45-generic root=UUID=be201df4-2268-419a-92ea-fd123a5acdef ro
  initrd  /boot/initrd.img-3.5.0-45-generic

It's total hackery, but I can then change my boot order programmatically using a script the executes these commands:

ln -sf /etc/grub.d/06_zje /etc/grub.d/01_first && update-grub

For different OSes, I created different files in /etc/grub.d, e.g. /etc/grub.d/07_xen

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.