mardi 16 décembre 2014

Mageia 5 systemd-nspawn

A killer feature of systemd is systemd-nspawn. From the man page, "Spawn a namespace container for debugging, testing and building", it is a kind of chroot on steroids, I feel, not limited to "testing and building", but with some care, can be used for production apps. There is little or no resources on how to use this tool on Mageia linux distribution which integrates systemd since a long time (Mandriva integrated Systemd before Mageia fork even exists).

Archlinux provides a rich set of docs which are a good practical starting point. This blog entry mostly adapt the systemd container pages to Mageia


The main differences between Archlinux and Mageia regarding these documents are the packaging system and the network configuration. The Mageia chroot page explain how to populate a directory (lets use a btrfs one) with base system with minimum configuration.

Lets suppose you have a directory named "mageia", first add all media:
  # urpmi.addmedia --distrib --urpmi-root mageia 
  ftp://mirror.netcologne.de/mageia/distrib/cauldron/x86_64/

Then install basesystem and other packages needed for your application:
  # urpmi  --urpmi-root mageia basesystem
  # urpmi  --urpmi-root mageia java

You have to create a regular user (i.e. other than root, which you can log with) and set the root passwd in the chroot environment (I did not succeed to log directly as root).

Log as root without booting
  # cd mageia
  # systemd-nspawn -D .

Change the root passwd in the chroot 
  # passwd

Add regular user in chroot and exit
  # createuser test
  # exit

You can now launch the container and log in using the regular user you just created
   # systemd-nspawn -bD .

To adapt network configuration from the Archlinux page, I do have to remove the default route that was created for br0 on Magiea. This is depending on your configuration, so it is better to check if nothing strange appears in your route after having started systemd-networkd service.

You can even copy the chroot directory on a Debian installation to use your Mageia chroot on your Debian (and vice-versa). 

Aucun commentaire:

Enregistrer un commentaire