How to Manage LXC/LXD Containers on Arch Linux

Linux Containers (LXC) and their more user-friendly sibling LXD offer powerful and lightweight system containerization features for developers, sysadmins, and Linux enthusiasts. On Arch Linux, known for its bleeding-edge nature and DIY philosophy, managing LXC and LXD gives you a potent mix of flexibility and performance. This guide will walk you through installing, configuring, and managing LXC/LXD containers effectively on Arch Linux.

What Are LXC and LXD?

LXC (Linux Containers) is an OS-level virtualization method that allows you to run multiple isolated Linux systems (containers) on a single host using a shared kernel. It’s lightweight compared to full virtualization methods like KVM or VirtualBox.

LXD is a next-generation system container manager built on top of LXC, offering a more user-friendly CLI (lxc), REST API, and additional features like container image management, networking, and clustering. It effectively turns LXC into a full container hypervisor.

Prerequisites

Before diving in, ensure you have:

  • An up-to-date Arch Linux system.
  • Root or sudo access.
  • A basic understanding of systemd and networking.

Update Your System

sudo pacman -Syu

Make sure your kernel is also updated, as LXC depends heavily on kernel features like cgroups and namespaces.


Installing LXC and LXD on Arch Linux

Step 1: Install Required Packages

Arch Linux provides both LXC and LXD packages through the official repositories.

sudo pacman -S lxc lxd

Optional but useful tools:

sudo pacman -S bridge-utils dnsmasq debootstrap rsync

These help with networking and container management.

Step 2: Enable Required Kernel Modules

LXC relies on several kernel modules. Load and enable them persistently:

sudo modprobe overlay
sudo modprobe aufs
sudo modprobe br_netfilter

To make them persistent across reboots, add them to /etc/modules-load.d/lxc.conf:

echo -e "overlay\naufs\nbr_netfilter" | sudo tee /etc/modules-load.d/lxc.conf

Step 3: Start and Enable Services

Start and enable the LXD daemon:

sudo systemctl enable --now lxd.service

LXC itself doesn’t require a persistent daemon but benefits from cgroup support, so make sure your system is running systemd and /sys/fs/cgroup is mounted.


Initializing LXD

Once LXD is installed, it must be initialized.

sudo lxd init

You’ll be prompted with a series of configuration questions:

  • Use LXD clustering? (no)
  • Storage backend (e.g., zfs, btrfs, dir)
  • Network bridge? (yes)
  • Name of the bridge (e.g., lxdbr0)
  • IPv4/IPv6 address ranges

For a simple local setup, the default values are usually sufficient. A commonly used storage backend is dir, but zfs and btrfs offer advanced features like snapshots and compression.


Managing Containers with LXD

Launching a Container

To start a new container, use:

lxc launch images:archlinux arch-container

Here:

  • images:archlinux refers to a remote image from the LXD image server.
  • arch-container is your container’s name.

You can list available images with:

lxc image list images:

Listing Containers

lxc list

Accessing the Container Shell

lxc exec arch-container -- bash

This gives you an interactive shell inside the container.

Starting and Stopping Containers

lxc stop arch-container
lxc start arch-container

Deleting Containers

lxc delete arch-container

If the container is still running, add --force.


Networking Setup

LXD automatically creates a bridge network (typically lxdbr0) for containers. You can inspect it with:

ip addr show lxdbr0

To assign static IPs or manage DNS, edit the bridge configuration:

lxc network show lxdbr0

To create a new bridge network:

lxc network create mybridge ipv4.address=10.100.100.1/24 ipv4.nat=true ipv6.address=none

Attach it to containers as needed:

lxc network attach mybridge arch-container eth0

Storage Management

LXD supports several storage backends: dir, btrfs, zfs, lvm. The simplest is dir, which stores container data as regular files.

To create a new storage pool:

lxc storage create mystorage dir

To launch a container using this storage pool:

lxc launch images:archlinux mycontainer -s mystorage

Using LXC Directly (Without LXD)

Some users prefer the traditional LXC workflow using lxc-* tools like lxc-create, lxc-start, etc. Here’s a brief overview.

Step 1: Create a Container

sudo lxc-create -n mylxc -t download

Choose your desired distribution when prompted.

Step 2: Start the Container

sudo lxc-start -n mylxc -d

Step 3: Attach to the Container

sudo lxc-attach -n mylxc

Step 4: Stop and Destroy

sudo lxc-stop -n mylxc
sudo lxc-destroy -n mylxc

Advanced Features of LXD

Snapshots

lxc snapshot arch-container snap1

Restore with:

lxc restore arch-container snap1

Container Profiles

LXD uses profiles to define default container configurations (network, storage, etc.)

lxc profile list
lxc profile show default

To create and apply custom profiles:

lxc profile create devprofile
lxc profile edit devprofile  # Use a YAML editor
lxc profile add arch-container devprofile

Remote Image Repositories

You can add more image servers:

lxc remote add myremote https://images.linuxcontainers.org

Then list and launch containers from the new remote.


LXD GUI Options

While LXD is primarily CLI-based, there are some third-party GUI tools:

  • LXD Dashboard (web UI via community projects)
  • Cockpit + LXC Plugin
  • Webmin (generic but can manage LXC to some extent)

Tips for Arch Linux Users

  • Always check the Arch Wiki for updates—Arch evolves quickly.
  • Consider creating LXD containers with other distributions (like Ubuntu or Alpine) for testing.
  • Use btrfs or zfs for better snapshot performance and quota management.
  • Keep your kernel updated to avoid compatibility issues with cgroups and namespaces.

Conclusion

Managing LXC and LXD containers on Arch Linux opens up a world of lightweight, efficient, and powerful system virtualization. Whether you choose the raw control of LXC or the ease and scalability of LXD, Arch gives you the flexibility to tailor container environments precisely to your needs.

LXD simplifies container creation, networking, storage, and automation while remaining robust and fast. From testing environments to lightweight system services, containers are a vital tool in a modern Linux toolkit. With Arch Linux’s rolling updates and bleeding-edge nature, you always have access to the latest in container technologies—just be sure to keep pace with the changes.