This guide will show you how to create chroots to assist in testing packages for stabilization.
What is a chroot?
A chroot is a operation to change the root directory of the current process and the children spawned from it. In the simplest terms, it allows us to setup a completely separate install inside the one that you are already running.
Setting up your chroot for a new install
The first thing that you need to do is create a directory for your chroot to reside; it needs to have enough space for a second install.
The next step is to download a stage three tarball to the chroot and untar it:
Stage filename shown below is an example, actual filename may vary # mv stage3-x86.tar.bz2 /foo # cd /foo # tar xvjpf stage3-x86.tar.bz2
To actually proceed with the install at this point, you need to mount a few directories from your live system to the chroot.
You might have to create some of the directories in your chroot to be able to mount them, as you'll get the mount point does not exist.
Mount the following directories to their appropriate area within your chroot. # mount -t proc none /foo/proc # mount -o bind /dev /foo/dev # mount -o bind /usr/portage /foo/usr/portage # mount -o bind /usr/src/linux /foo/usr/src/linux # mount -o bind /lib/modules /foo/lib/modules # mount -o bind /sys /foo/sys # cp /etc/resolv.conf /foo/etc/resolv.conf Finally, if you want one /tmp for both # mount -o bind /tmp /foo/tmp
You might want to create a simple bash script you can run before you chroot to the directories for the future. It makes it a easier task to run one script then having to remember what each mount you need to do.
As you will notice this is by no means a secure chroot but for what we need it doesn't need to be. With all that mounted you can actually go into your new setup.
# chroot /foo /bin/bash
As you are now in your new chroot, you can start a standard install from Configuring Portage.
Running X apps inside the chroot
In order to be able to launch applications with a GUI from inside your chroot when your X session was started outside the chroot, there are a few extra steps you must follow.
First, you must be using /tmp from outside the chroot (see above). Second, since /dev/pts is a separate filesystem to /dev you will need to mount that as well.
# mount -o bind /dev/pts /foo/dev/pts
You will also need to copy your ~/.xauth file to the home directory of your user in the chroot:
# cp /home/user/.Xauthority /foo/home/chroot_user/ # cp /home/user/.xauth* /foo/home/chroot_user/
You will need to redo this every time you restart X.
Finally, when you are inside your chroot, you need to set the DISPLAY environment variable.
# export DISPLAY=":0.0"
This article is based on a document formerly found on our main website gentoo.org.
The following people have contributed to the original document: Joshua Jackson, David Morgan, Shyam Mani, Mark Loeser
They are listed here as the Wiki history does not provide for any attribution. If you edit the Wiki article, please do not add yourself here, your contributions are recorded on the history page.