Introduction
This HOWTO covers how to converting a qcow2 disk image to a ZFS volume.
This process can be useful if you are migrating virtual machine storage or take advantage of the snapshot functionality in the ZFS filesystem.
Prerequisites
- A working ZFS installation with free space
- The
qemu-img
command line utility - The
qemu-nbd
command line utility - Kernel support for nbd
doas modprobe nbd
Steps
The following steps needs to be performed
Verify the qcow2 Image
qemu-img check /path/to/image.qcow2
Connect the qcow2 Image to a Network Block Device
doas qemu-nbd --connect=/dev/nbd0 /path/to/image.qcow2
Get the size of the current virtual disk
doas blockdev --getsize64 /dev/nbd0
Create the ZFS Volume
doas zfs create -V <REPLACE_THIS_WITH_THE_OUTPUT_OF_THE_PREVIOUS_COMMAND>b <ENTER_THE_ZFS_PATH>
# Example:
# doas zfs create -V zfs create -V 4294967296b zpool/ROOT/vm/vm1-vda
Copy the disk
doas dd if=/dev/nbd0 of=/dev/zvol/<PATH_TO_YOUR_CREATED_ZFS_VOLUME> bs=4096 status=progress
# Example:
# doas dd if=/dev/nbd0 of=/dev/zvol/zpool/ROOT/vm/vm1-vda bs=4096 status=progress
Disconnect the qcow2 image
doas qemu-nbd --disconnect /dev/nbd0
Update your Configuration
Update the configuration that previously used the .qcow2 image to instead use the block device proviced by ZFS (/dev/zvol/)