Site Tools


Sidebar

lxd
This article is a work in progress. Information here is probably incomplete or inaccurate.

LXD

LXD is a system container and virtual machine management tools primarily targeted for Linux machines. Similar in concept to docker, unlike docker it is vastly easier to manage and much more sane in scope.

list of features include:

  • Sane cli utility for container management.
  • Containers are rootless by default 1).
  • Easily send/receive files from a container.
  • Decently rich set of publicly-available images (the important ones being alpine/ubuntu/void).
  • Tool for creating your own images locally without any friction.
  • Storage pools with ceph/zfs/btrfs

Basic Usage

Containers with LXD are managed by the cli utility lxc 2)

echo "hi"

LXD sane build from source

Long story short the official docs on the LXD source install are quite terrible. It doesnt actually spit out normal libs and binaries, rather it uses go's ugly install subcommand that really sucks for anything other than small cli utilities.

This guide aims to build & install LXD on any system. This guide also assumes that you have a recent version of go installed, if you dont go install that too.

NOTE: you should also have lxc (the lib) installed

The build has 3 parts:

  • raft
  • dqlite
  • LXD

We will be building each dependency in this order.

raft

Start by installing the latest release archive from the releases page.

wget -O raft-1.17.1.tar.gz "https://github.com/canonical/raft/archive/refs/tags/v1.17.1.tar.gz"
tar -xvf raft-1.17.1.tar.gz
cd raft-1.17.1

Now for configure/build (typical autotools bullshittery)

autoreconf -i
./configure --prefix=/usr
make

Finally the install

sudo make install

dqlite

Start by installing the latest release archive from the releases page.

wget -O dqlite-1.14.0.tar.gz "https://github.com/canonical/dqlite/archive/refs/tags/v1.14.0.tar.gz"
tar -xvf dqlite-1.14.0.tar.gz
cd dqlite-1.14.0

Now for configure/build (again the typical autotools bullshittery)

autoreconf -i
./configure --prefix=/usr
make

Finally slap it into your prefix

sudo make install

LXD

Now that we have all of the required dependencies installed we can get to building LXD. Start by getting the latest release tarball from the downloads page.

# this is for version 5.13 but should literally be whatever is the latest
wget "https://linuxcontainers.org/downloads/lxd/lxd-5.13.tar.gz"
tar -xvf lxd-5.13.tar.gz
cd lxd-5.13

Next configure both go and cgo inital flags.

export GOFLAGS="-buildmode=pie -trimpath"
export CGO_LDFLAGS_ALLOW="-Wl,-z,now"
CGO_LDFLAGS="-static" go build -v -tags "agent" -o bin/ ./lxd-agent/...
 
go build -v -tags "netgo" -o bin/ ./lxd-migrate/...
for tool in fuidshift lxc lxc-to-lxd lxd lxd-benchmark lxd-user; do
  go build -v -tags "libsqlite3" -o bin/ ./$tool/...
done

And now for the really painful part, installing everything, first lets get all the basic things where they need to be

for tool in fuidshift lxc lxc-to-lxd lxd lxd-agent lxd-benchmark lxd-migrate lxd-user; do
  sudo install -v -p -Dm755 "bin/$tool" "/usr/bin/$tool"
done

Now most people are gonna run systemd on their prod machines, so this guide assumes that. If you in particular dont, you are certainly smart enough to figure out porting this you your preferred init.

create the following files:

  • /usr/lib/systemd/system/lxd.service
lxd.service
[Unit]
Description=LXD Container Hypervisor
After=network-online.target lxcfs.service
Requires=network-online.target lxcfs.service lxd.socket
Documentation=man:lxd(1)
 
[Service]
Environment=LXD_OVMF_PATH=/usr/share/ovmf/x64
ExecStart=/usr/bin/lxd --group=lxd --logfile=/var/log/lxd/lxd.log
ExecStartPost=/usr/bin/lxd waitready --timeout=600
ExecStop=/usr/bin/lxd shutdown
TimeoutStartSec=600s
TimeoutStopSec=30s
Restart=on-failure
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
 
[Install]
WantedBy=multi-user.target
  • /usr/lib/systemd/system/lxd.socket
lxd.socket
[Unit]
Description=LXD - unix socket
Documentation=man:lxd(1)
 
[Socket]
ListenStream=/var/lib/lxd/unix.socket
SocketMode=0660
SocketGroup=lxd
Service=lxd.service
 
[Install]
WantedBy=sockets.target
  • /usr/lib/sysusers.d/lxd.conf
lxd.conf
g lxd - -

Log dir

install -v -dm700 "/var/log/lxd"

Some extra bash completions

sudo install -v -p -Dm644 "scripts/bash/lxd-client" /usr/share/bash-completion/completions/lxd

Notes for Debian 12 Machines

You may need to re-install the following pagkages:

libacl1-dev
libuv1-dev
libcap-dev
ibudev-dev
1)
as they should be
2)
dont confuse this with lxc, as that is the low-level tooling that lxd itself utilizes for its functionality.
lxd.txt · Last modified: 2023-05-11 Thu 04:13 by theorytoe