frank's page

DragonFlyBSD VM

Summary: Booting DragonFlyBSD in QEMU from physical storage.

Old hardware needed to be cleaned up, but I still need access to its data. Unfortunately Linux-based systems can't mount HAMMER2 file systems. QEMU to the rescue!


The two storage devices (boot and data) appear as /dev/sdb and /dev/sdc on my Linux system.

Pass these devices to QEMU with the -drive option:

qemu-system-x86_64 \
    -m 2G \
    -display curses \
    -enable-kvm \
    -drive file=/dev/sdb,if=virtio,format=raw,media=disk \
    -drive file=/dev/sdc,if=virtio,format=raw,media=disk \
    -netdev user,id=mynet0,hostfwd=tcp::7722-:22 \
    -device e1000,netdev=mynet0

NOTE: Add your user to the disk group. It lets you access disk files without being root. Run usermod -aG disk <user>. Instead of a re-login, run newgrp disk and then run the QEMU command in the same shell.

hostfwd=tcp::7722-:22 enables port forwarding from port 7722 on the host to port 22 on the guest OS. With the following command you'll be able to log into the guest OS (if SSH server is enabled):

ssh -p 7722 username@localhost


While booting, DragonFlyBSD complains that it can't find the root filesystem:

Mounting root from hammer2:serno/50026B77820A3CD8.s1d
hammer2_mount: root 'serno/50026B77820A3CD8.s1d'
hammer2_mount: dev="serno/50026B77820A3CD8.s1d" label="ROOT" rdonly=1
no disk named 'serno/50026B77820A3CD8.s1d'
hammer2: cannot find 'serno/50026B77820A3CD8.s1d'
Root mount failed: 6

It gives a way to select one:

Manual root filesystem specification:
  <fstype>:<device>  Specify root (e.g. ufs:da0s1a)
  ?                  List valid disk boot devices
  panic              Just panic
  abort              Abort manual input


Entering ? gives you a list of possibilities:

mountroot> ?
Possibly valid devices for root FS:
 "md0"  "md0s0"  "vn0"  "vn1"  "vn2"  "vn3"  "acd0"  "vbd0"  "vbd0s1"  "vbd1"  "
vbd0s1a"  "vbd0s1b"  "vbd0s1d"  "vbd0s1e"  "vbd1s0"  "cd0"  "sg0"

NOTE: vbd devices are block devices created by virtio_blk.

With some guesses I found the correct one:

mountroot> hammer2:vbd0s1d

loader.conf and fstab

DragonFlyBSD boots into single-user mode and mounts the root file system in read-only mode. /boot/loader.conf and /etc/fstab need to be updated with the new storage device names in order for the system to boot properly

Remount to read-write:

# mount -w /

Open /boot/loader.conf and replace the old device name (e.g. serno/50026B77820A3CD8.s1d) with vbd0s1d. It'll look like this:


Open /etc/fstab and replace the old devices (e.g. serno/50026B77820A3CD8 and serno/WD-WCC4N0TL77FD) with vbd0 and vbd1. It'll look like this:

# Device        Mountpoint  FStype  Options   Dump  Pass#
/dev/vbd0s1a    /boot       ufs     rw        2     2
/dev/vbd0s1b    none        swap    sw        0     0
/dev/vbd0s1d    /           hammer2 rw        1     1
/dev/vbd0s1e    /build      hammer2 rw        2     2
/dev/vbd1s0     /data       hammer  rw        1     1


Reboot the system.

Now it's possible to access the files using, for example, sshfs:

sshfs -p 7722 username@localhost: ./guestfiles