Skip to content

Install LXD on Ubuntu — system containers and VMs from one tool

Install LXD via snap on Ubuntu, initialize the storage and network backends, and launch both system containers and QEMU-backed VMs from a unified daemon.

LXD is a daemon that runs system containers — full Ubuntu/Debian/Alpine userlands sharing the host kernel — and, since version 4.0, qemu-backed VMs through the same API. Where Docker treats a container as a single-process unit-of-work, LXD treats it as a long-lived machine with init, multiple services, and a normal apt/systemctl workflow. For workloads that want VM-style semantics but container-style density, this is the right tool.

How to verify

A working LXD install responds to these probes:

snap list lxd
lxd --version
lxc list
lxc network list
lxc storage list
lxc remote list

lxc is the client CLI (named lxc for historical reasons — it talks to the lxd daemon, not to legacy LXC). After lxd init you should see at least one storage pool (default) and one network (lxdbr0).

What’s happening

LXD is built on the same kernel primitives Docker uses (namespaces, cgroups, AppArmor profiles), but exposes them in a machine-oriented API rather than a process-oriented one. A container in LXD has its own init system, its own /etc, its own packages, and can be backed up, snapshotted, migrated to another host, and resized like a VM. Multi-tenant hosters use it because density is much higher than full virtualisation while isolation is good enough for shared infrastructure.

The VM mode is qemu under the hood. From the user’s perspective the same lxc launch ubuntu:24.04 my-vm --vm syntax works — the difference is that LXD ships a tiny qemu launcher and ovmf firmware, and the resulting “container” is actually a VM with its own kernel. This matters when you need genuine kernel isolation (Windows guests, kernel module testing, security boundaries the host kernel cannot enforce).

LXD ships on Ubuntu exclusively as a snap. The snap package wires up AppArmor, cgroup delegation, and the per-process confinement that the system service needs. Installing via apt is no longer supported upstream.

The procedure

  1. Install the LXD snap and put the current user in the lxd group:
sudo snap install lxd
sudo usermod -aG lxd $USER
newgrp lxd
lxc --version
  1. Initialise LXD interactively the first time. For automation, use a preseed YAML; for hands-on, the wizard is faster:
sudo lxd init

The questions worth answering carefully:

  • Storage backend: choose zfs if you have a spare block device or a dataset on an existing pool — snapshots and clones are nearly free. btrfs is the second choice. dir is fine only for non-production hosts.
  • Network: accept lxdbr0 with NAT enabled. If you need bridged interfaces with public IPs, use a bridge profile with nictype: bridged instead.
  • MAAS connection: skip unless you actually run MAAS.
  • Listen on network: only yes if you intend to manage this host remotely from a workstation; otherwise the Unix socket is enough.
  1. Verify the storage pool and network are healthy:
lxc storage list
lxc storage show default
lxc network list
lxc network show lxdbr0
  1. Launch a system container and a VM side-by-side to confirm both runtimes work:
lxc launch ubuntu:24.04 web-container
lxc launch ubuntu:24.04 web-vm --vm

lxc list
lxc exec web-container -- bash
lxc exec web-vm -- bash

Inside web-container, uname -r shows the host kernel. Inside web-vm, it shows a guest kernel — the VM has its own.

  1. Resize a running container’s resources. This is online for containers, online-with-snapshot for VMs:
lxc config set web-container limits.cpu 4
lxc config set web-container limits.memory 4GiB
lxc config set web-container limits.disk.priority 7
lxc config show web-container | grep -E "cpu|memory|disk"
  1. Take a snapshot and create a forensic clone — the killer feature for incident response:
lxc snapshot web-container before-deploy
lxc copy web-container web-container-debug --instance-only
lxc start web-container-debug

You now have a frozen copy of the production container’s state to poke at while production continues to run.

Common pitfalls

  • Installing LXD via apt install lxd on Ubuntu 24.04 — the package is a transitional shim that just installs the snap. Use the snap directly.
  • Using the dir storage backend on a production host. Snapshots become full disk copies, migrations are slow, and lxc move between hosts is glacial.
  • Forgetting that lxc (the client) and lxc (the legacy LXC tool, see LXC classic) are entirely different binaries with overlapping syntax. Always check lxc info to confirm you are talking to LXD.
  • Not setting security.nesting=true on containers that themselves need to run nested containers — Docker-in-LXD fails silently otherwise.
  • Trusting the default lxdbr0 NAT for production traffic and being surprised that outbound connections appear from the bridge IP rather than the container’s published address.

Stack Harbor uses LXD for client workloads that need VM-style semantics with container density — see clustered environments for how we run mixed container-and-VM fleets behind a single API, with ZFS-backed storage pools and live migration between cluster members.