Using ncdu on LXD (ZFS) storage pool from the host

Hi,

Disclosure: I don’t fully understand ZFS!

I was just going to check what was consuming space in some of my containers. I tried running ncdu from the host against the container mountpoints as shown in zfs list (i.e. sudo ncdu /var/snap/lxd/common/lxd/storage-pools/lxd/containers/web-server) but whilst all the folders I expected were shown, the sizes don’t align with what ZFS reports:

ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help                                                                                                                                                 
--- /var/snap/lxd/common/lxd/storage-pools/lxd --------------------------------------------------------------------------------------------------------------------------------------------------------------
   52.0 KiB [##########] /containers                                                                                                                                                                         
   16.0 KiB [###       ] /containers-snapshots
    8.0 KiB [#         ] /images
e   4.0 KiB [          ] /virtual-machines-snapshots
e   4.0 KiB [          ] /virtual-machines
e   4.0 KiB [          ] /custom-snapshots
e   4.0 KiB [          ] /custom

Within ncdu, I can drill down all the way into what I would expect to be the root of the container but ncdu shows an empty folder.

I then found some other info, that under snap the container mounts could be found under /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/<pool-name>/containers but that was exactly the same issue.

Any hints on how I might be able to drill down into this?

Cheers,
Whytey

The snap package uses a mount namespace of its own, so that is why you don’t see much usage underneath the lxd dir, this is because your instances are on ZFS volumes that are not visible in your host’s mount namespace, and even inside the snap’s mount namespace, they are only mounted when the instance is running.

Best thing to do is to start the instances you’re interested in and then run the du command (or similar) inside the instance using;

lxc exec <instance> -- du /