root@lxd:~# btrfs filesystem resize 10g /var/lib/lxd/storage-pools/default
Resize '/var/lib/lxd/storage-pools/default' of '10g'
ERROR: unable to resize '/var/lib/lxd/storage-pools/default': No space left on device
Which can’t be right because there is 42G available.
How can I increase the LXD container storage space by 20G?
Note that the btrfs resize would not work with snap lxd.
Also, using a sparse file is the default but not the preferred option (!) to store containers. It’s advised to manage containers in a dedicated partition or even dedicated disk.
Well, you have to understand that usually in a project when it’s said that some way of doing something is ‘not recommended’, it’s a code word for ‘hideously bugged’. That’s why I have stopped using sparse files.
Anyway, here is a way of doing it.
First stop all containers and unset any containers set to automatic start.
Then
gp@raspberry:~$ lxc storage info mybtrfs
info:
description: ""
driver: btrfs
name: mybtrfs
space used: 17.24MB
total space: 5.00GB
used by: {}
gp@raspberry:~$ sudo truncate -s +5GB /var/lib/lxd/disks/mybtrfs.img
gp@raspberry:~$ sudo systemctl stop lxd
gp@raspberry:~$ sudo systemctl disable lxd
gp@raspberry:~$ sudo reboot
(…)
gp@raspberry:~$ sudo losetup /dev/loop0 /var/lib/lxd/disks/mybtrfs.img
gp@raspberry:~$ sudo mount /dev/loop0 /mnt/disk1
gp@raspberry:~$ sudo btrfs fi show /mnt/disk1
Label: ‘mybtrfs’ uuid: a8add0a3-e384-499d-b339-4e0a51a58669
Total devices 1 FS bytes used 256.00KiB
devid 1 size 4.66GiB used 500.75MiB path /dev/loop0
gp@raspberry:~$ sudo btrfs fi resize max /mnt/disk1
Resize ‘/mnt/disk1’ of ‘max’
gp@raspberry:~$ sudo btrfs fi show /mnt/disk1
Label: ‘mybtrfs’ uuid: a8add0a3-e384-499d-b339-4e0a51a58669
Total devices 1 FS bytes used 256.00KiB
devid 1 size 9.31GiB used 500.75MiB path /dev/loop0
gp@raspberry:~$ sudo reboot
(…)
gp@raspberry:~$ sudo systemctl enable lxd
Synchronizing state of lxd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable lxd
insserv: warning: current start runlevel(s) (empty) of script lxd' overrides LSB defaults (2 3 4 5). insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of scriptlxd’ overrides LSB defaults (0 1 6).
Created symlink /etc/systemd/system/multi-user.target.wants/lxd-containers.service → /lib/systemd/system/lxd-containers.service.
Created symlink /etc/systemd/system/sockets.target.wants/lxd.socket → /lib/systemd/system/lxd.socket.
gp@raspberry:~$ sudo systemctl start lxd
gp@raspberry:~$ lxc storage info mybtrfs
info:
description: “”
driver: btrfs
name: mybtrfs
space used: 17.24MB
total space: 10.00GB
used by: {}
If you have no way of restarting your computer, you can temporarily create another storage with something like
lxc storage create mybtrfs btrfs size=5GB
and you can create containers in the secondary storage with the -s mystorage switch
Unfortunately (IIRC) I don’t think there is an easy way to copy a container from a storage to another with the stable LXD version.
Ah yeah, this makes sense. Resizing the backing file for the loop device doesn’t resize the loop device itself, so btrfs can’t actually grow.
There may be some ioctls that can be used to tell the loop device itself to grow, avoiding the need for the reboot, but it’s not something I’ve got experience with.
@morphis this may explain what you saw the other day too, assuming you were using a loop device.
It’s possible to do a losetup -c /dev/loopx but while resizing the loop device all right, it has always locked hard the computer when trying to resize the file system.
Thanks for all the help. I think I will build a new LXD server with BTRFS in a partition instead of a file, just in case I need to do this again. How do we setup BTRFS in a partition for LXD to use?