Migrate LXD container to new server

I was running LXD on a CentOS 8 system using the DIR storage method. The CentOS system crashed and I want to move the LXD containers to an Ubuntu 20.04 system using the LVM storage method.

How can I do this?

I tried to run “lxd import” on a tar file of one of the old containers, but that failed complaining of a missing “index.yaml” file.

Easiest may be for you to initialize LXD with a dir storage pool again.
Then restore the data at /var/snap/lxd/common/lxd/storage-pools/NAME/containers/

And once everything is back in place, run lxd recover to scan the pools and import the containers.

After creating a new storage pool with a new empty directory, /var/snap/lxd/common/lxd/storage-pools/NAME is a directory on my root drive, not a link to the new storage pool directory. This directory is empty; there is no subdirectory named containers.

Did you mean restore to the new storage pool directory?

I ran “sudo nsenter -t $(cat /var/snap/lxd/common/lxd.pid) -m” and I can see the subdirectories under var/snap/lxd/common/lxd/storage-pools/NAME.

Ah, so I guess you’re either not using a dir storage pool or you’re using one with an alternate source field as a plain dir storage pool using the default source path would have shown directly under /var/snap/lxd/common/lxd without needing to go look into the mntns.

In any case, once that pool looks good, lxd recover should be able to detect the instances and import them back into LXD.

lxd recover did work, but not on the first (or even second or third) go around. It appears that you need to say “yes” to search for lost volumes. I’m not sure what a “volume” is in LXD. Apparently, it means “container” or “vm”. Saying “no”, the default, means nothing happens.

I received errors when I ran lxd recover. The name of the pool and the source directory are stored in the backup.yaml file and these did not match the new DIR storage pool. I deleted the storage pool and recreated it with the same name/source as in the backup.yaml file and copied the containers. Then lxd recover found the containers.