Ubuntu 12.04 updates on an external HDD–Grub recovery fight

Okay, I know what you guys will tell me now. That there are tons of tutorials on the internet on various sites on how to install Ubuntu on an external HDD. The knowledge level will vary between using UNetBoot to burning a CD and booting from it. As with all my articles, I will write my experiences here so that I can refer to the same in future if needed and also spread the information on various aspects of upgrades of Ubuntu on external HDD. And by external HDD, I mean the external HDD with rotating platters. Not a huge USB stick or any other MMC but an external HDD.

Ubuntu as well know comes with Grub2 in its latest incarnation. And I don’t know if it is a problem with Ubuntu (I am pretty sure it would be) or with Grub but whatever external HDD you install to, the MBR of your primary disk will always be replaced with a Grub2. So before trying any heroics and to have a truly portable Linux installation, burn the Ubuntu ISO to either a CD/DVD or better still, use a USB stick and make it bootable using the many methods you read on the internet.

Once done, shutdown and disconnect your mail HDD. Now start with booting your computer and install Ubuntu as you normally do. During installation Ubuntu writes to the proper external HDD and also installs Grub2 on the HDD. In my case, the external HDD was mounted on /dev/sde (my PC has a list of attached USB drivers including MMC readers and stuff so I got the e number there). In any case, I reboot the PC and everything goes fine.

Now comes the time for an upgrade. Again at upgrade/update time, I recommend to remove the primary HDD and just do the boot from USB HDD and then upgrade/update. And you already know why. Because Ubuntu screws up here. Again, if you primary HDD is attached, it will write the Grub updates to that HDD. And the best part comes now. Even if your primary is not attached, it will in the Grub config try to mount /dev/sda for vmlinuz and initrd images!

Hola, I am not joking. Even though the drive GUID is used, Grub will have problems finding the kernel and initrd images after the update. While booting after update, you will instantly end up in Grub recovery. For someone inexperienced with Grub, the only option would be to use a liveCD to put the proper MBR back and fix the Grub config. But instead below, I will show you how you go about navigating yourselves to sanity.

So when you land up in Grub recovery, execute ls (i.e. ELL ESS not III ESS). You should see something like hd0, (hd0,msdos1) depending on the USB HDD and the number of partitions you have created while installing Ubuntu. To keep things simple, I had just asked Ubuntu to use the whole disk, so I got only those 2 partitions. Anyways, the first one is the disk which starts with 0 and the next one is the partition which starts with a 1. Yep, I know it is confusing but that is how it is.

Now type in find / and press tab. You should see your root FS and find the kernel and initrd images. So now all you need to do is point Grub to the proper files and off you go. For me the commands look like below:

set root=(hd0, msdos1)
linux /vmlinuz root=/dev/sde1
initrd /initrd.img

In the above code segment, you can also use (hd0,msdos1)/vmlinuz instead of /vmlinuz and same with initrd.img. Also notice that in the second line, I have specified my root partition to mount at /dev/sde1 since my original installation was at /dev/sde. You can also check your boot logs by specifying a random entry like /dev/sda. The onscreen logs will show you a root mount error and show a list of possible devices. Now you select one more and proceed. Once that is done, Ubuntu should boot up. Now before doing anything, fire up terminal and issue a sudo update-grub that writes the proper stuff to your grub config. Pretty easy to keep handy when stuff goes wrong because of a small, simple update right?

If you want to read more look at the below links:


So, there you have it lads. Now enjoy your portable installation with any machine. Just take precaution while upgrading/updating.