My daily laptop is a Apple MacBook M4 Pro - it accomplishes everything I need, from API development to OCI containers. My internet gateway runs Dragonfly BSD and has been rock solid for many years now, using my prototype work published as autumnjolitz/cerberus_gateway.
My plan was if the gateway was hosed, I could pull out it's USB drive, connect it to my laptop [1], mount it in a guest virtual machine [2], see what's up, fix the issue or just reimage the drive and then redeploy it.
I completed it enough to put it into production. Then I had other things to do. Along the years that went by, I had switched from an x86-64 laptop to an arm64 one. I naively thought that whatever issues would occur with an architecture switch, they would be solved by someone else in time.
I discovered that options for virtual machines on OSX for running a different architecture (x86-64) than the host (arm64) were few and had documented issues that meant even sharing a USB device was unreliable or broken.
Turns out with qemu-nbd installed, you can share a OSX block device (/dev/disk##). And it works with the App Store release of UTM!
- UTM
qemu-nbd(Suggest you use Homebrew and brew install qemu)
I have a Dragonfly BSD guest named "Rana". It's an x86-64 guest as Dragonfly only supports x86-64.
We will be sharing a user mounted DMG with the guest for purposes of this demo.
- Create a blank dmg (ASIF preferred but a SPARSEBUNDLE works as well)
$ hdiutil create -layout NONE -size 1024g -type ASIF Blank-1TB
$ echo Blank-1TB*
Blank-1TB.asif
Tip
If you're not using Tahoe, I suggest you create a Tahoe guest via the UTM "Create New Virtual Machine" button. Share a local folder into Tahoe, create the ASIF images in that folder and then you can shutdown the guest and use these blank images
- Attach (do not mount!) the blank image
$ cp Blank-1TB.asif Dragonfly.asif
$ diskutil image attach --noMount Dragonfly.asif
/dev/disk4
- Edit UTM guest "Rana" under section Qemu -> Arguments and add the following arguments to the bottom using the "New" button
-device virtio-blk-pci,drive=driveCAFEBABE,serial=CE2AAFBCA18E4B55AE667359E213AFB6,bootindex=1-drive file=nbd:localhost:10809:exportname=rdisk4,if=none,media=disk,id=driveCAFEBABE
- Share the block device
Note
An actual block device like a physical USB drive will likely require you to prefix your qemu-nbd command with sudo -H.
$ qemu-nbd \
--bind localhost \
--port 10809 \
--image-opts \
driver=raw,file.driver=host_device,file.filename=/dev/rdisk4 \
--description 'DragonflyBSD ASIF target volume' \
--export-name=rdisk4
- Start the guest and work inside the guest
Footnotes
| [1] | The machine that runs the virtual machine is termed the "Host" |
| [2] | A virtual machine is often referred to as a "Guest" |