(Snap) LXD Resize default BTRFS storage pool


I currently have 2 LXC containers, and I’d like a third container.
However I’ve run out of space.

How would one resize the default btrfs storage?

# lxc storage list
|  NAME   | DESCRIPTION | DRIVER |                   SOURCE                   | USED BY |
| default |             | btrfs  | /var/snap/lxd/common/lxd/disks/default.img | 9       |

On my container:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/loop1      5.0G  4.0G  761M  85% /

I’m running LXD on Debian via Snap, and run 3.4:

# lxd --version

Any help/ advice is appreciated! Thanks

You should be able to grow the sparse file with:

  • dd if=/dev/zero of=/var/snap/lxd/common/lxd/disks/default.img bs=1 count=0 seek=10G
  • btrfs filesystem resize max /dev/loop1

(untested, based from a bit of googling)

Hi @stgraber, thanks for your help.

Should I do the ‘btrfs filesystem resize’ on my container?
If not, on which loop device then?
This is on my host-server:

/dev/loop0                     55M   55M     0 100% /snap/lxd/8393
/dev/loop2                     88M   88M     0 100% /snap/core/5328
/dev/loop3                     87M   87M     0 100% /snap/core/4917
/dev/loop4                     87M   87M     0 100% /snap/core/5145
/dev/loop5                     55M   55M     0 100% /snap/lxd/8415
/dev/loop1                     55M   55M     0 100% /snap/lxd/8339

Thank you!


NAME                   FSTYPE       SIZE MOUNTPOINT      LABEL
loop0                  squashfs    54.6M /snap/lxd/8393  
loop1                  squashfs    54.6M /snap/lxd/8339  
loop2                  squashfs    87.9M /snap/core/5328 
loop3                  squashfs    86.9M /snap/core/4917 
loop4                  squashfs      87M /snap/core/5145 
loop5                  squashfs    54.6M /snap/lxd/8415  
loop6                  btrfs         10G                 default
sda                                  30G                 
|-sda1                 ext2         243M /boot           
`-sda2                 LVM2_member 29.8G                 
  |-noc--01--vg-root   ext4        27.8G /               
  `-noc--01--vg-swap_1 swap           2G [SWAP]          
sr0                                1024M    

# btrfs filesystem resize max /dev/loop6
ERROR: resize works on mounted filesystems and accepts only
directories as argument. Passing file containing a btrfs image
would resize the underlying filesystem instead of the image.

Ok, so you may want to do:

  • nsenter -t $(pgrep daemon.start) -m – btrfs filesystem resize max /var/snap/lxd/common/lxd/storage-pools/default

Which should then aim the resize operation at the right mount namespace.

# btrfs filesystem show
Label: 'default'  uuid: 14359730-f8e4-4ba9-b9f2-81e929d841d6
        Total devices 1 FS bytes used 3.70GiB
        devid    1 size 10.00GiB used 4.77GiB path /dev/loop6

I mounted /dev/loop6 (to /mnt) and resized it with truncate -s +10G /dev/loop6 and rebooted, that’s it!

Thank you!


Trying to do the same, without success

    mounted /dev/loop4 (to /mnt), then truncate like in the example:
    truncate -s +10G /dev/loop4

    got the following error:
    truncate: failed to truncate '/dev/loop4' at 42949672960 bytes: Invalid argument

The following steps made it in my case (Ubuntu 18.04, LXD 3.0.1):

ATTENTION: In order to understand the following steps, I recommend to read this thread from the beginning.

  • Stopped containers (lxc stop containername)

As root (obvious but it may help someone):

  • mount /dev/loop4 mnt
  • truncate -s +30G /var/lib/lxd/disks/default.img
  • reboot
  • stop containers
  • btrfs filesystem resize max /var/lib/lxd/storage-pools/default

and that’s it
Don’t know if there is something unnecessary in my solution, but that’s the way it worked for me
Cheers !!


For me, I’m getting this:

root@sb35 ~ # lxc --version

root@sb35 ~ # nsenter -t $(pgrep daemon.start) -m -- btrfs filesystem resize max /var/snap/lxd/common/lxd/storage-pools/default
nsenter: failed to execute btrfs: No such file or directory

Is there another easy way? My workaround is to determine the device of the default pool, temporarily mount it, execute btrfs on the mounted pool, unmount it.

Update : for LXD on snap when using default BTRFS storage pool :

  • Enter any container and execute df -h | grep loop and you can see the loop
  • Stop containers
  • mkdir /mnt/loop{n°}
  • mount /dev/loop{n°} /mnt/loop{n°}
  • truncate -s +{size}G /var/snap/lxd/common/lxd/disks/default.img
  • reboot
  • Check if all containers are stoped if not stop them
  • btrfs filesystem resize max /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/default