Last update: 01 November 2022 - Alpine 3.16 has lxd packages in contrib
Lxc is a great technology. I’ve been using it since 2012 and I’ve always appreciated its lightweight approach and efficiency. Nowadays KVM and hardware virtualization extensions have reached a very good level of performance. While a KVM VM allows to run another kernel and another OS, it ties specific resources to the VM and this isn’t always the best solution. Lxc uses the host’s kernel and shares its ram so the host machine runs lxc container’s processes as local processes - no slowdown, no resource wasting.
Alpine Linux is a great distribution. It’s minimal, reliable, secure and easy to deploy. It’s great for containers but it’s also great for low footprint servers, like hypervisors. It’s good as Xen Dom0, it’s good as KVM host and - no surprise - is great as Lxc host too.
Alpine Linux is great for low energy devices (Raspberry Pis, etc.), too, and has an efficient and reliable out-of-the-box read-only file system support. But I’ll write more about it in another post.
Lxd is a great solution. It uses lxc but simplifies a lot of operations like new container creation, profile management, automatic snapshots, clustering, etc. The “official” best option to use lxd is installing Ubuntu, Snap and so on. I don’t want to use Ubuntu to install Snap. I don’t want to use Snap just to install lxd. That’s why I’m choosing to use lxd with Alpine.
Long story short: this video shows all the steps described below:
Installing Alpine Linux on BTRFS Root File System
Alpine Linux installer supports btrfs as rootfs destination but the setup-alpine command doesn’t allow you to select it: it will partition your disk and create a ext4 standard root file system.
So let’s start with the installation but, then, we’ll interrupt it at disk selection:
Start with setup-alpine and set network, hostname, password, etc. Stop at:
1
2
3
Available disks are:
sda (20.5 GB QEMU QEMU HARDDISK )
Which disk(s) would you like to use? (or '?' for help or 'none') [none]
Press ctrl+C and interrupt the script.
Now we can install Alpine Linux on btrfs root system:
test:~# setup-disk /dev/sda
The following disk is selected:
sda (20.5 GB QEMU QEMU HARDDISK )
How would you like to use it? ('sys', 'data', 'lvm' or '?' for help) [?] sys
WARNING: The following disk(s) will be erased:
sda (20.5 GB QEMU QEMU HARDDISK )
WARNING: Erase the above disk(s) and continue? (y/n) [n] y
Creating file systems...
btrfs-progs v5.10
See http://btrfs.wiki.kernel.org for more information.
Label: (null)
UUID: 6ace888a-2f36-41e8-86b1-3e4214b9e34e
Node size: 16384
Sector size: 4096
Filesystem size: 15.17GiB
Block group profiles:
Data: single 8.00MiB
Metadata: DUP 256.00MiB
System: DUP 8.00MiB
SSD detected: no
Incompat features: extref, skinny-metadata
Runtime features:
Checksum: crc32c
Number of devices: 1
Devices:
ID SIZE PATH
1 15.17GiB /dev/sda3
Installing system on /dev/sda3:
/mnt/boot is device /dev/sda1
Installation is complete. Now eject the installation media and reboot.
After rebooting, let’s check that root file system is on btrfs:
Let’s follow the tutorial I wrote on Alpine Linux wiki and let’s install lxc, lxd, lxcfs and dbus (not needed but recommended to avoid problems with some containers).
After rebooting, you have a fully functional lxd-enabled Alpine Linux installation.