[Guide] Chrooting into a Gentoo Linux system

Chrooting

Optional: Selecting Mirrors

In order to download source code quickly it is recommended to select a fast mirror. Portage will look in your make.conf file for the GENTOO_MIRRORS variable and use the mirrors listed therein. You can surf to our mirror list and search for a mirror (or mirrors) close to you (as those are most frequently the fastest ones), but we provide a nice tool called mirrorselect which provides you with a nice interface to select the mirrors you want. Just navigate to the mirrors of choice and press spacebar to select one or more mirrors.

Code Listing 1.1: Using mirrorselect for the GENTOO_MIRRORS variable

# mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

A second important setting is the SYNC setting in make.conf. This variable contains the rsync server you want to use when updating your Portage tree (the collection of ebuilds, scripts containing all the information Portage needs to download and install software). Although you can manually enter a SYNC server for yourself, mirrorselect can ease that operation for you:

Code Listing 1.2: Selecting an rsync mirror using mirrorselect

# mirrorselect -i -r -o >> /mnt/gentoo/etc/portage/make.conf

After running mirrorselect it is adviseable to double-check the settings in /mnt/gentoo/etc/portage/make.conf !

Note: If you want to manually set a SYNC server in make.conf, you should check out the community mirrors list for the mirrors closest to you. We recommend choosing a rotation, such as rsync.us.gentoo.org, rather than choosing a single mirror. This helps spread out the load and provides a failsafe in case a specific mirror is offline.

Copy DNS Info

One thing still remains to be done before we enter the new environment and that is copying over the DNS information in /etc/resolv.conf. You need to do this to ensure that networking still works even after entering the new environment. /etc/resolv.conf contains the nameservers for your network.

Code Listing 1.3: Copy over DNS information

(The "-L" option is needed to make sure we don’t copy a symbolic link)
# cp -L /etc/resolv.conf /mnt/gentoo/etc/

Mounting the necessary Filesystems

In a few moments, we will change the Linux root towards the new location. To make sure that the new environment works properly, we need to make certain file systems available there as well.

Mount the /proc filesystem on /mnt/gentoo/proc to allow the installation to use the kernel-provided information within the chrooted environment, and then mount-bind the /dev and /sys filesystems.

Code Listing 1.4: Mounting /proc and /dev

# mount -t proc proc /mnt/gentoo/proc
# mount --rbind /sys /mnt/gentoo/sys
# mount --rbind /dev /mnt/gentoo/dev

Entering the new Environment

Now that all partitions are initialized and the base environment installed, it is time to enter our new installation environment by chrooting into it. This means that we change from the current installation environment (Installation CD or other installation medium) to your installation system (namely the initialized partitions).

This chrooting is done in three steps. First we will change the root from / (on the installation medium) to /mnt/gentoo (on your partitions) using chroot. Then we will reload some settings, as provided by /etc/profile, in memory using source. The last step is to redefine the primary prompt to help us remember that we are inside a chroot environment.

Code Listing 1.5: Chrooting into the new environment

# chroot /mnt/gentoo /bin/bash
# source /etc/profile
# export PS1="(chroot) $PS1"

Congratulations! You are now inside your own Gentoo Linux environment. Of course it is far from finished, which is why the installation still has some sections left :-)

If you at any time would need another terminal or console to access the chroot environment, all you need to do is to execute the above steps again. 

Attached Files
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Name
Email
Security Code Security Code
Related Articles RSS Feed
[Info] Useful Gentoo packages
Viewed 1351 times since Sun, Nov 9, 2014
[Info] Gentoo linux - useful commands
Viewed 1393 times since Mon, Oct 13, 2014
[Info] List of Gentoo packages with required kernel options
Viewed 2714 times since Fri, Sep 23, 2016
[Guide] Migrate Gentoo Portage to Git
Viewed 1727 times since Sun, Nov 6, 2016
MENU