You are here

How to chroot

Here is a good link on how to Recover a Non-booting Linux System

and the core:

sudo fdisk -l #find the destination file system
ROOT=/dev/sda #set it here

sudo mount $ROOT/mnt
for i in /sys /proc /run /dev /dev/pts; do sudo mount --bind "$i" "/mnt$i"; done
sudo cp /etc/resolv.conf /mnt/etc/ #only if there was a network problem before
sudo chroot /mnt

Older link:
ubuntu@ubuntu:~$ sudo mount /dev/sda6 /mnt
ubuntu@ubuntu:~$ sudo mount /dev/sda1 /mnt/boot
ubuntu@ubuntu:~$ sudo mount /dev/sda7 /mnt/home

Verify everything looks correct before proceeding (i.e. you got the partitions correct and mounted in the correct places).

Next, you need to take care of /proc and /dev as follows:

ubuntu@ubuntu:~$ sudo mount -t proc none /mnt/proc
ubuntu@ubuntu:~$ sudo mount -o bind /dev /mnt/dev

Ok, now you have setup your chroot environment, and may change into it:

ubuntu@ubuntu:~$ sudo chroot /mnt


From Arch...
Here's two scripts I use to chroot:
(replace sda7 with your karmic partition)
## /mnt
mount /dev/sda7 /mnt/
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /dev/pts /mnt/dev/pts
cp /etc/resolv.conf /mnt/etc/resolv.conf
chroot /mnt/ /bin/bash

Now Inside karmic, I update using this method:

sudo aptitude update && sudo aptitude full-upgrade

When complete, Ctrl+d to release chroot. Then I run the following script to cleanly unmount everything:

## /mnt already exists
umount /mnt/dev/pts
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt