I have started migrating content to my Hugo blog at https://blog.cavelab.dev, already migrated pages will redirect there.


From CaveLab

LXC (Linux Containers) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel. (source: Wikipedia)


apt install lxd lxd-client
sudo lxd init

# Using a Preallocated File
Would you like to use an existing block device (yes/no) [default=no]? no

# Using a Block Device
Would you like to use an existing block device (yes/no) [default=no]? yes


Change default

lxc profile edit default

Make LAN

lxc profile copy default lan
lxc profile edit lan

Change profile

lxc profile apply {vm-name} lan

Copy profile

lxc profile copy dmz epsilon:

Make container

lxc launch ubuntu:16.04 {vm-name} (-p {profile})
lxc list
lxc exec {vm-name} -- /bin/bash


lxc config show {vm-name}


lxc config set {vm-name} limits.cpu 1
lxc config set {vm-name} limits.memory 1

lxc profile device set {profile-name} {device/eth0} limits.ingress 100Mbit
lxc profile device set {profile-name} {device/eth0} limits.egress 100Mbit


lxc config set {vm-name} boot.autostart true
lxc config set {vm-name} boot.autostart.delay 10 # seconds to wait after starting container
lxc config set {vm-name} boot.autostart.priority 99 # higher values means earlier start

Mount disk

lxc config device add {vm-name} {dev_name} disk source=/mnt/md0 path=/mnt/md0

Privilege is needed for read/write access

lxc config set {vm-name} security.privileged=true



Both local and remove must have https_address set.

lxc config set core.https_address [::]:8443
lxc config set core.trust_password something-secure

lxc remote add foo
lxc remote list



$ lxc storage list


$ sudo apt install zfsutils-linux

Create a loop-backed pool named “lxd”. The ZFS Zpool will also be called “lxd”.

$ lxc storage create lxd zfs

Create a new pool called “lxd” on /dev/sdX. The ZFS Zpool will also be called “lxd”.

lxc storage create lxd zfs source=/dev/sdX

Change default

No images or containers can exist on system

$ lxc profile device remove default root
$ lxc storage delete default
$ lxc storage create default …
$ lxc profile device add default root disk path=/ pool=default


$ sudo truncate -s +5G /var/lib/lxd/disks/<POOL>.img
$ sudo zpool set autoexpand=on <POOL>
$ sudo zpool online -e <POOL> /var/lib/lxd/disks/<POOL>.img
$ sudo zpool set autoexpand=off <POOL>


lxc snapshot {container} {snapshot-name}
lxc info {container/snapshot-name}
lxc restore {container} {snapshot-name}
lxc delete {container}/snapshot-name}

Remap users

Allow on host

echo "root:1000:1" | sudo tee -a /etc/subuid /etc/subgid

This will allow root to use 1 new user and group ids, from 1000 to 1001.

Config container

lxc config set wiki-test raw.idmap "both $UID 1000"
echo -en "both 1000 1000\nboth 33 33" | lxc config set wiki-test raw.idmap -
Instead of remapping — you can set the permissions on the host to UID+100000, that will align with the remapped IDs on the container.