Fixing Ubuntu Kernel upgrade errors in grub

I've been running Ubuntu, since Feisty, on a couple of machines. During this time I've been burned a couple of times by menu.lst not being updated properly. This is just a couple of paragraphs on how to get back in action.

Symptom:

Machine won't boot, kernel message is something like:

Kernel Panic - not syncing: VFS: Unable to mount root fs

Reboot - when Grub starts up, try selecting the previous kernel. The previous kernel is usually 2 entries down the list. If you can do this then jump down to (Re-)Building the initram.img.

If you can't reboot from your HDD don't panic. Get a linux boot disk like the Ubuntu install or Knoppix CD/DVD and boot from that instead. Once you've booted from the CD/DVD:

  • Open an xterm.

  • List available volumes - look for your normal boot evice

  • Mount your Ubuntu HDD... try something like:
    sudo mount /dev/sda6 /mnt


  • chroot into your normal directory structure:
    sudo chroot /mnt /bin/bash


  • Move to the grub configuration directory:
    cd /boot/grub

Now you're on your normal HDD and any changes you make will impact your HDD not the CD/DVD you just booted from.

(Re-)Building the initram.img

Open menu.lst with your favourite text editor. Search for a line beginning with title. You should see an entry in this form:

title           Ubuntu 8.04, kernel 2.6.24-17-generic
root            (hd0,5)
kernel          /boot/vmlinuz-2.6.24-17-generic root=UUID=f4470c26-594e-4638-9f33-e1750e8baae8 ro quiet splash
initrd          /boot/initrd.img-2.6.24-17-generic
quiet

If you don't see the initrd line then you'll need to add it. Look closely at the kernel & initrd lines and you'll see that they both specify the kernel version. The difference is 'vmlinuz-' vs. 'initrd.img-'. Save any changes and exit the menu.list editor.

Verify that the initrd.img file above actually exists. If it does you can just reboot from your HDD and you should be good to go.

If the initrd.img file doesn't exist, then you'll have to create it. To create this you need to use the update-initramfs command. I used the command:

update-initramfs -c -k 2.6.24-17-generic

If you had to boot from a CD/DVD then you should exit from the chroot environment and unmount the HDD.

Reboot from your HDD and you should be good to go.