Pither.com / Simon
Development, systems administration, parenting and business

LXD on LVM - thinpool setup

No matter what I tried I couldn't convince "lxd init" to create, or configure an existing, LVM thinpool for it's use!

So I ended up doing it rather more manually...

Basic requirements before getting started at all:

apt install lxd thin-provisioning-tools

Then create a thinpool, in this case using all of the remaining space on the "local" volume group:

lvcreate --type thin-pool --thinpool LXDPool -l 100%FREE local

Now we can do the lxd init bit, here's transcript of that process for me (the lines without a typed answer used the default):

# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: no
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
Would you like LXD to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes
config: {}
cluster: null
networks:
- config:
    ipv4.address: auto
    ipv6.address: auto
  description: ""
  managed: false
  name: lxdbr0
  type: ""
storage_pools: []
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: lxdbr0
      type: nic
  name: default

During that process I chose not to create a storage pool. Instead that had to be done afterwards:

lxc storage create default lvm source=local lvm.thinpool_name=LXDPool

Not forgetting that the name "default" is actually just a name, so you also need to set it as the actual default:

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

After that new containers can be created as normal with lxc launch and they will be allocated space from the LVM thinpool.

Comments

On March 20, 2020, 6:31 p.m. zeus said...

Thanks alot for this wrapup, it is a freaking hassle to set up lxd on an existing LVM volume without getting a completely wierd setup of pseudo-devices, and the documentatoin really doesn't help here. Your guide helped a lot to this. Thanks.

- zeus
blog.tastatursport.de

On March 30, 2020, 12:36 a.m. Kristof said...

Thanks, that helped me a lot! I approached it different, though. I did not create a pool with 'lvcreate'. Instead, I did this:
lxc storage create pool lvm source=<ExistingVgName> lvm.vg.force_reuse=true lvm.use_thinpool=true lvm.thinpool_name=lxd-pool
This created a proper thin pool 'lxd-pool' in my existing lvm vg, instead of some loop to a file. Afterwards your 'lxc profile' was still necessary:
lxc profile device add default root disk path=/ pool=pool

Thanks a lot!
Kristof

Add a comment