(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

(Stéphane Graber) #2

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.

(Stéphane Graber) #4

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!