I have been using some form of GNU/Linux as my main operating system for the best part of 5 years now. In general, I am a very happy user - most of the software I use ‘just works’ and the time I need to spend doing system administration is minimal. However, very occasionally I end up succumbing to the temptation of bleeding edge, and my computer refuses to boot…
Don’t panic!
So the Linux heart has stopped beating, and you can no longer access your precious OS. What do you do? Well the first thing is to remain calm, don’t try anything crazy like doing a complete reinstall, I can almost guarantee you won’t need to.
Pull your bootstraps up
The first thing you need is another means by which to boot your machine so you can mount your hard drive and access your data. This process is known as bootstrapping. There are a number of dedicated rescue disks for this purpose, but most of the time your distribution CD will be just fine. I recently used an Xubuntu CD to rescue an Ubuntu system, because I couldn’t find my Ubuntu disk.
Basically you need to get yourself booted into a shell on your machine ASAP, so you can get to fixing your system. To do this, some disks provide a ‘boot into rescue mode’ option, others will give take you straight into a window manager from which you can launch a terminal. For older disks, you might have specify ‘linux single’ to the the ‘boot:’ prompt to boot into single-user mode.
The kiss of life
Booting into a shell from your CD isn’t in itself going to bring your system back to life. For this you need to switch to a chrooted environment, and I always forget the exact process, hence this blog post! (I recommend writing the following commands on the cover of your boot CD as a future aide-mémoire).
Firstly you need to mount your system disk at a mount point in the current shell’s virtual file system. Something like:
mkdir /mnt/mydisk
mount /dev/sda3 /mnt/mydisk
Where /dev/sda3 is the system disk partition you are recovering. If you can’t work out which partition holds your system, fdisk -l might give you some hints. If you can’t mount your system partition, you are probably in more serious trouble, perhaps try running fsck on the wounded partition e.g. fsck /dev/sda3.
Now we have a mounted system partition, we are half way to accessing it, but first we must bind to our current /dev tree. This means that when we perform the chroot, our new environment will still get access to the special /dev (device) file system:
mount --bind /dev /mnt/mydisk/dev
Now we are ready to chroot:
chroot /mnt/mydisk/dev
It’s alive!
If you’ve got this far, it’s good news, you have now successfully mounted your system partition, and are you are no longer in the boot CD shell, but instead inside a chrooted shell. This means that your system disk root is now your working root. To confirm this try ls -al.
More special file systems
With Linux (and other Unixes), from the Kernel’s perspective everything is a file. Before we did the chroot, we bound to the /dev filesystem, which provides access to devices such as the computer’s disks, sound card etc. We now need to mount the proc and sys file systems:
mount -t proc none /proc
mount -t sysfs none /sys
What to do next?
This article can help you no further! How to get your system back to a state where it boots depends on exactly what your problem is. In my most recent experience, I had corrupted my lilo configuration, and just needed to fix a symbolic link, and re-run lilo -b /dev/sda3. You’ve done the resuscitation, now for the surgery…