Recovering files from lxd containers

I recently had to nuke my laptop. I have full filesystem backups on a separate box. I was using the lxd snap, and would like to recover a few files from one of the containers. Somewhere in the 92GB /var/snap/lxd/common/lxd/disks/default.img is I imagine the parts needed.

What’s the “best” (fastest / easiest) thing to do here? Is there some way to ‘mount’ that glob of data and poke about in it for the files I need? Or should I shutdown lxd on my laptop, snap refresh to the same snap version on the backup and manually copy all the data and config directories to restore it?

I don’t need any of the containers, just a few files from one of them, but if I managed to restore the system back to how it was before I nuked, that’d be fine too. I’m just not sure what exactly to recover as files seem to be spread out a bit.

Appreciate any pointers. Thanks.


the /var/snap/lxd/common/lxd/disks/default.img file is simply a raw loop block device image. So you can attach it to a loop device with:

losetup /dev/loop0 /var/snap/lxd/common/lxd/disks/default.img

at that point /dev/loop0 will be a block device backing the filesystem you chose as storage pool backend driver. If you are using zfs as backend driver, the loop block device should contain a single zpool and you can the use zfs command line tools to list and mount the datasets in that zpool, including the datasets containing the filesystem of the container you’re interested in.

Thanks. I found a guide at which suggests I can indeed use the zfs tools, but I can’t even get past step 2, the kxpartx part doesn’t produce any output and the mout line doesn’t work either.