Want to move /var/lib/lxd on a btrfs RAID1 (away from the small root partition)

Let’s say there is server with a 32GB ssd drive hosting the core system (ubuntu 16.04 server) and 2 x 1TB drives forming a btrfs RAID1.

how would I ideally add an lxd storage pool to that scenario if I do not want to add another hard drive? LXD should be snap LXD.

from the top of my head …

  1. create a loop drive on the RAID1
  2. mount --bind /dev/loopX /var/snap/lxd/common/lxd/ (*1)

that would put all containers and images on the btrfs RAID, so I guess I need some location for the lxd storage pool. Maybe another loop device? getting lost

(*1) the equivalent of /var/lib/lxd when lxd runs from the snap package)

I would create a storage pool pointing to whereever you want and make that the default (change default profile to use new storage pool)

If your raid1 is formatted as btrfs, you could just create a subvolume on it, then mount that subvolume on /var/snap/lxd/common/lxd/.

Something like:

btrfs subvolume create /data/lxd/
mount --bind /data/lxd /var/snap/lxd/common/lxd/

In “lxd init”, you can then select “btrfs” as the storage pool backend, tell it not to create a new pool, then give it “/var/snap/lxd/common/lxd/storage-pools/default/” as the path to an existing subvolume.

Non-interactively, that’d be:

lxc storage create default btrfs source=/var/snap/lxd/common/lxd/storage-pools/default
lxc profile device add default root disk path=/ pool=default

The /var/snap/lxd/common/lxd mount should obviously land in /etc/fstab to ensure it’s there before LXD starts on boot.

thanks, awesome!

yes, that’s what I meant. RAID1 made by/formatted as btrfs

lxc storage create default btrfs source=/var/snap/lxd/common/lxd/storage-pools/default

is the default in that command referring to the default lxd profile?

Nope, it’s the name of the storage pool as will be seen in “lxc storage list” afterwards.

To attach your storage pool to the default profile, you’ll need:

lxc profile device add default root disk path=/ pool=default

So in this case the first “default” refers to the profile name, the second to the pool name.