TL;DR;
I'm seeing some discrepancies between what I setup using zfs
, what lxd
may be doing during the lxd init
process, and what I expected to see.
I've been using LXD for about a month and have gone over the documentation and made several searches, but they don't appear to touch this topic.
Please look at the section below for more details about my questions:
- Can someone explain why I'm observing the mountpoint discrepancy between LXD and ZFS and what implications this may have, if any?
- Is LXD actually moving the
tank/lxd
dataset contents out of the ZFS Pool VDEVs from its mount location at/mnt/tank/lxd/...
and into/var/lib/lxd/...
, or is something else being done? (a) How can I confirm/verify either case? (b) Better yet, how can I get LXD to keep/put everything in the dataset I setup usingzfs
? - I want everything that would normally be stored under
/var/lib/lxd/
to be stored within thetank/lxd
I specified duringlxd init
: How can I do that? (A good ZFS/LXD-way is preferable; I couldmv /var/lib/lxd
into the tank andln -s
the directory to point to/mnt/tank/...
, but that seems like a bad hack and want to avoid it. There must be a better way.)
Thanks in advance.
Background
I'm using LXD 3.0.0 in Ubuntu 18.04, setting it up to use a pre-existing ZFS Pool and Dataset. This is how it looks before running lxd init
:
$ sudo zpool create -m /mnt/tank tank raidz3 <6 storage SSDs omitted>
$ sudo zfs set compression=on tank
$ sudo zfs create tank/lxd
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 216K 1.31T 43.7K /mnt/tank
tank/lxd 41.7K 1.31T 41.7K /mnt/tank/lxd
This looks as I expected. I then run lxd init
and follow up as follows:
$ lxd init
[...]
Create a new ZFS pool? (yes/no) [default=yes]: no
Name of the existing ZFS pool or dataset: tank/lxd
[...]
This is what zfs list
shows after completing the above:
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 589K 1.31T 41.7K /mnt/tank
tank/lxd 250K 1.31T 41.7K none
tank/lxd/containers 41.7K 1.31T 41.7K none
tank/lxd/custom 41.7K 1.31T 41.7K none
tank/lxd/deleted 41.7K 1.31T 41.7K none
tank/lxd/images 41.7K 1.31T 41.7K none
tank/lxd/snapshots 41.7K 1.31T 41.7K none
LXD created some datasets, but the mountpoint
s are no longer what they used to be (i.e. tank/lxd
is gone) nor what I expected (nothing under lxd/...
is listed). In short, the original mountpoint is gone and the other datasets are not showing up as I expected.
I'm probably wrong here, but it looks as if LXD has moved the data that should be under /mnt/tank/lxd/...
out of the ZFS pool vdevs and into the /var/lib/lxd/
directory on the LVM where the OS was installed. I'm not sure what I've missed.
I can use zfs set
commands to change "correct" this:
$ sudo zfs set mountpoint=/mnt/tank/lxd tank/lxd
$ sudo zfs set mountpoint=/mnt/tank/lxd/containers tank/lxd/containers
$ sudo zfs set mountpoint=/mnt/tank/lxd/custom tank/lxd/custom
$ sudo zfs set mountpoint=/mnt/tank/lxd/deleted tank/lxd/deleted
$ sudo zfs set mountpoint=/mnt/tank/lxd/images tank/lxd/images
$ sudo zfs set mountpoint=/mnt/tank/lxd/snapshots tank/lxd/snapshots
And verify that they show up as expected once again:
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 641K 1.31T 43.7K /mnt/tank
tank/lxd 252K 1.31T 43.7K /mnt/tank/lxd
tank/lxd/containers 41.7K 1.31T 41.7K /mnt/tank/lxd/containers
tank/lxd/custom 41.7K 1.31T 41.7K /mnt/tank/lxd/custom
tank/lxd/deleted 41.7K 1.31T 41.7K /mnt/tank/lxd/deleted
tank/lxd/images 41.7K 1.31T 41.7K /mnt/tank/lxd/images
tank/lxd/snapshots 41.7K 1.31T 41.7K /mnt/tank/lxd/snapshots
But this seems like a partial solution, as all the other files (e.g. lxd.db
, keys, etc) are left behind under /var/lib/lxd
. So, I'm not sure if I'm "fixing" anything or if there's anything to fix at all.
In addition, I'm not clear on whether I actually achieved anything with the zfs set
commands. For example, touch /var/lib/lxd/containers/hi.txt
does not show the file under /mnt/tank/lxd/containers/
, which I would've expected if they were both looking at the same location.
Thanks in advance for your help.
EDIT0: Suggested Test in Comments & Results
It was suggested that I try writing out some files as a test to see where the used space is actually consumed based on system info. The test steps were as follows:
- Destroy and re-create ZFS pool and LXD configs, but without running the
zfs set mountpoint
commands to let LXD do its own thing and see what happens. (Steps omitted below for brevity.) - As a control, check pool/dataset storage capacity and usage on host.
- Enter a container and do another control check on space usage.
- Write out a test file inside container.
- Repeat checks on steps 1 & 2 to look for changes.
The results were inconclusive and can be seen below.
2. Control Check on the Host
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 1.18G 1.31T 41.7K /mnt/tank
tank/lxd 1.18G 1.31T 41.7K none
tank/lxd/containers 270M 1.31T 41.7K none
tank/lxd/containers/base-server 251M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/base-server
tank/lxd/containers/dev-server 9.18M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/dev-server
tank/lxd/containers/qa-server 9.14M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/qa-server
tank/lxd/custom 125K 1.31T 41.7K none
tank/lxd/custom/dev-volume 41.7K 512G 41.7K /var/lib/lxd/storage-pools/lxd-pool/custom/dev-volume
tank/lxd/custom/qa-volume 41.7K 512G 41.7K /var/lib/lxd/storage-pools/lxd-pool/custom/qa-volume
tank/lxd/deleted 41.7K 1.31T 41.7K none
tank/lxd/images 937M 1.31T 41.7K none
tank/lxd/images/ab23ac2bda8cfb48c176a2d1e790181d5a1ed3522732a0cf8ff189dea848d3f1 588M 1.31T 588M none
tank/lxd/images/b36ec647e374da4816104a98807633a2cc387488083d3776557081c4d0333618 349M 1.31T 349M none
tank/lxd/snapshots 41.7K 1.31T 41.7K none
3. Inside a Container
root@dev-server:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tank/lxd/containers/dev-server 1.4T 589M 1.4T 1% /
none 492K 0 492K 0% /dev
udev 32G 0 32G 0% /dev/tty
tmpfs 100K 0 100K 0% /dev/lxd
tank/lxd/custom/dev-volume 512G 128K 512G 1% /mnt/tank
tmpfs 100K 0 100K 0% /dev/.lxd-mounts
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 160K 32G 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
4. Write out Test File in Container
root@dev-server:~$ dd if=/dev/zero of=/root/test.img bs=8MB
^C3929+0 records in
3929+0 records out
31432000000 bytes (31 GB, 29 GiB) copied, 17.7005 s, 1.8 GB/s
root@dev-server:~$ ls -lh
total 512
-rw-r--r-- 1 root root 30G May 7 20:21 test.img
5.1. Check Results from Container
root@dev-server:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tank/lxd/containers/dev-server 1.4T 589M 1.4T 1% /
none 492K 0 492K 0% /dev
udev 32G 0 32G 0% /dev/tty
tmpfs 100K 0 100K 0% /dev/lxd
tank/lxd/custom/dev-volume 512G 128K 512G 1% /mnt/tank
tmpfs 100K 0 100K 0% /dev/.lxd-mounts
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 160K 32G 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
5.2. Check Results from Host
$ sudo zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 1.18G 1.31T 41.7K /mnt/tank
tank/lxd 1.18G 1.31T 41.7K none
tank/lxd/containers 270M 1.31T 41.7K none
tank/lxd/containers/base-server 251M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/base-server
tank/lxd/containers/dev-server 9.18M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/dev-server
tank/lxd/containers/qa-server 9.14M 1.31T 588M /var/lib/lxd/storage-pools/lxd-pool/containers/qa-server
tank/lxd/custom 125K 1.31T 41.7K none
tank/lxd/custom/dev-volume 41.7K 512G 41.7K /var/lib/lxd/storage-pools/lxd-pool/custom/dev-volume
tank/lxd/custom/qa-volume 41.7K 512G 41.7K /var/lib/lxd/storage-pools/lxd-pool/custom/qa-volume
tank/lxd/deleted 41.7K 1.31T 41.7K none
tank/lxd/images 937M 1.31T 41.7K none
tank/lxd/images/ab23ac2bda8cfb48c176a2d1e790181d5a1ed3522732a0cf8ff189dea848d3f1 588M 1.31T 588M none
tank/lxd/images/b36ec647e374da4816104a98807633a2cc387488083d3776557081c4d0333618 349M 1.31T 349M none
tank/lxd/snapshots 41.7K 1.31T 41.7K none
Running the df -h
command on the host before and after the test file had been created/destroyed also showed no changes. I repeated this with a larger (100GB) test file, but failed to notice a difference.