Monthly Archives: June 2013

Generate systemd units for lxc containers

Now that lxc containers are so easy, how about adding systemd unit files that will start/stop them and autostart them at boot time?

This is a simple script to generate systemd unit for for a container. It appends a _container prefix to the name of the container e.g. the container named webproxy is managed by service file webproxy_container.service.

You can add and remove unit files for any container with this script.

Enjoy.

 

An i686 container

Creating an i686 container is equally easy as creating an x86_64 container. Only difference is it needs a separate pacman.conf and mirrorlist that points to i686 instead of x86_64.

Following commands can be used to create a separate pacman.conf.

# sed 's/Architecture = auto/Architecture = i686/g' /etc/pacman.conf  > pacman.conf
# grep -v ^# /etc/pacman.d/mirrorlist|cat -s|sed s'/x86_64/i686/g' > mirrorlist

or

 

# grep -v ^# /etc/pacman.d/mirrorlist|cat -s|sed s'/\$arch/i686/g' > mirrorlist

Update the pacman.conf to use the new mirrorlist.

And create the container as follows

# lxc-create -n i6861 -t archlinux -- -P net-tools,openssh,vi,squid -p /data/shridhar/lxc/i6861  -c /root/pacman.i686.conf

After the container is created, replace its pacman.conf and mirrorlist with the ones used during the creation, so that it can continue to use the correct setting.

Rest of the steps are similar to the x86_64 container.