Create btrfs storage pool on a btrfs subvolume

28 views
Skip to first unread message

Marcel Menzel

unread,
Sep 19, 2021, 7:23:44 AMSep 19
to lxc-...@lists.linuxcontainers.org
Hello list,

I am planning to move all containers off the default storage pool to a
new storage pool which I plan to reside on an existing btrfs format-ed
block device but a new subvol.

I am currently passing btrfs subvolumes directly to the containers from
a block device (the one which I plan to put on the new storage pool
aswell) without having to mount them on the host in the container config
via:

  postgres:
    path: /var/lib/postgres
    raw.mount.options: subvol=postgres
    source: /dev/md0
    type: disk

.. which works flawlessly. So I looked into the storage pool
configuration and saw the "btrfs.mount_options" option for storage
pools, and I tried the following:

  # lxc storage create lxd btrfs source=/dev/md0
btrfs.mount_options=subvol=lxd
  Error: Failed to format block device: Failed to run: mkfs.btrfs -L lxd
/dev/md0: /dev/md0 appears to contain an existing filesystem (btrfs).
  ERROR: use the -f option to force overwrite of /dev/md0

Which obviously does not work, because LXD still assumes I want to use
the block device as a whole.

Mounting the new subvolume on onto a folder on the host and instructing
lxd to create a storage pool there works, but then I'd have to mount the
subvolume on the host itself for lxd to use it, which I am trying to
avoid as above.

Is there a way to accomplish my idea?


Kind regards,

Marcel

Brian Candler

unread,
Sep 20, 2021, 5:49:20 AMSep 20
to lxc-users, wtfnofr...@gmail.com
I don't use btrfs that way myself, but the documentation here says:
  • Create a new pool called "pool1" using an existing btrfs filesystem at /some/path.
        lxc storage create pool1 btrfs source=/some/path

So I think you need to do that, rather than give the block device as the source.

That's consistent with the way I create a zfs storage pool within an existing zpool: "source" is the desired zfs dataset name. e.g. when the zpool is called "zfs":

storage_pools:
- config:
    source: zfs/lxd
    zfs.pool_name: zfs/lxd
  description: ""
  name: default
  driver: zfs


Marcel Menzel

unread,
Sep 20, 2021, 5:54:06 AMSep 20
to Brian Candler, lxc-users
I was able to convince LXD to use a pre-existing btrfs subvol by
mounting it to /var/lib/lxd/storage-pools/<name>, creating the folder
structure by hand and inserting the rows into the sqlite manually:

# lxd sql global "insert into storage_pools (name, driver, description,
state) values ('lxd', 'btrfs', '', 1);"
# lxd sql global "insert into storage_pools_config (storage_pool_id,
node_id, key, value) values (9, 1, 'source',
'/dev/disk/by-uuid/038ce7f2-8a2c-4b26-a71a-ec1493ac7696');"
# lxd sql global "insert into storage_pools_config (storage_pool_id,
node_id, key, value) values (9, 1, 'volatile.initial_source',
'/dev/disk/by-uuid/038ce7f2-8a2c-4b26-a71a-ec1493ac7696');"
# lxd sql global "insert into storage_pools_config (storage_pool_id,
node_id, key, value) values (9, 1, 'btrfs.mount_options', 'subvol=lxd');"

This seems to work as it survived multiple reboots and I was able to
migrate containers to the new storage pool with "lxc move".

Regards,

Marcel

Am 20.09.2021 um 11:49 schrieb Brian Candler:
> I don't use btrfs that way myself, but the documentation here
> <https://linuxcontainers.org/lxd/docs/master/storage#btrfs> says:
>
> * Create a new pool called "pool1" using an existing btrfs
Reply all
Reply to author
Forward
0 new messages