Some notes on how to install and configure lxc/lxd containers.
Read the 'getting started' docs first:
Lots of good examples:
Links:
- https://lxd.readthedocs.io/en/latest/
- https://github.com/lxc/lxd/blob/master/doc/index.md
- https://www.digitalocean.com/community/tutorials/how-to-set-up-and-use-lxd-on-ubuntu-16-04
These notes were created for LXD version 2.21:
$ lxc --version
2.21
$ lxd --version
2.21
Install on Ubuntu 16.04 like this:
$ sudo apt install zfsutils-linux
$ sudo apt install -t xenial-backports lxd lxd-client
It's important to use the backports repo to get a version new enough to have networking configuration built-in. Only versions >= 2.3 have the new networking.
After installation run the configuration script, defaults are fine:
$ sudo lxd init
Do you want to configure a new storage pool (yes/no) [default=yes]?
Name of the new storage pool [default=default]:
Name of the storage backend to use (dir, zfs) [default=zfs]:
Create a new ZFS pool (yes/no) [default=yes]?
Would you like to use an existing block device (yes/no) [default=no]?
Size in GB of the new loop device (1GB minimum) [default=43GB]:
Would you like LXD to be available over the network (yes/no) [default=no]?
Would you like stale cached images to be updated automatically (yes/no) [default=yes]?
Would you like to create a new network bridge (yes/no) [default=yes]?
What should the new bridge be called [default=lxdbr0]?
What IPv4 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
What IPv6 address should be used (CIDR subnet notation, “auto” or “none”) [default=auto]?
LXD has been successfully configured.
Links:
$ lxc launch ubuntu:xenial first
As a normal user:
$ lxc exec ${container-name} -- sudo --login --user ubuntu
As root:
$ lxc exec ${container-name} -- /bin/bash
Attach a static list to a single container like this:
$ lxc network attach lxdbr0 ${container-name} eth0
$ lxc config device set ${container-name} eth0 ipv4.address 10.233.40.2
Links:
$ lxc config set ${container-name} boot.autostart true
Links:
Take a snapshot:
$ lxc snapshot ${container-name} ${snapshot-name}
List snapshots:
$ lxc info ${container-name}
Restore a snapshot:
$ lxc restore ${container-name} ${snapshot-name}
Links:
Delegate an entire NIC to a container like this:
$ lxc config device add ${container-name} wlp1s0 nic name=wlp1s0 nictype=physical parent=wlp1s0
Then configure as normal with wpasupplicant
and wireless-tools
:
- https://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line
- https://wiki.debian.org/WiFi/HowToUse#WPA-PSK_and_WPA2-PSK
If the eth0
interface needs to be disabled on boot in Ubuntu 16.04 add this file:
/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
With the following contents:
network: {config: disabled}
Notes:
- I also had to configure the default route since it seemed to not exist anymore when I disabled eth0.
- It seems to be important to use the same device name in the container as in the host
$ lxc file push path/to/source ${container-name}/path/to/dest
$ lxc file pull ${container-name}/path/to/source path/to/dest
Use images to create backups that can be exported to a file or pushed to anther LXD server. To create an image, first create a snapshot:
$ lxc snapshot riverpl backup-2022-02-22
Next "publish" that snapshot as an image (it wont't be public):
$ lxc publish riverpl/backup-2022-02-22 --alias riverpl_backup_2022-02-22 description="Backup on 2022-02-22"
Finally, export the published image as a tarball:
$ lxc image export riverpl_backup_2022-02-22 ~/backups/riverpl_backup_2022-02-22.tar.gz