How I can create storage pool in another place, for example create into /mnt/work/hddpool.img ?
When I use option source I get a message:
Error: Provided path does not reside on a btrfs filesystem
Do I need first create loopback file and then formatted into btrfs and then use lxc storage create? Why can’t lxc storage create do it for me?
How can move file /var/lib/lxd/disks/ssdpool2.img to another place, for example to /mnt/work/ssdpool2.img? Create symlink on /var/lib/lxd/disks/ssdpool2.img?
Symlinks won’t work. Using a separate loop device would work, though remember that for production environments, actual partitions will be a lot more reliable and a lot faster.
If you want to move all your disks elsewhere, you can do so while LXD is off, then setup a bind-mount over /var/lib/lxd/disks. Again, stay away from symlinks, those will not work or may break at any time.
LXD does not accept loop files outside of /var/lib/lxd/disks, if you use a loop, then you must make sure it will always be using the same path and pass that as the source, not the file backing it.
I am in the same case scenario, trying to recover containers from an existing btrfs partition.
Following the documentation, it should be feasable to reuse an existing btrfs filesystem like this
mount /dev/sdb3 /media/pvincent/pool1/
lxc storage create pool1 btrfs source=/media/pvincent/pool1/
It replies => Error: Requested btrfs subvolume exists but is not empty
When I type
lxc storage create pool1 btrfs source=/dev/sdb3
It replies => Error: Failed to format block device: Failed to run: mkfs.btrfs /dev/sdb3 -L pool1: /dev/sdb3 appears to contain an existing filesystem (btrfs). Use the -f option to force overwrite.
I understand after mounting this existing storage, the command lxd import will help recovering the existing containers. However, I’m stuck on creating a storage onto an existing btrfs partition.
What did I do wrong ?
btw, I tried something else
create a brand new btrfs partition
copy from the old container rootfs to the new partition, and then
lxd import each container separately => SUCCESS !
but it’s such a long and painful process. reusing an existing partition would be so helpful !
You can re-use the existing partition, you just need to mount it where it used to go /var/snap/lxd/common/lxd/storage-pools/NAME and then use lxd import on each container.
The first import will cause LXD to re-add the storage pool in the DB for you.
[…]
=> Error: Failed to create storage pool ‘default’: Failed to run: btrfs subvolume create /var/snap/lxd/14133/default: ERROR: not a btrfs filesystem: /var/snap/lxd/14133
CHANGE AGAIN lxd init, entering /dev/sdb3
lxd init
Create a new BTRFS pool? => no
Name of the existing BTRFS pool or dataset => /dev/sdb3
[…]
=> Error: Failed to create storage pool ‘default’: Failed to format block device: Failed to run: mkfs.btrfs /dev/sdb3 -L default: /dev/sdb3 appears to contain an existing filesystem (btrfs).
CHANGE AGAIN lxd init, entering default as a mount point to /dev/sdb3
That’s because of mount namespaces, not all processes see the same mount entries.
Instead of mount /dev/sdb3 /var/snap/lxd/common/lxd/storage-pools/default, you can use nsenter --mount=/run/snapd/ns/lxd.mnt mount /dev/sdb3 /var/snap/lxd/common/lxd/storage-pools/default which will then mount it in the right namespace
No, lxd import is for disaster recovery when the LXD database has been removed/damaged but the instances on disk remain in their original locations. lxd import uses the backup.yaml files in each instance root volume to restore the LXD database.