A few days ago I was able to backup my SSD short before failure. The system was already in a quite unstable state with services like ssh failing. I was not able to export the containers properly anymore. LXD reported some integrity issues and crashed. Not sure how faulty is the disk dump, but I hope for the best regarding the zfs pool.
I would like to recover the containers in a different machine. So far I was able to:
mount the root partition incl. var/snap/lxd/common/lxd/database
mount the zfs pool as read-only under the temporary name backup (since default is already taken on this machine), so I also have access to all files in the containers
lxd from snap was already present at the rescue machine
I looked at the following answer to a similar question, but I am lost in the last part:
snap remove lxd
snap install lxd ← is this correct?
zfs destroy -r default/lxd
zfs rename backup/lxd default/lxd
snap install lxd
nsenter + mkdir + mount the datasets ← I’m lost here!
lxd import container1, etc. for all containers
So I can follow the first half, but I think renaming the pool should happen before installing lxd again. I am quite lost in what to do in 6:
what is the nsenter good for?
to what directory should I mount the containers?
is it possible to take advantage of the lxd database in the backup or any other container related data during the restore?
I would be very happy about any help, since I’ve never done this before and I don’t want do destroy any of the rescued data by accident. Thank you in advance.
For anyone who encounters the same situation, here is my successful solution. I needed a few days to find out the right steps and their ordering, fighting various error messages.
Recovery containers from a damaged drive, assuming you managed to backup/dump the zfs partition on a second HDD that is now in a new machine with Ubuntu 20.04, goes as follows:
sudo adduser $(whoami) lxd && newgrp lxd
adds you to the lxd group granting you permissions to manage LXD
sudo zpool import
prints a list of available volumes to import, remember a long number at the top, e.g. 1234567890123456789
sudo zpool import -d /dev -f -R / 1234567890123456789 default
imports the volume, note that long number copied from the listing in the previous step
– if you just want to read the files, you can also add -o readonly=on but that will not allow you to import any container
– i chose -R / since the mountpoints for all containers were already correctly specified as /var/snap/lxd/common/lxd/storage-pools/default/containers/container_name (after zpool import just check by zfs list otherwise export and import again with a new path (or just reboot)
– the last argument is the pool name, use the same as you had on the old machine
Maybe you need to call lxc info once, not sure but it will do no harm anyway.
create any profiles you used in the old setup, e.g. X11
repeat 7. - 9. for all containers you need to recover
lxc list should now show all recovered containers, note that after starting their IP address will not be assigned. Now you may either export the containers, re-install lxd (now finally calling lxd init as well) and import the images again or you may follow the suggestions over here to initialize network and storage manually: