LXD ZFS use existing zfs volumes

Hi guys,

Reading through Storage.MD and want to try “import” an existing dataset that was originally created through the LXD storage API, is this possible with the following command?

lxc storage create pool1 zfs source=my-tank/slice

Will this wipe my data?

If not, would I be able to attach the child zfs sets into containers with:

lxd storage attach

Sorry if this is mundane question, I’m trying to recover from a corrupt lxd.db


OK - doesn’t look possible. Must need to zfs send | zfs recv…

error: Provided ZFS pool (or dataset) isn't empty

Funny, I just did this yesterday…

What follows is more or less what I did after accidentally nuking the database. It’s mostly based off of https://github.com/lxc/lxd/issues/3257#issuecomment-330631241 and https://github.com/lxc/lxd/issues/3479#issuecomment-312509327. I’m not sure how “correct” it is.

Basically, what you’ll want to do to recover the storage pool and the containers is zfs mount the containers and then lxd import them individually by name. e.g. if you have a container named foo, you’d do something like zfs mount default/containers/foo and then lxd import foo.

When you try to start the containers afterwards, it might complain about a missing root device. You can view the original root device by going to a container’s mount directory (run zfs list to see where it is) and opening backup.yaml.

You’re looking for the root: key under expanded_devices:. This key and its contents might need to be copied into the profile, e.g. lxc profile edit default under devices.

LXD will recognise the storage pool after the first container is imported, but you’ll still have to manually mount and import all the others one at a time - it won’t pick up the other containers automatically.

You can view all your containers in the storage with zfs list, assuming the ZFS pool itself is imported. If not, you’ll have to zpool import it first.

(I think) This won’t restore your networks, so you’ll have to recreate them. It also won’t recover your images, so you’ll either have to recover those manually from the storage, or just delete them if they’re from a remote source you can re-fetch.