Question: What is the best way to mount the .bin file that’s created by incus export for read-only review on a running incus server so it doesn’t interfere with the existing running instances?
Background:
I have a linux virtual machine on an Incus server that has a block device for it’s hard drive.
$zfs list
...
default/virtual-machines 111G 3.37T 24K legacy
default/virtual-machines/myvirtual1 10.1M 490M 10.1M legacy
default/virtual-machines/myvirtual1.block 102G 3.37T 102G -
I run incus exportnightly and have many backups where the tar.gz file for this VM has files in it
index.yaml virtual-machine.bin virtual-machine-config.bin
$ file virtual-machine.bin
virtual-machine.bin: ZFS snapshot (little-endian machine),
version 17301505, type: ZVOL, destination GUID: REDACTED,
name: 'default/virtual-machines/myvirtual1.block@backup-REDACTED'
$ file virtual-machine-config.bin
virtual-machine-config.bin: ZFS snapshot (little-endian machine),
version 17301521, type: ZFS, destination GUID: REDACTED,
name: 'default/virtual-machines/myvirtual1@backup-REDACTED'
I want to be able to mount the block .bin device on the incus server and and move a ton of files in that mount to a new container that will be setup as a regular incus container in default/containers/Container2
The reason why I’m trying it this way is because the simple rsync between running instances VM myvirtual1 and Container2 was causing iostat issues, but I can think of other reasons one might want to mount an old .bin file too (Disaster recovery, forensics, real-time change monitoring, etc, etc.)
I’m new to zfs, so forgive this newbie question. I don’t want to mess up my existing incus zpools or use up a ton of space importing a large filesystem as a duplicate.
To repeat the above question
What is the best way to mount the .bin file that’s created by incus export for read-only review on a running incus server so it doesn’t interfere with the existing running instances?
I’ve looked up recommended methods and there seem to be two ways to do this
(1) stream the .bin file to a new temporary pool:
#create sparse file
truncate -s 50G /tmp/zfs_temp.raw
#point pool to blank file
zpool create temprecovery /tmp/zfs_temp.raw
#stream data into zpool
zfs recv temprecovery/disk < virtual-machine.bin
#find loop
FOOLOOP=$(kpartx -av /dev/zvol/temprecovery/disk)
mkdir -p /mnt/vm_files
mount /dev/mapper/$FOOLOOP /mnt/vm_files
#when done ... remove it all
umount /mnt/vm_files
kpartx -dv /dev/zvol/temprecovery/disk
zpool destroy temprecovery
rm /tmp/zfs_temp.raw
(2) Attach the old file to a loop device (apparently this doesn’t work since the .bin files are zfs - streams)
—BEGIN IGNORE THIS PART—
# Create loop device
losetup /dev/loop20 /path/to/virtual-machine.bin
#import that block device
zpool import -d /dev/loop20 -o readonly=on -o altroot=/mnt/recovery mypool
zpool status
zfs list
# see if it is already mounted in /mnt/recovery
# if not mounted
zfs mount mypool/MYDATA #where MYDATA is what shows up under
-–END IGNORE THIS PART—
(2) Stream directly to a new volume in the existing default pool
# 1. Receive stream into new
zfs receive default/recovery-disk < virtual-machine.bin
# 2. Map partitions
FOOLOOP=$(kpartx -av /dev/zvol/default/recovery-disk)
# 3. Mount the target partition
mkdir -p /mnt/recovery_os
mount /dev/mapper/"$FOOLOOP" /mnt/recovery_os
Thanks!