How to mount BTRFS images

I’ve switched to using Qubes with BTRFS when upgrading to 4.2, and my backup script broke as a result (the script mounts some qubes as read-only images to an offline backup qube and rsyncs any changes).

The method previously used for mounting was the one here: How to mount LVM images | Qubes OS, which doesn’t work with BTRFS since the images don’t show up as devices in the same way.

The only change that needed to be made was changing the $dev variable:

# Set up loop device, like /dev/loop42, that can be used with qubesdb-write
loopdevice=$(sudo losetup --find --read-only --show /var/lib/qubes/appvms/$YOUR_APPVM/private.img)
# Remove the leading /dev/ from the losetup output

Note that the path for a template will be different than for an appvm, check /var/lib/qubes to find that path.

Then follow the rest of the steps from How to mount LVM images | Qubes OS to mount the image.

After detaching, remove the loop device since it’s no longer needed:

sudo losetup -d $loopdevice