
This question relates to questions that are asked often. The procedure is frequently mentioned or linked to offsite, but is not often clearly and correctly stated. In an objective to concentrate useful information in one place, this question seeks to provide a clear, correct reference for this procedure. What are the proper steps to prepare a chroot environment for a recovery procedure? In many situations, repairing a broken Linux installation is best done from within the installation. But if the system won't boot, how do you fix it from within? Let's assume you manage to boot into an alternate system. Once there, you need to access your broken installation in order to fix it. Many recovery How-Tos recommend using chroot in order to run programs as if you are actually booted into the broken installation.
As this is Community Wiki, feel free to edit this question to improve it as well. | ||||
Here are some resources:
"Changing root" or "chrooting" is a method for zooming in on part of your filesystem, so that, for example, Preparation
Performing the chroot If your Similarly for any other parts of your filesystem ( (It's also possible to mount filesystems after you've chrooted, but it's smarter to do so beforehand. The reason is that when you do it after, the outside/kernel environment won't know about the mounted filesystems, so if you forget to umount them before exiting the chroot, the system won't know to umount them when it shuts down, either. This could damage those filesystems.) If you've setup your network and want to use it in the chrooted system, copy over Now you're ready to move into the mounted filesystem: (If this returns an error At this point, you're still running the kernel you booted with, but all paths If you'll be doing anything with GRUB, you'll need to be sure your It might also be helpful at this point to do: Do your dirty workAt this point, you can perform whatever troubleshooting you need to do:
Cleaning upWhen you're finished, ensure that all running programs have stopped. Then exit the chroot: Now unmount all the partitions you mounted: Finally attempt to unmount your hard drive: If you get an error saying that /mnt (or any other partition) is busy, this can mean one of two things:
In the latter case, simply unmount the offending mount point first. To get a reminder of all the current mount points, run Finally: | ||||
chroot.shin the root of every system that I use, whose contents more or less match the above. When I need to chroot into that system from a LiveCD or something, then I just mount the root filesystem and run the chroot script. No more frantic googling for the right commands. – Ryan Thompson Apr 14 '10 at 1:01