For about eight years I ran Gentoo Linux before I eventually gave it up, and moved on to Ubuntu. It was remarkable in that it provided a BSD like ports system and let you compile your system from the ground up. It also tended to break, a lot.
Even today, almost all x86 linux distributions can run (in theory) on a 32bit 386 processor. Let’s be clear though, while it is a remarkable (and successful) processor, the 386 is an antique. The selling point of Gentoo was that it was one of the few distributions to give you the power to build a system, specifically for modern processors abandoning backwards compatibility for long-obsolete ones.
In the early days you had to start from what was called a (and I don’t think they do it this way anymore) ‘stage 1’ install. A stage 1 install is where all you have is a bootable livecd with a few basic set of tools: a c compiler, a shell and the basic gnu coreutils…and irssi. Enough utilities to allow you to build further C packages. You’d run the command ‘emerge system’ and it would go off and build gcc, glibc, coreutils etc. Once these were built you’d then rebuild glibc, and gcc with your newly compiled, architecture specific, compiler and c library.
Anyway, this took a long time, particularly on sub gigahertz Pentium 2s and 3s, and Gentoo systems tended to break a lot, and by break, in the absolute best case, I mean merely became un-bootable.
The process to recover the system was pretty much the same as to install it, you had to boot from a livecd, configure your network card, hook up to the network, then chroot to the broken disk. At this point you could try and repair whatever damage you had caused.
These days if you do something silly, like I don’t know, try and dist-upgrade from Ubuntu Oneiric to Precise, you can get that true Gentoo feeling (i.e. nothing works and you can’t boot the machine).
This happened to me this afternoon and the hard yards done with Gentoo came to the rescue.
Here’s how you do it.
Boot up from a livecd (or usbkey), get the network card modules loaded and get a dhcp address. With the Precise Live DVD you can do all of this pretty easily by selecting the ‘try without installing’ option from the bootloader.
Once you’re online, you need to prepare the mount. First step is to mount the root partition somewhere, I typically use /mnt/ so say /mnt/oneiric (it can be whatever). If you’re not sure of your partition numbers, your livecd will almost certainly come with fdisk with which you can push ‘p’ to print the partition table.
$ mount -t ext4 /dev/sda5 /mnt/ubuntu
If you have a separate boot partition mount that too.
$ mount -t ext2 /dev/sda1 /mnt/ubuntu/boot
Now in order to have a functional chroot, we need the proc, dev and sys subsystems to be mounted onto the chroot. This is the tricky bit.
$ mount -t proc none /mnt/ubuntu/proc
$ mount -o bind /dev /mnt/ubuntu/dev
$ mount -o bind /sys /mnt/ubuntu/sys
In the case of the sys and dev dirs, we need to reference the exact same mountpoints as the host so we use the -o bind option.
Last thing, we want to have functional network name resolution so we copy over the host’s /etc/resolv.conf to /mnt/ubuntu/etc/resolv.conf
Now the chroot is ready
$ chroot /mnt/ubuntu /bin/bash
$ source /etc/profile
The chroot will be pretty much as it would be if you’d booted into it normally with a few exceptions. The kernel and kernel modules will be those of the host. If you need to access some specific hardware you need to set this up on the host.
My busted Precise install was fixed with a simple apt-get update and upgrade, before re-running the grub installer.