Recently, I’ve been wanting to build package for my not very powerful eee-pc laptop. I just have one problem: all my computers except this one are use a 64bit architecture instead of a 32bit one. So I needed to make a chroot. So, instead of doing that I decided to play a little with systemd containers. Here is what I did.

Install a 32bit arch in a folder somewhere

I’ve decided to do that in my home folder. First, I made a copy of my /etc/pacman.conf, called pacman-i686.conf, in my home folder with the architecture explicitely stated as i686. So I’ve changed this line: Architecture = i686

Then, I’ve installed the extra/arch-install-scripts package.

After that, I created a folder and used pacstrap to install a basic arch in it using my custom pacman-i686.conf file. I use sudo because I’m lazy but you can do that using your root account, you just need to change your paths accordingly. Also, please disable the multilib repository, it won’t work.

sudo pacstrap -C ~/pacman-i686.conf -c -i -d ~/i686 base

The first option, -C ~/pacman-i686.conf will allow you to choose a pacman.conf different than your host’s /etc/pacman.conf, the second one -c uses the host’s cache instead of the target’s so that you can remove it more easily later and managing like the rest of your package cache. The -i option will disable auto-confirmation of packages so that you can choose what you install. And last, the -d option allows you to chose a non-mountpoint directory.

Starting the container

Simply use that command, the same thing about paths, sudo and root stays valid. sudo systemd-nspawn -bD ~/i686

It is now working. Login as root, there is no password. You might now want to install stuff, build packages, etc.

For some weird reason, my guest pacman.conf architecture was set on auto and it tried to install 64bit packages, probably due to my host, be sure to change it to i686. Make sure to synchronise your pacman databses with pacman -Syy to make sure you don’t have any x86_64 packages.

Managing the container

The first step we have to do is to symlink the container to /var/lib/container/. Again, paths, sudo, root.

sudo ln -s ~/.i686 /var/lib/container/i686

I had to create /var/lib/container.

Now, you can see your container using machinectl list. Don’t mind my prompt.

“-> % machinectl list MACHINE CONTAINER SERVICE i686 container nspawn

1 machines listed.“

You can now do fun stuff. man machinectl

Remember that you need to launch the machine using systemd-nspawn. Like that in the case of our example :

sudo systemd-nspawn -bD ~/i686

Edit: 2014-10-26

You can also use systemctl to launch the machine. Just use sudo systemctl start systemd-nspawn@MyContainer.service, in our case, the service is systemd-nspawn@i686.service. It will start and be listed in machinectl’s list. You can also enable the service to start it with your computer.


Mostly Arch’s Wiki, pacstrap --help, and man machinectl