Chroot

Chroot is one of the (thousand) reason because I love Linux!

From Wikipedia

A chroot on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children.
A program that is run in such a modified environment cannot name (and therefore normally not access) files outside the designated directory tree.
The term "chroot" may refer to the chroot system call or the chroot wrapper program.
The modified environment is called a "chroot jail".

To execute a fully working chrooting you should know some trick:

Same architecture systems

allow x access (if nedded)

xhost+ # be careful with this command, it disable x access policy

mount your device (if exist)

CHROOTDIR="/tmp/myfirstchrooting" # "destination" folder
mount /dev/sdx $CHROOTDIR # if the source is a device
mount /path/linux.img $CHROOTDIR -o loop # if the source is an image

copy base system file

(REMBEMBER THAT YOU ARE REPLACING)

sudo cp /etc/hosts $CHROOTDIR/etc/hosts
sudo cp /etc/fstab $CHROOTDIR/etc/fstab
sudo cp /etc/resolv.conf $CHROOTDIR/etc/resolv.conf

mount all system folders

sudo mount -o bind /proc $CHROOTDIR/proc
sudo mount -o bind /dev $CHROOTDIR/dev
sudo mount -o bind /dev/pts $CHROOTDIR/dev/pts
sudo mount -o bind /dev/shm $CHROOTDIR/dev/shm
sudo mount -o bind /tmp $CHROOTDIR/tmp
sudo mount -o bind /var/tmp $CHROOTDIR/var/tmp
#sudo mount -o bind /proc/bus/usb $CHROOTDIR/proc/bus/usb # not more really useful
sudo mount -o bind /sys $CHROOTDIR/sys

enter in the new system

sudo chroot $CHROOTDIR /bin/bash

export display

export DISPLAY=:1

Alien chroot (for example armel inside amd64)

This is the reason because I love Debian! :D You should do these two steps and then forget that chroot destination is a foreign architecture!

install qemu static binary and binfmt-support helper

sudo apt-get install qemu-user-static binfmt-support

copy static binary in chroot

cp /usr/bin/qemu-arm-static /target_fs/usr/bin # replace "arm" with your foreign architecture
Navigation
Print/export
QR Code
QR Code Chroot (generated for current page)