LXD Initialization and Configuration

Install, initialize, and configure LXD.

This guide provides instructions for installing, initializing, and configuring LXD . LXD is the default lightweight hypervisor for creating and managing lightweight VMs in the form of Linux (LXC) containers.

Install LXD

Most nodes in this project come in the form of LXD Linux containers. For this we need to create the microk8s LXD profile and the lxdbr1 network bridge. The microk8s profile is required to install MicroK8s on c2d-ks1, c2d-ks2, and c2d-ks3.

LXD is installed by default on Ubuntu 24.04, but we must initialize it with lxd init. Accept all defaults by pressing Enter. Note that init creates the lxdbr0 bridge.

sudo apt install curl -y
sudo snap refresh lxd --channel=5.21/stable
sudo snap refresh --hold lxd
curl -s -L https://gitlab.com/c2platform/c2/ansible-inventory/-/raw/master/doc/howto-development/lxd-init-preseed.yml | lxd init --preseed

Create the microk8s profile

Create the microk8s profile.

lxc profile create microk8s
curl -s -L https://gitlab.com/c2platform/c2/ansible-inventory/-/raw/master/doc/howto-development/microk8s.profile.txt | lxc profile edit microk8s

Create the lxdbr1 bridge

Create the lxdbr1 bridge and attach it to the default profile.

lxc network create lxdbr1 ipv6.address=none ipv4.address=1.1.4.1/24 ipv4.nat=true
lxc network attach-profile lxdbr1 default eth1

Set https_address

Make LXD available to the Vagrant LXD provider by setting core.https_address and configuring trust. Without this step, vagrant up shows:

The LXD provider could not authenticate to the daemon at https://127.0.0.1:8443.

lxc config set core.https_address [::]:8443

Vagrant synced folders

Allow support for LXD synced folders by modifying /etc/subuid and /etc/subgid. Without this step, vagrant up shows:

The host machine does not support LXD synced folders

echo "root:$(id -u):1" | sudo tee -a /etc/subuid
echo "root:$(id -g):1" | sudo tee -a /etc/subgid

Dir storage pool

On Ubuntu 24.04, the default storage pool uses the zfs driver. This works well for production but is cumbersome for development. This project therefore uses a custom dir storage pool named c2d.

lxc storage create c2d dir
lxc profile edit default  # and change pool to c2d
Show me
onknows@io3:~/git/gitlab/vagrant-lxd$ lxc storage create c2d dir
Storage pool c2d created
onknows@io3:~$ lxc storage ls
+---------+--------+--------------------------------------------+-------------+---------+---------+
|  NAME   | DRIVER |                   SOURCE                   | DESCRIPTION | USED BY |  STATE  |
+---------+--------+--------------------------------------------+-------------+---------+---------+
| c2d     | dir    | /var/snap/lxd/common/lxd/storage-pools/c2d |             | 0       | CREATED |
+---------+--------+--------------------------------------------+-------------+---------+---------+
| default | zfs    | /var/snap/lxd/common/lxd/disks/default.img |             | 0       | CREATED |
+---------+--------+--------------------------------------------+-------------+---------+---------+
onknows@io3:~$ lxc profile edit default  # change pool to c2d
onknows@io3:~$ lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  eth1:
    nictype: bridged
    parent: lxdbr1
    type: nic
  root:
    path: /
    pool: c2d
    type: disk
name: default
used_by: []

LXC trust

Start the first node.

c2
vagrant up c2d-rproxy1

This produces the error:

The LXD provider could not authenticate to the daemon at https://127.0.0.1:8443.

Fix it with:

lxc config trust add ~/.vagrant.d/data/lxd/client.crt