I want to rebuild an LXD host by reinstalling the OS, and keep the containers as they are.
The reason for reinstalling is that I want to repartition the root filesystem (which is an SSD VPS), so that I can create a new ZFS filesystem on local SSD storage, which is now part of the root filesystem.
The containers are in a separate detachable zfs filesystem which I will not touch. I will detach it from the system while I reinstall the OS, and then reattach it.
Other than repartitioning, the OS will be the same, Ubuntu 18.04 + snap lxd.
All my container configuration is done via profiles.
What is the best way to do this? Can I somehow copy and restore all of /snap? Or export and restore the lxd snap? Or just its data? By the way, can i put /snap on a zfs filesystem, which I can backup and restore at any time?
This system has about a handful of small containers, but I am also interested in a solution that scales to many containers.
I’m thinking of trying something like this:
- Detach the zfs storage pool
- Reinstall the OS
- Create a temporary zfs storage pool at the same location as before
- lxd init with the same parameters as before, including the network address
- Create a dummy container for each old container, with the same guest OS as before.
- Stop all containers
- Detach the zfs storage pool filesystem and reattach the original one in its place
- Recreate the LXD profiles and apply them to the containers.
- Restart the containers
This will not copy the containers, although it creates temporary dummy containers.
I have tried a variation of this where instead of swapping the whole zfs storage pool, I replaced a container root filesystem, using “zfs receive” which I had previously “zfs send” from a container at another system.