Chroot/en

Chroot (Change root) is a Unix system utility used to change the apparent root directory to create a new environment logically separate from the main system's root directory. This new environment is known as a "chroot jail". A user operating inside the jail can not see or access files outside of the environment they have been locked into.

One of the main uses for chrooting is to create a separate Linux system on top of a the current one for the purpose of testing or software compatibility. Chroot is often seen as a lightweight alternative to virtualization because it is able to run without the overhead of a hypervisor.

Setting up the environment
When creating a new chroot setup, the first thing needed is a directory for the chroot to reside in. For example, a chroot could be created in :

To mount an existing installation from a partition the following command can be ran. Be sure to replace the  string in the example below with the drive and partition of the existing installation:

If an installation has been previously created in a sub directory of the current root file system the above steps can be skipped.

Unpacking system files and the Portage tree (new installations)
If you're building a new install, the next step is to download the stage3 and portage tarballs and set them up in the chroot location. For more information on this process please see sections 5a and 5b in the Gentoo Handbook.

Configuration
Before entering the chroot we need to mount a number of directories.

Some basic configuration files will need to be copied from the host, do not copy over when using an existing installation:

Once done enter the chroot environment by executing the following commands:

When creating a new installation, you can sync portage to make sure everything is up to date.

The system is now ready. You can install software, mess with settings, test experimental packages and configurations without having any effect on your main system. To leave the chroot simply type "exit" or press +, this will return you back to your normal environment. Don't forget to umount directories you've mounted.

Init scripts
If you need to do this often, you can speed up the mounting of the directories needed for a chroot by using an init script:

If you use a different directory or partition, add the necessary mounting commands in start and change if you use a different name.