Skip to content

Instantly share code, notes, and snippets.

@ntrepid8
Last active February 26, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntrepid8/a4efd40ac167030685b5609f72d04f30 to your computer and use it in GitHub Desktop.
Save ntrepid8/a4efd40ac167030685b5609f72d04f30 to your computer and use it in GitHub Desktop.
LXC/LXD Notes 2022

LXC/LXD Notes 2022

An update to my older notes found here:

See also:

Install on Ubuntu 20.04

Install like this:

$ sudo apt install -y zfsutils-linux
$ sudo snap install lxd

After install configure like this:

$ sudo lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: 
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 (ceph, btrfs, dir, lvm, zfs) [default=zfs]: 
Create a new ZFS pool? (yes/no) [default=yes]: 
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: 
Size in GB of the new loop device (1GB minimum) [default=30GB]: 64GB
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local 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]: 
Would you like the LXD server 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 a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:

Launch a Container

Launch a container like this:

$ lxc launch ubuntu:20.04 riverpl-focal
Creating riverpl-focal
Starting riverpl-focal
$ lxc list
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
|     NAME      |  STATE  |         IPV4         |                     IPV6                      |   TYPE    | SNAPSHOTS |
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| riverpl-focal | RUNNING | 10.254.72.164 (eth0) | fd42:dbc3:8e7f:f6c2:216:3eff:fe4d:fcc6 (eth0) | CONTAINER | 0         |
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+

Static IP Address

Configure a static IP address like this:

$ lxc config device override riverpl-focal eth0
Device eth0 overridden for riverpl-focal

$ lxc config device set riverpl-focal eth0 ipv4.address 10.254.72.164

Then restart and verify the IP address is the same:

$ lxc restart riverpl-focal

$ lxc list
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
|     NAME      |  STATE  |         IPV4         |                     IPV6                      |   TYPE    | SNAPSHOTS |
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| riverpl-focal | RUNNING | 10.254.72.164 (eth0) | fd42:dbc3:8e7f:f6c2:216:3eff:fe4d:fcc6 (eth0) | CONTAINER | 0         |
+---------------+---------+----------------------+-----------------------------------------------+-----------+-----------+

Get a Shell

Get a shell inside the container like this:

$ lxc shell riverpl-focal
root@riverpl-focal:~#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment