qemu QEMU instructions

Does anyone have concise instructions for running qemu on FreeBSD?

I'm mainly interested in running aarch64 and riscv64, both 14.2-RELEASE. That would be on an amd64 14.2-RELEASE host.

Most of the instructions that I can find are for Linux and the wiki looks very outdated, covering FreeBSD 7 and 8.
 
the wiki looks very outdated, covering FreeBSD 7 and 8.
Try those more up to date specific arm64/QEMU (last edited 2025-03-31) and riscv/QEMU (last edited 2024-11) FreeBSD wiki pages.
Rich (BB code):
/usr/src-main # make targets
Supported TARGET/TARGET_ARCH pairs for world and kernel targets
    amd64/amd64
    arm/armv7
    arm64/aarch64
    i386/i386
    powerpc/powerpc
    powerpc/powerpc64
    powerpc/powerpc64le
    riscv/riscv64
 
Here is my RISC-V command:
Code:
qemu-system-riscv64 \
  -M virt \
  -smp 8 \
  -m 32G \
  -nographic \
  -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
  -kernel u-boot.bin \
  -drive file=FreeBSD-14.0-RELEASE-riscv-riscv64.raw,format=raw,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -nographic \
  -netdev user,id=net0,ipv6=off,hostfwd=tcp::3235-:22 \
  -device virtio-net-device,netdev=net0 \
  -device virtio-rng-pci
 
That looks better. I still get

qemu-system-aarch64: -netdev user,id=net0: network backend 'user' is not compiled into this bi
nary
 
I still get

qemu-system-aarch64: -netdev user,id=net0: network backend 'user' is not compiled into this bi
nary
/usr/ports/emulators/qemu/Makefile shows
Rich (BB code):
CONFIGURE_ARGS+=        --disable-attr \
...
                        --disable-user \
...
I wonder if this configuration is responsible for the message.

Try "tap" instead.


Network backend types

In most cases, if you don't have any specific networking requirements other than to be able to access to a
web page from your guest, user networking (slirp) is a good choice. However, if you are looking to run any
kind of network service or have your guest participate in a network in any meaningful way, tap is usually
the best choice.


EDIT: If you insist on "user", perhaps try (lower distversion) emulators/qemu-devel , --disable-user is not set.
Code:
CONFIGURE_ARGS= --localstatedir=/var --mandir=share/man --extra-ldflags=-L\"/usr/lib\" \
                --extra-ldflags=-L\"${LOCALBASE}/lib\" --enable-debug \
                --prefix=${PREFIX} --cc=${CC} --enable-netmap --disable-kvm \
                --disable-linux-user --disable-linux-aio --disable-xen \
                --enable-debug-info --python=${PYTHON_CMD} --disable-guest-agent \
                --extra-cflags=-I${WRKSRC}\ -I${LOCALBASE}/include\ -DPREFIX=\\\"\"${PREFIX}\\\"\"
 
/usr/ports/emulators/qemu/Makefile shows
Rich (BB code):
CONFIGURE_ARGS+=        --disable-attr \
...
                        --disable-user \
...
I wonder if this configuration is responsible for the message.

The text of pkg-messsage could be better

"- Needs to set net.link.tap.user_open sysctl in order to use /dev/tap*
networking as non-root. Don't forget to adjust device node
permissions in /etc/devfs.rules."

How to make the sysctl permanent? And how about actually explaining what to put in /etc/devfs.rules?

"- slirp (usermode networking) is fixed now, you still have to manually
do: echo nameserver 10.0.2.3 >/etc/resolv.conf but that is normal. And
you have to wait a bit for dhclient to do its thing; traffic to
address 10.0.2.2 is routed to 127.1 on the host."

That sounds like it conflicts with the --disable-user option.

Try "tap" instead.

With tap I can at least get both aarch64 and riscv64 images to boot. Only when running qemu as root though.

Next I need to figure out what they need to get dhcp to work.
 
"- Needs to set net.link.tap.user_open sysctl in order to use /dev/tap*
...
How to make the sysctl permanent?
In /etc/sysctl.conf, in case the question wasn't rhetorically.

And how about actually explaining what to put in /etc/devfs.rules?
I suppose the author of the pkg-message expected that the user should look into devfs.rules(5) manual by mentioning it, if not familiar with the configuration. Specifying the manual by name and man section number (devfs.rules(5) ) would have been more precise, though.

Considering the topic is about permissions for the "tap" device, an example rule could be:
Code:
[qemurules=6]
add  path  'tap*'  mode  660 group qemu

/etc/rc.conf
Code:
devfs_system_ruleset="qemurules"
Create "qemu" group, add user to that group, service devfs restart


"- slirp (usermode networking) is fixed now, you still have to manually
...

That sounds like it conflicts with the --disable-user option.
The pkg-message you quoting from seems from emulators/qemu-devel, remember this port is not build with the "--disable-user" configuration argument (see post # 6, under EDIT, in case you haven't seen it) .

In comparison emulators/qemu pkg-message.
 
Did you get this working? All the examples I have to contribute are for Mac ARM, and I'm pretty sure they won't work on FreeBSD.
 
Did you get this working? All the examples I have to contribute are for Mac ARM, and I'm pretty sure they won't work on FreeBSD.

Mostly. I was doing the testing in a VirtualBox VM, and I've gotten as far as being able to boot FreeBSD and get to a terminal on both aarch64 and riscv64. I haven't worked out how to get DHCP working yet. I need to decide whether to try this directly on either my old or new systems and whether I really need DHCP or not.
 
i have an old 13.0 armv7 image
it works with qemu package (vntnet usage causes a panic because of unaligned data but i think this is fixed in newer releases)
i used it to build packages for a rpi zero
sh:
#!/bin/sh
# send image file as first arg ($1)
qemu-system-arm \
  -M virt \
  -m 2048 \
  -drive file=pflash0.img,format=raw,if=pflash,readonly=on \
  -drive file=pflash1.img,format=raw,if=pflash \
  -drive file=$1,if=virtio,cache=writethrough \
  -nographic \
  -device qemu-xhci \
  -device usb-kbd \
  -device usb-tablet \
  -device virtio-net-pci,netdev=network0 \
  -netdev tap,ifname=tap6,id=network0,script=no,downscript=no \
  -serial mon:stdio \
  -serial telnet:10.1.1.2:4321,server,nowait
tap init
Code:
sysctl net.link.tap.up_on_open=1
sysctl net.link.tap.user_open=1
ifconfig tap6 create 2>/dev/null

ifconfig tap6 10.10.10.10/24
chmod 660 /dev/tap6
pflash images creation
Code:
dd if=/dev/zero of=pflash0.img bs=1m count=64
dd if=/dev/zero of=pflash1.img bs=1m count=64
dd if=QEMU_EFI.fd of=pflash0.img conv=notrunc
dd if=QEMU_VARS.fd of=pflash1.img conv=notrunc
source of QEMU_* is https://retrage.github.io/edk2-nightly/
 
Back
Top