Qemu on FreeBSD as host

Qemu is a very fast generic and open source processor emulator by Fabrice Bellard. It runs under Windows 2000, Windows XP, GNU/Linux (RedHat, Debian) and FreeBSD "host" systems. After reading this page you should know:

How to install qemu from the Ports tree

How to run Qemu in FreeBSD 7.X or later

Installation notes

The installation of Qemu is pretty fast and easy. You can just install it from the Ports. The two Qemu ports we have in the Ports tree as of this writing are "emulators/qemu" and "emulators/qemu-devel". Installing "qemu-devel" for example should be as easy as:

# cd /usr/ports/emulators/qemu-devel
# make install && make clean

Note: If you want to use the KQEMU accelerator you need to use the old /usr/ports/emulators/qemu port instead and enable its KQEMU knob (otherwise qemu is much slower), this installs /usr/ports/emulators/kqemu-kmod-devel as a dependency and(!) builds kqemu support into the port. The qemu-devel port no longer supports kqemu (support was removed upstream.)

If you forget to load aio, then Qemu may crash with an error message of:

Bad system call: 12 (core dumped)

The if_tap and if_bridge modules are mandatory only when you plan to connect the "hosted" FreeBSD system with your existing network. If you don't need networking inside Qemu, it's ok to fire it up without these two networking modules in the host kernel.

Note: if you use kqemu make sure your kqemu.ko module is always in sync with your kernel (like with any kld installed outside of base), i.e. rebuild its port whenever you update the kernel — especially if you are switching branches or are following a -STABLE or -CURRENT branch!

You can enable autoloading of kqemu (and aio) at boot by adding a line to your /etc/rc.conf file:

kqemu_enable="YES"

Note: it is impossible to continue to use existing Windows 2000/XP disk images, since driver has been changed by activating IDE Bus-master DMA support.

Networking on FreeBSD 8

In FreeBSD 8.x, a couple of features have been introduced to make unprivileged tap networking setup easier. In particular, you do without the ifup script. All in all, the configuration is as follows:

Networking on FreeBSD 7

Default, network is configured inside of the emulator; not visible from outside. if you use fxp0, then:

# ifconfig tap create

# ifconfig bridge create

# ifconfig bridge0 addm tap0 addm fxp0 up

Also, /usr/local/etc/qemu-ifup script is needed. Networking Default, network is configured inside of the emulator; not visible from outside. This is not absolutely confotable! There are pros and cons: you must be the root and your qemu virtual machine is visible from outside. Assume you know your network interface name. In this case it is fxp0. you can check this by:

% dmesg | grep Ethernet

First, as root,

# sysctl net.link.ether.bridge_cfg=fxp0,tap0

# sysctl net.link.ether.bridge.enable=1

create /usr/local/etc/qemu-ifup script as

#!/bin/sh
/sbin/ifconfig ${1} up

and make this script runnable.

# chmod 755 /usr/local/etc/qemu-ifup

To do this at every boot time, write /etc/sysctl.conf

net.link.ether.bridge_cfg=fxp0,tap0
net.link.ether.bridge.enable=1

and in /boot/loader.conf

bridge_load="YES"

Invoke qemu by:

# qemu -net nic -net tap

This was originally taken from freebsd vde helpp Qemu as VNC server Display writing is very slow in QEMU, so run qemu as vnc server is very useful.

You should wait for while until Windows starts up. Full Screen mode (slow) QEmu uses SDL to output the screen. Modern video card supports VESA 2.0, so you can use SDL with VESA 2.0. While using SDL you need additional settings. First, reconfigure kernel with this configuration.

include GENERIC
ident MAHO
device atapicam
options VESA

save as /usr/src/sys/i386/conf/MAHO or something like that. Then,

# cd /sys/i386/compile/MAHO

# made cleandepend ; make depend ; make ; make install

you need additional setting:

# setenv SDL_VIDEODRIVER vgl

and you can run with full-screen in the console. Again, you must be the root. As far as I tested,

# kldload vesa

DOESN'T WORK (FOR ME). Unfortunately this is very slow, slower than X11 mode... Summary (My setting and command line) As summary, I present my setting for qemu 0.8.0.