Chroot from a livecd

Occasionally a Linux install will end up unbootable. It could be because another OS has overwritten the MBR, or there's a problem with boot scripts or kernel configuration.

This guide shows how to perform a "chroot" from virtually any live CD (or another Linux) environment to allowing diagnosing and fixing the problem.

Limitations
While a chrooted install from a live CD has excellent functionality, it won't be complete. For example, the chrooted system is still using the kernel of the live CD. This means that any relevant kernel driver modules not already loaded will need to be modprobe'd before entering the chroot. For the same reason, any kernel modules only available in the chrooted system (such as ndiswrapper or other third party modules) can't be loaded.

To solve the problem of drivers, either locate a live CD that does contain the drivers requried or alternatively consider creating a live CD specifically for the system.

Prerequisite knowledge
This guide assumes knowledge of the hardware of the system to be chrooted and the drivers (specifically kernel modules) required by that hardware. It also assumes command line knowledge equivalent of someone who has completed an install using the Gentoo Handbook (since most of the steps and instructions are very similar).

Preparing the live CD environment
Before actually chrooting to the install, the live CD environment needs to be prepared using the following steps:
 * Load any required kernel modules. Some are autoloaded for you.
 * Set up the network if you think you may need it.
 * Initialize any available swap with, for example (where is a swap partition):.

Mounting the installed system
First a quick note on mounting filesystems. While it's possible to mount filesystems from within the chrooted system, this is not recommended. The reason for this is that the live CD environment won't know about these mounted systems, so if they are forgotten about and left mounted, they will not be unmounted properly when the system shuts down, which could cause damage to the filesystems on those mounts.

Mount the root (and if necessary, ) partitions of the installed system. If separate partitions are used for other areas of the system (for example, a separate partition for ) then these will also need to be mounted.

In the following example, is the  partition and  is the root partition.

Additionally, mount the and  filesystems so that they can be used by the chrooted environment.

Chrooting to the installed system
Before you chroot, you want to copy over so that your chroot environment can resolve domain names:

To actually enter the chrooted environment, the steps are the same as those used in the Gentoo Handbook:
 * Chroot to the installed system.
 * Ensure the environment is correct.
 * Add a reminder to the command prompt.

Reinstalling Grub
Grub reads the file to learn about the currently mounted filesystems, so this needs to be up-to-date. You can update it from by running:

Exiting the chroot
When finished, ensure that all running programs have stopped and then run the following commands to exit the chroot and unmount the mounted partitions. Don't forget to unmount any other mounted partitions before unmounting.

If you receive a message stating that a given mount is busy, this can mean one of two things:
 * A program was left running inside of the chroot.
 * Or more frequently: A mount point still exists on this mount. For example, is still mounted when trying to unmount.

In the latter case, simply unmount the offending mount point first. To get a reminder of all the current mount points, run mount with no parameters.

Exec format error
If the chroot command returns with the error "", this usually indicates that the live CD environment is not compatible with that of the installed system.

For example, the error is most frequently seen when trying to chroot to a 64-bit system (eg. ) from a 32-bit live CD (eg. ).

The solution is to use a live CD which is using the same architecture as the installed system.

For building a 32bit gentoo from a 64bits livecd there is a useful trick :

Chroot von einer Live-CD Chroot depuis un live CD Chroot_z_live CD live CD kullanarak sistemi açmak