Error while creating btrfs disk

I’m trying to create a btrfs img at a custom path:

[n4r3n disks]$ lxc storage create makepkg btrfs source=/data/lxd/disks/makepkg.img
Error: Existing path is neither a BTRFS subvolume nor does it reside on a BTRFS filesystem

The image is formatted as btrfs and has the label of the pool:

[n4r3n disks]$ btrfs filesystem show makepkg.img
Label: 'makepkg'  uuid: 8028af7a-8ebf-4e83-97b3-a8cbc79f40c7
        Total devices 1 FS bytes used 128.00KiB
        devid    1 size 15.00GiB used 536.00MiB path /data/lxd/disks/makepkg.img

LXD version: 3.18 - from AUR
Distro: ArchLinux

LXD doesn’t support custom loop devices for btrfs. It expects either a disk/partition (block device) or a path to a mounted btrfs filesystem.

In this case, this means that you can either loop mount your .img and then pass the /dev/loopX to LXD (but you’ll need to ensure that the loopX is identical on every boot). Or more likely, setup an fstab entry on the host to mount this .img somewhere and then pass that path to LXD as a source.

I don’t think that LXD support arbitrary loop file locations (zfs or lvm don’t either).

It allows you to prefix a file by ‘/’ for btrfs because btrfs has the idea of subvolume. So if you have an existing btrfs system you could create a storage pool in a subvolume. A loop file path begins by ‘/’ like a btrfs subvolume; but it’s not by itself a btrfs subvolume, even it it contains btrfs partitions.

IMO it’s better to not fight the system. LXD allows you to set up storage pools anywhere you want, provided it’s in a dedicated partition (not a loop file).
Loop files are not recommended for production, so having them only in a special place is not a real problem anyway.

Thanks for the answers
@stgraber: The file in fstab is what I’m doing now, I just hoped that there is a “cleaner” solution
@gpatel-fr: I certainly don’t want to use loop files for production :slight_smile: