Migrating from Linux-VServer to LXC (Slackware)

September 11, 2019 Roberto Puzzanghera0 comments

Tired of the nightmares of remotely compiling the kernel with Linux-VServer, a software that I'm pleased with, despite of some lack of documentation, these days I was playing with LXC, which is included and supported by Slackware and for which the Linux kernel doesn't need any patching because it already embeds the hacks for LXC containers.

To convert an existing Linux-VServer container in a (eventually unprivileged) LXC container you can follow these steps. I assume that you already know  how to create an LXC container; in case you are interested in unprivileged containers take a look to the excellent Chris Willing's guide (a big thanks to him) linked below.

More info:

In the following /vservers is the directory where your Linux-VServer containers are stored, while /lxc is the directory with your LXC ones (this directory would be /var/lib/lxc by default).

First of all prepare the directory which will host the container

mkdir /lxc/test

Copy your existing Linux-VServer container (assuming that its name is "test") in the rootfs:

cp -rp /vservers/test /lxc/test/rootfs

Now we have to

  • configure the newly created container
  • adjust the config and log files privileges
  • remap uids & gids

The last two steps are just in case of unprivileged containers.

Concerning configuration, we'll use a script like convert-vserver.sh, which I derived from the Slackware's template from Matteo Bernardini, which comes with LXC himself.

Download and execute:

wget https://notes.sagredo.eu/files/linux-vserver/convert-vserver.sh
chmod +x convert-vserver.sh
./convert-vserver.sh -n test

Once the script was executed with no errors, if the container is supposed to be an unprivileged containe, adjust the config and log files privileges as follows (I assume that lxc is the user which runs the container):

touch /lxc/test/test.log
chown lxc:users /lxc/test /lxc/test/config /lxc/test/test.log

where the name of the log file is of course the same as the container's name.

Finally, since my container had to be unprivileged, I had to remap its uids & gids according to the Chris Willing's guide:

container-userns-convert test 100000

Add a comment