Skip to main content

Install LXD on Alpine Linux

·

In this tutorial, we’ll install LXD, configure our system to run LXC containers, and initialize LXD on Alpine Linux. It should work on all platforms where LXD/LXC is supported (x86_64, ARM64, and more).

Alpine Linux is “an independent, non-commercial, general purpose Linux distribution designed for power users who appreciate security, simplicity and resource efficiency.” It’s incredibly lightweight and useful for containers and virtual machines as both a host and a guest. Due to its small size, it’s able to run on everything from Protectli Firewall Appliances and MicroServers to Threadripper PRO -based workstations.

LXD is a “next generation system container manager,” which offers “a user experience similar to virtual machines but using Linux containers instead.” Unlike Docker, Kubernetes, and similar, LXD is well suited for running system containers (full OS) at near bare metal speeds.

This article assumes you already have Alpine Linux installed and running on a node.

Configure Repositories #

To use LXD on Alpine Linux, we’ll need to use the edge branch ( development tree). Replace the repositories in /etc/apk/repositories and:

$ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
$ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
$ sudo echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories

Update the apk cache and “upgrade” the system to edge:

$ sudo apk update
$ sudo apk upgrade

Install LXD #

Install LXD using apk:

$ sudo apk add lxd

Enable and start the lxd service:

$ sudo rc-update add lxd
$ sudo rc-service lxd start

Configure System #

We’ll need to enable and start the cgroups service.

$ sudo rc-update add cgroups
$ sudo rc-service cgroups start

Add cgfs to pam.d/system-login:

$ sudo echo "session optional pam_cgfs.so -c freezer,memory,name=systemd,unified" >> /etc/pam.d/system-login

Add user and group idmaps to LXC config:

$ sudo echo "lxc.idmap = u 0 100000 65536" >> /etc/lxc/default.conf
$ sudo echo "lxc.idmap = g 0 100000 65536" >> /etc/lxc/default.conf

Add root (and other users as well) subuid and subgid:

$ sudo echo "root:100000:65536" >> /etc/subuid
$ sudo echo "root:100000:65536" >> /etc/subgid

Initialize LXD #

Finally, initialize LXD:

$ sudo lxd init # --auto

That should be it! You should now have a fully operational LXD instance. If you selected to initialize an LXD cluster, you can now join your other nodes to the cluster following the instructions on the LXD documentation! 📦😀

Revision #

2023-08-31 Revised language