How to move lxd zfs-pool to another zfs dataset on the same host


I am rebuilding my workstation, including a reinstall of Ubuntu 16.04.x LTS.

Currently my lxd zfs storage uses a whole disk/pool. I would like to:

  • move to lxd zfs pool to a dataset within another pool.
  • tell lxd/c to use the new copy of the original pool.
  • not have to individually export and import each container

I have got this far, but find it unclear how I should proceed. I’ve spent a few hours with google, but nothing clearly covers the topic of telling lxd to use an existing populated zfs dataset - in my interpretation.

sudo -i
lxd shutdown
zfs snapshot -r lxd-virt@migrate
zfs send -R lxd-virt@migrate | zfs receive -F dev-pool/lxd-storage 

Is there a way to progress from here? Or do I need to take a different approach. I’m happy to document any clear solution.

–Peter G

1 Like

It’s certainly possible, but it’s not exactly supported so is slightly involved.

You’ll indeed want to transfer all the datasets to the new zpool, which the above will do fine.
Then you’ll need to remove that @migrate snapshot from the target so that it won’t confuse LXD. Then you should mark down all the mountpoint properties of the source datasets, then unset them all and set the original value on the target datasets.

Lastly you’ll need to do a tiny bit of DB surgery to have LXD look at the new place.
That bit depends on whether you’re on LXD 2.0.x (default on 16.04) or if you’re on 2.x (likely 2.21 if using backports).

In the former case, something like this should do the trick:

sudo sqlite3 /var/lib/lxd/lxd.db "UPDATE config SET value='POOL/DATASET' WHERE value='POOL';"

In the latter case, it’ll instead be:

sudo sqlite3 /var/lib/lxd/lxd.db "UPDATE storage_pools_config SET value='POOL/DATASET' WHERE value='POOL';"

Once that’s done, you can start LXD again and things should be fine.

1 Like