Chroot jails are a neat way of building for target Linux distros without having to run the distro in a vm. For example, in my case, I can host the filesystem for RHEL on my Arch linux machine and then build binaries for RHEL that will be compatible. All I need to install is rpm and yum and because it’s not native to Arch which I got from the Arch user repository. A program call
schroot makes the configuration and mounting the chroot environment easier and less error prone. It will mount /dev and /proc and /home from the host into the chroot and copy basic system database files over so that when you log into the chroot your home directory from the host is automatically mounted inside the chroot guest and you’ll be able to use the system like it is a native (insert name of guest chroot here) distribution.
This is how I setup the RHEL chroot on Arch. Obviously I installed
yum previously. How you install those programs depends on your distro.
sudo mkdir /srv/chroot/rhel
wget http://<some yum repo>/packages/redhat-release-server-6Server-220.127.116.11.el6.x86_64.rpm
sudo rpm --root=/srv/chroot/rhel --nodeps -i redhat-release-server-6Server-18.104.22.168.el6.x86_64.rpm
Then configure yum on the chroot to point to the yum repository you want to use. For example:
$ cat /srv/chroot/rhel/etc/yum.repos.d/rhel-ericsson.repo
Then install yum in the chroot.
sudo yum --installroot=/srv/chroot/rhel6.6/ install -y yum
schroot for this guest. Create an entry like the following in
The keys are fairly self-explanatory. The
directory because well the guest is layed out in, yes you guessed it, a directory
users are the users you want to allow access to the chroot.
root-users are users on the host you want to allow to login as root inside the guest.
profile is the name of the schroot profile described next. See
man schroot.conf for a full description of all keys.
Next create a directory with the same name assigned to
sudo mkdir /etc/schroot/rhel
Add the following files in that directory. For example:
sashan@phoenix ~/code > cat /etc/schroot/rhel/nssdatabases
# System databases to copy into the chroot from the host system.
# <database name>
sashan@phoenix ~/code >
sashan@phoenix ~/code > cat /etc/schroot/rhel/copyfiles
# Files to copy into the chroot from the host system.
# <source and destination>
sashan@phoenix ~/code > cat /etc/schroot/rhel/fstab
# fstab: static file system information for chroots.
# Note that the mount point will be prefixed by the chroot path
# <file system> <mount point> <type> <options> <dump> <pass>
/proc /proc none rw,bind 0 0
/sys /sys none rw,bind 0 0
/dev /dev none rw,bind 0 0
/dev/pts /dev/pts none rw,bind 0 0
/home /home none rw,bind 0 0
/tmp /tmp none rw,bind 0 0
sashan@phoenix ~/code >
Then you are done. Now you can login to the chroot as your username or
root. For example:
schroot -u sashan -l rhel -s /bin/bash
schroot -u root -l rhel -s /bin/bash
Once inside you might need to run
$ rpm -vv --rebuilddb
to make sure the rpm database works nicely.