Linux Technology

Dedicated to people who wrote the code.

Populating chroot Using yum

Linux admin often finds himself in a need for a temporary testing installation to check or simulate new configuration or to experiment with a new technology outside of the production system. Some paranoid admins deploy chroot jails as means of separating network services from the rest of the system in order to isolate potential attacker.

Whatever be the reasons, the admin is ultimately challanged with populating the chroot with binaries for applications that will run within. For Fedora and derivates, one way to do this is using the yum.

Because it is often advantageous not to use plain chroot, but rather new Linux Containers (or LXC), I will assume they will be used when deciding on naming. Feel free, however, to use your own naming schema.

Place for chroots

It does not matter where is the chroot system placed, but for additional comfort I recommend using a logical volume with btrfs file system. This combination will provide means for growth when required and the valued snapshot capability, which makes it possible to create several installations swiftly, with lower storage costs.

lvcreate -n lxc -L 50G datavg

Create new logical volume.

mkfs.btrfs -L lxc /dev/datavg/lxc

Format it as btrfs file system.

Installing Release Packages

We need to do two things. Initialize RPM database and get mirror configuration for yum. Both these things can be done at once by installing release information RPM packages.

wget 'ftp://ftp.sh.cvut.cz/MIRRORS/fedora/linux/development/rawhide/x86_64/os/Packages/fedora-release-[1-9r]*'

Download Fedora release information packages. Use whichever mirror you like, this (these) files are small and the mirror choice won't reflect in the next steps.

btrfs subvolume create /lxc/test01

Create btrfs subvolume for chroot.

rpm --root=/lxc/test01 -ivh fedora-release-*.rpm

Install the packages to the chroot.

Installing Base System

Now when yum operation prerequisites are in place, we can install the yum into the target system. This will also pull in most of the things you would expect in an ordinary Linux system.

This step is actually not necessary as you can install directly the package you wish to run, but since it is much more comfortable to just enter the chroot and act like it was a separate system, I include it nevertheless.

yum --installroot=/lxc/test01 install -y yum

Install yum and it's dependencies into the chroot.

With this, you now have a system that you can chroot into. It lacks kernel-based filesystem mounts and proper configuration, however. That topic is covered in other documents.

Entering the chroot

Entering the chroot is a rather simple matter of one command. If you need to start init in there, you need to use LXC.

chroot /lxc/test01

Enter the chroot and launch /bin/sh.