Please Note

This document is under constant changes, this is nowhere near the final stage.

FreeBSD is not officially supported by any virtualization package as a host operating system at this time, but many people use older versions of VMware in this capacity. Work is also ongoing in getting Xen™ to work as a host environment on FreeBSD.

... FreeBSD as a Host OS using QEMU

Old unsupported VMware 3 avialable in FreeBSD Ports collection runs only in Linux Emulation and has other limitations. Many today systems have dual/quad-core CPUs and some even have several CPUs. VMware is very limited here because it forces you to use non SMP kernel so you will be able to only use ONE core or ONE CPU. This is non-acceptable.

There is very sensible open source alternative for VMware and it is named QEMU. It is still under heavy development being very stable and quite fast at the same time. This chapter will guide you how to run many operating systems under QEMU with FreeBSD as a Host OS.

QEMU is both machine emulator and virtualizer, it just depends how You use it. While used as an emulator it is able to emulate machine with diffrent architecture using dynamic translation. When used as a virtualizer, it is pretty fast by executing code directly on CPU, but You will need to use KQEMU accelrator kernel module and You will be limited to run only operating system from the same architecture, but that is obvious of course.

... Installing QEMU

QEMU is ready to install from the Ports Collection. Simply do the following:

# cd /usr/ports/emulators/qemu
# make install clean

Choose these options to get best results from QEMU and also enable support for KQEMU accelrator:

Options for qemu:
[X] KQEMU Build with (alpha!) accelerator module
[X] HACKS_CIRRUS Large display speedup (buggy!)
[ ] RTL8139_TIMER allow use of re(4) nic with FreeBSD guests
[ ] SAMBA samba dependency (for -smb)
[X] SDL SDL/X dependency (graphical output)

You can also consider enabling Samba if you wish to have your Host OS resources avialable in guest os.

After you successfully installed QEMU you must now load necesary modules kqemu and aio. You must be root to do that.

# kldload aio
# kldload kqemu

Now as you invoke kldstat(8) you will see modules that you just have loaded.
% kldstat
Id Refs Address    Size     Name
 1    4 0xc0400000 2fc0b0   kernel
 2    1 0xc0788000 62880    acpi.ko
 3    1 0xc6850000 7000     aio.ko
 4    1 0xc8be7000 1d000    kqemu.ko
To make those modules load always at system boot you will need to add this line to /etc/rc.conf.


After these steps you have fully functional QEMU installation on you system.

... Using QEMU

While there are avialable some graphical QEMU frontends like GTK2 based Qemu Launcher amd QT based kqemu, QEMU itself by default works as a pure CLI application and does that extreamly well.

After installation there are several binaries under /usr/local/bin named qemu, those are:


All qemu-system-* binaries are used to emulate other architectures. qemu is used for pure virtualization with KQEMU accelrator module and qemu-img is used to create or convert hard disk images used by QEMU.

... . ... Dumping operating system ISO image to hard disk

Constant switching of operating system media like CD or DVD is not very comfortable, creating its ISO image on hard disk is more handy. We can do that in many ways, for example using FreeBSD base system utilities like cat(1) or dd(1).

Both bottom lines does the same, but using diffrent utilities. I also assume that the media is in first CD/DVD drive named acd0, if you have more then one optical drive remember to put proper acd device as source for operating system ISO image.

% cat /dev/acd0 > ~/qemu/operating-system.iso
% dd bs=2048 if=/dev/acd0 of=~/qemu/operating-system.iso

Do the same for every oeprating system that you want to emulate, it will save you time in the future.

... . ... Creating QEMU hard disk images

QEMU supports several diffrent image types, but qcow2 seems most suitable because only the needed space is used, it also allows other possibilities like optional AES encryption, zlib based compression and support of multiple VM snapshots.

To create a new empty hard disk image type the following.

% qemu-img create -f qcow2 ~/qemu/image.qcow2 4G
Formating 'image.qcow2', fmt=qcow2, size=4194304 kB

This will create a empty 4 gigabytes file ~/qemu/image.qcow2.

To get more info about creating and converting QEMU images to other formats, enabling encryption and other topics read qemu-img manual page.

... . ... Installation of Guest OS under QEMU

After you have created QEMU hard disk image you can now start installing the Guest OS.

% qemu -boot d -hda ~/qemu/image.qcow2 -cdrom ~/qemu/operating-system.iso -localtime

You can experience a situation like your mouse will not respond, it is because QEMU "stolen" the Mouse Focus, to bring back Mouse to X11 hit Left CTRL + Left ALT keys. To bring back Focus to QEMU click again on its window or hit mentioned combo again.

Short description of used options, -boot tells QEMU from which device it should boot, a for floppy (used with -fda option), c for standart hard disk boot which is QEMU default behavior and d for booting from CD-ROM drive.

Next is -hda which tells which image to use as a Primary Master hard disk device, Primary Slave, Secondary Master and Secondary Slave hard disk devices are avialable thru respectively -hdb, -hdc and -hdd options.

Oprtion -cdrom (as you propably guesed) is used to tell QEMU which image or device use as CD-ROM device. To specify first avialable physical CD-ROM device you use it like that -cdrom /dev/acd0.

To synchronize Guest and Host OS time we use -localtime option.

By default QEMU assigns 128 megabytes of RAM to Guest OS, this behavior can be changed using -m option, like that for example -m 100 which will limit Guest OS RAM to 100 megabytes. Size of maximum assigned memory is limited by KQEMU module and is equal to half of you computer memory, so if you run a box with 512 megabytes of RAM, maxumim amount of memory that you can use for Guest OS is 256 megabytes.

You can also emulate sound card to hear sound from Guest OS, to achieve that use -soundhw option with suitable arguments, pcspk for standart PC Speaker, es1370 for Sound Blaster™ 128 or sb16 for Sound Blaster™ 16 card. Example use of mentioned option -soundhw es1370,pcspk will add PC Speaker and Sound Blaster™ card to our Guest OS.

For more advandes options like Serial Console redirection, VPN session or adding custom Network Adapters check qemu(1) manual page for details.

QEMU loading FreeBSD 6.2.

IMPORTANT NOTE: While KQEMU accelrator greatly enhances QEMU preformance it sometimes must not be used while installing Guest OS because it will hand durring the installation process. A short note how to achieve that.

# kldunload kqemu
% qemu -boot d -hda ~/qemu/image.qcow2 -cdrom ~/qemu/operating-system.iso -localtime

Windows2000 NOTE: to install this one as a Guest OS invoke qemu with -win2k-hack option to omit "no free space left" error message.

SCO Unixware NOTE: installation of this one as a Guest OS is little diffrent from typical process, You do not boot from provided ISO image but using two boot floppies. A command to boot into SCO Unixware installation process is as follows.

qemu -boot a -no-fd-bootchk -fda ~/qemu/sco-unixware-disk1.img -hda ~/qemu/sco-unixware.qcow2 -cdrom ~/qemu/sco-unixware.iso -localtime -net nic,model=ne2k_pci

You will be asked to insert 2nd floppy in the boot process, like on the screen bellow.

To do that you must switch to QEMU command line (which offers some basic TAB completion) with this combo Left CTRL + Left ALT + 2 and change to 2nd floppy to continue boot process.

(qemu) change fda /home/YOU/qemu/sco-unixware-disk2.img

Now switch back to main QEMU screen with Left CTRL + Left ALT + 1 combo, boot process will end and you will be ready to proceed SCO Unixware installation.

About used SCO Unixware qemu fancy options, -no-fd-bootchk disables checking for boot signature on the floppy (you will not be able to boot this floppy whiout that option), -net nic,model=ne2k_pci changes the default Network Adapter to NE2000 which is good supported under SCO Unixware operating system.

After you installed Guest OS you will probably have to stop QEMU and start it again with diffrent options, there are two reasons for that, you have been force to install Guest OS without KQEMU module and now performance will hurt or you will not be able to boot just installed os because it will boot again from the CD-ROM. Here is an example of invoking qemu after installation.

% qemu -hda ~/qemu/image.qcow2 -localtime

... . ... Changing removable media under QEMU

While invoking qemu with -cdrom option you have ISO image or physical CD-ROM drive avialable under Guest OS, to change that media while running QEMU switch to QEMU Command Line with Left CTRL + Left ALT + 2 combo. Example below will tell You how to switch between ISO image image.iso and physical drive /dev/acd0.

(qemu) change cdrom eject
(qemu) change cdrom /home/YOU/image.iso
(qemu) change cdrom eject
(qemu) change cdrom /dev/acd0

Changing floppies is very similar, but You do not have to eject the media before setting the new one.

(qemu) change fda /home/YOU/floppy-image.img
(qemu) change fdb /dev/fd0
(qemu) change fdb eject

You can also remove all the media from QEMU with eject command, like change cdrom eject.

... . ... Using KQEMU accelrator to improve QEMU performance

After you loaded kqemu.ko module using kldload KQEMU accelrator is ready to use and will be used by default by QEMU. You can check if qemu uses KQEMU accelrator module like that.

(qemu) info kqemu
kqemu support: enabled for user code

Phrase "enabled for used code" shows that QEMU is using KQEMU accelrator. However if kqemu.ko module is not loaded you will se info like that.

(qemu) info kqemu
kqemu support: disabled

Remember also that while QEMU is running wothout KQEMU it is much slower, but sometimes mandatory for installation process of Guest OS as mentioned above.

... . ... Using QEMU to run LiveCD or LiveDVD distribution

LiveCD/DVD distribution does not need hard disk image, so qemu invocation can look like that.

% qemu -boot d -cdrom ~/qemu/livecd.iso

... . ... Network under Guest OS

To enable network connection in Guest OS use DHCP inside Guest OS, you will automatically get 10.x.x.x class address.

... . ... Using snapshots under QEMU

Running Guest OS with -snapshot option runs Guest OS without changing its QEMU hard disk image, you can change inside Guest OS whatever you want, even break the Guest OS, and after qemu quits you will be able to launch it again just like that. However if you would like to write changes made in snapshot mode switch to QEMU Command Line with Left CTRL + Left ALT + 2 and type commit, this will write your changes to hard disk image.

... . ... Glossary about running Guest OS under QEMU

Not all operating systems will run under QEMU, but most of them will do, here is a list of operating systems that runs under QEMU.

list of operating systems that I succesfully run as Guest OS:
- FreeBSD
- NetBSD
- DragonflyBSD
- OpenBSD
- Solaris
- QNX Neutrino
- SCO Unixware
- Linux
- WindowsNT 4.0
- Windows2000
- WindowsXP

QNX Neutrino running under QEMU.


author: vermaden [AT] interia [DOT] pl