LXC container setting disk space limits


I have been trying to configure disk space limitations for my lxd containers without much success. I currently have a storage pool configured for 100GB using btrfs.Now say my goal is to create 5 lxc containers each one being limited to 10GBs of space within this storage pool, how would I go about doing this?

I have used the command “lxc config device add test root disk pool=default size=10GB”, and using “lxc config show test” I can see that disk space has been set to 10GB. However, after some testing, it seems that the “test” container is able to surpass the 10GB limit.

Any help or clarifications on the subject would be appreciated,


Hmm, that’s odd, the right btrfs qgroup should have been configured, though btrfs quotas are enforced semi-asynchronously in my experience so it may let you write a bit more than the quota.

stgraber@castiana:~/data/code/lxc/lxd (stgraber/shiftfs)$ lxc storage create btrfs btrfs
Storage pool btrfs created

stgraber@castiana:~/data/code/lxc/lxd (stgraber/shiftfs)$ lxc launch ubuntu:18.04 btrfs-1804 -s btrfs
Creating btrfs-1804
Starting btrfs-1804                         

stgraber@castiana:~/data/code/lxc/lxd (stgraber/shiftfs)$ lxc config device set btrfs-1804 root size 2GB

stgraber@castiana:~/data/code/lxc/lxd (stgraber/shiftfs)$ lxc exec btrfs-1804 bash
root@btrfs-1804:~# dd if=/dev/zero of=blah.img bs=4M count=1000
dd: error writing 'blah.img': Disk quota exceeded
467+0 records in
466+0 records out
1955594240 bytes (2.0 GB, 1.8 GiB) copied, 2.69377 s, 726 MB/s

root@btrfs-1804:~# ls -lh blah.img 
-rw-r--r-- 1 root root 1.9G Feb 15 22:30 blah.img
1 Like

Thanks for the reply, although I had implemented a different “solution”. I just used a zfs storage pool instead of the btrfs, and the disk limitations now work with no problems.

@stgraber Do you know why the result of the df -H command inside the container shows the wrong available space:

Filesystem                                              Size  Used Avail Use% Mounted on
/dev/disk/by-uuid/85718809-e3c0-43cf-b899-ba375160df8e  215G   11G  203G   5% /

And what is the solution? Thanks.

See reply here

1 Like