Ubuntu LiveUSB recovery using chroot
When you’re playing with alpha versions of Ubuntu and you accidentally delete your kernel, don’t fret and think to yourself about backing up your data and reinstalling. Get in there and fix it with a chroot command.
I found myself loading grub with only a memtest option available. A sinking feeling crept up, but I wasn’t too worried as it’s not like a Windows booting problem where the only answer is to back up and restore. I had another Ubuntu PC handy and first created a fresh LiveUSB device via the new LiveUSB creator tool in Intrepid. Pressing F12 to pick my USB drive as the boot device and I was at a friendly desktop moments later.
At this point, I’m feeling pretty good. I don’t even know if my data is safe, but at least my PC loads a desktop and I can get on the internet. A quick couple clicks and I’m browsing my old home folder and all my data. Phew! Now to figure out what went wrong to leave me kernelless and to fix it.
I needed to get into my old installation to be able to run package tools. I googled and it took me a short while, but I found a gentoo wiki article about the subject. Basically, we want to mount our root drive and boot drive and mount a few system directories to our chrooted environment.
In my case, /dev/sda3 was my /boot and /dev/sda6 was my /. If you don’t know, you can always run ‘fdisk -l’ to give you an idea of your partitions. My commands were as follows.
mount /dev/sda6 /media/ubuntu
mount /dev/hda3 /media/ubuntu/boot
mount -t proc none /media/ubuntu/proc
mount -o bind /dev /media/ubuntu/dev
Then to get networking in my new environment, I ran:
sudo dhclient eth0
Now I’m in business and am back at a root terminal in my installed to HD OS. From here, I was able to “apt-get install linux-generic” and I had a working kernel again. 🙂 If you have other broken packages, “apt-get -f install” and “dpkg –configure -a” are your friends in troubleshooting.
All said and done, I didn’t lose any data and I’m rockin Jaunty with a kernel again!

No Comments »