How to check lxd container size and how much space they are tacking

(amiya) #1

i am new to lxd , can any one help how to check lxc container size and how much space they are taking , i created a lxd container when i am trying to install few packages in it , its giving error that no space available.


First of all, there is no integrated way to check how much space containers are taking. I think that the reason is that developers want to commit only to solutions that are giving exact results that can’t be contested. However, disk space calculation has no exact answer for modern storage systems (think to wasted space due to block size, disk deduplication for example)
So the best answer may depend on your storage system. Also the lxd version matters.
This said, for lxd 3.12 (snap version) and the default storage, I use:

sudo nsenter -t $(pgrep daemon.start) -m – du -m -d 2 /var/snap/lxd/common/lxd/storage-pools/default

it’s a bit slow and certainly not ‘exact’ but I have no need for more. For LTS LXD version (not snap) you can drop the nsenter stuff and have to change the path for the storage.



When you first setup LXD, you assign some space for all the containers. This space is called a storage pool. Here is mine. The storage pool is called (in my case) lxd, I am using the zfs storage driver and I have 51 containers in total.

$ lxc storage list
| lxd  |             | zfs    | lxd    | 51      |

Let’s see some more details about this storage pool. We run lxc storage info with the name of the storage pool (in my case, lxd). It shows the total space that my containers are using (around 45GB), and also the total space that I have dedicated for the storage pool (around 215GB).

$ lxc storage info lxd
  description: ""
  driver: zfs
  name: lxd
  space used: 45.20GB
  total space: 215.88GB
used by:

In my case, I am using the ZFS storage driver, and I can use some ZFS commands to get a rough overall idea of how much space is used by each container. Below it reaffirms that I am using around 40-plus gigabytes for my containers, out of a total of about 200 gigabytes of available space.

$ zfs list
NAME                              USED  AVAIL  REFER  MOUNTPOINT
lxd                                    42,3G   201G    24K  none
lxd/containers                  42,8G   201G    24K  none
lxd/containers/c1             486M   201G   816M  /var/snap/lxd/common/lxd/storage-pools/lxd/containers/c1
lxd/containers/c2             901M   201G  1,11G  /var/snap/lxd/common/lxd/storage-pools/lxd/containers/c2

If you have setup LXD with the default settings, you probably created a storage pool of size 15GB (the default).
Can you verify that this is the case with your installation? Run the above commands and report back.

There are two ways to solve a small storage pool problem; you can either reinstall LXD and create a bigger storage pool, or you can create a second bigger storage pool, and move some containers there. Ask for details for any of these two.