When I needed specific linux distribution on a modern linux host, I used to utilize schroot. More robust solution would be to use LXC. However the same page suggests systemd-nspawn as an alternative. So I tried it the other day when needed to prepare CentOS 7 for my work.

Setup is easy: just obtain root file system tree. Needed to work around inaccessible /tmp/.X11-unix within the container — bound directory explicitly from non-tmpfs. Created launch script to launch the system conveniently:


cur_dir=`readlink -f $(dirname ${BASH_SOURCE[0]})`

xhost +local:

# Note that --bind /tmp/.X11-unix doesn't actually preserve sockets,
# pass them through /w

sudo systemd-nspawn \
    -D $cur_dir/centos \
    -b \
    -n \
    --bind /w \
    --bind /home/sakhnik

The result is impressive. The system “boots” into login terminal:

Booted CentOS 7

I used virtual network ethernet connection in the container with systemd-networkd:

Network configuration

So far, so good. Let’s see later how usable the container is.