Solved convert a zvol into a file

Hello,

I’m running few bhyve VMs on a FreeBSD 13-RELEASE host. Those VMs use a mix of disk image files and zvols as storage.
For example:

Code:
disk0_type="virtio-blk"
disk0_name="disk0.img"
disk1_type="virtio-blk"
disk1_name="/dev/zvol/sas/vm/rocky-splunk-d1"
disk1_dev="custom"

I would like to got back to 100% disk image files. Is there a clean way to convert my /dev/zvol/sas/vm/* into diskN.img?
 
I would truncate(1) a file with the exact same size than the zvol, then dd into with the zvol as input file.
Never did though. That said, there is no risk to try as you don't touch the zvol. You just copy it.
 
I guess I can try something like this. I’ll just have to ensure the «VM coherence» between disk image and zvol if I need to roll back.
 
Only partially related hint:

I can see why you want to do this: Some published benchmarks suggest simple files perform better than zvols for backing virtual disks. I wonder whether this is still the case (and if so, whether it can be fixed, because it's at least a bit counter-intuitive ...)

But: There's one feature that only (at least as far as I know) works with (sparse) zvols: Automatic shrinking of allocated space, as soon as the guest issues proper TRIM commands. So maybe think about whether you will need that first ;)
 
I tested zvol versus files and I saw no difference in speed. (But, the driver matters and nvme is the best.)

In my own framework, I chose files by default because it's simpler to manage ZFS snapshots for the VMs. All that relate to a VM can be in only one dataset.
 
Performance is interesting but in the end I feel like it’s easier to handle (I can move/backup a disk image file) and it’s more coherent to use only disk image files (or only zvols) instead of a mix.
 
You can also use qemu-img from emulators/qemu(@tools flavor):
qemu-img convert -p -O raw /dev/zvol/sas/vm/rocky-splunk-d1 /path/to/image/file.img
hooo this one looks nice.

Edit: been there, done that. It works really great. I’ve converted a bunch of zvols, tested corresponding VMs, no errors.
 
Last edited:
Back
Top