Ross's Shared News Items

Friday, August 01, 2014

Boot an unbootable Ubuntu Linux system with chroot

How to recover an unbootable Linux system. This is mostly documentation for me since I KNOW I will needs this again.

Situation:

1) You have a somewhat unique Linux system and your system does not successfully complete the upgrade process,
2) You made some critical updates to system configuration or boot files and now the compuiter won't boot.

Here's what to do: Materials: 2GB USB stick for boot device. Optional: Reasonably large USB drive for data recovery if needed

Make a bootable USB stick or DVD of the latest Ubuntu as described here

Boot your troubled system from an alternate boot device - namely the USB stick. If your computer doesn't support boot from USB and you need a DVD, you can make one and boot from it, but it is significantly slower.

Choose: 'Try Ubuntu', and you should have a mostly fully functioning Ubuntu system that has already mounted any other block devices visible to the system

Find mounted devices with: mount |grep dev - find your other boot partition - it's probably something like /dev/sda1 or /dev/sda2.

Assuming it's /dev/sda2, do this to create a chroot environment with networking out of your problematic partition that won't otherwise boot:

sudo mount /dev/sda2 /mnt/chroot/
sudo mount -o bind /proc /mnt/chroot/pro1
sudo mount -o bind /dev /mnt/chroot/dev
sudo mount -o bind /dev/pts /mnt/chroot/dev/pts
sudo mount -o bind /sys /mnt/chroot/sys
sudo cp /etc/resolv.conf /mnt/chroot/etc/resolve.conf
sudo chroot /mnt/chroot /bin/bash
 The one modification to this that I had to make in my Ubuntu 13.10 --> 14.04 mess image was that I had to move the /mnt/chroot/etc/resolv.conf manually to another file and then copy over a simple text file for resolv.conf

Open another terminal window - one for USB booted OS, one for chrooted OS.
In the USB window, enter 'xhost +' to allow displaying GUI apps from the chroot environment running as root.

Now, in chroot window, edit or fix whatever you know is broken if you just broke it. If you're in the middle of an upgrade, try to continue it.

sudo apt-get update
sudo apt-get dist-upgrade

If there are any errors, try 'sudo apt-get dist-upgrade -f'
Watch the updates, and any interactive prompts that come up.

When it completes, or fails...

sudo apt-get update    <--- again
synaptic &    <--- use GUI to resolve as many of the upgrade dependencies as possible

shut down USB booted OS. Remove USB. Boot system normally. Cross fingers.