Using Virtual Machines with QEMU

General Information

Do you like to run virtual servers, but don’t want to run Windows as a host? QEMU is your answer as it will host several virtual machines within you FreeBSD installation.


  1. Root/sudo access.


Install qemu with the options showed below:

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

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)

Install and configure sudo:

# cd /usr/ports/security/sudo && make install clean

sudo config:

Note: ‘username’ is your username.
# cat > /usr/local/etc/sudoers << EOF
# root            ALL=(ALL) ALL
# username        ALL=(ALL) NOPASSWD: ALL


Load the needed modules:

# sudo kldload aio
# sudo kldload kqemu

Create Windows 2000 install CD image by using cat or dd:

# cat /dev/acd0 > ~/qemu/win2k.iso
# dd bs=2048 if=/dev/acd0 of=~/qemu/win2k.iso

Create qemu image for new OS:

# qemu-img create -f qcow2 ~/qemu/win2000.img 4G

Install new os, Windows 2000 in our example:

# qemu -boot d -hda ~/qemu/win2000.img -m 128 -cdrom ~/qemu/win2k.iso -win2k-hack -localtime


Typical usage of OS under qemu:

# qemu -hda ~/qemu/win2000.img -m 256 -localtime

Typical usage of OS under qemu in snapshot mode [to commit made changes hit left_CTRL+left_ALT+2 and type commit]:

# qemu -hda ~/qemu/win2000.img -m 256 -localtime -snapshot

To switch focus between qemu mouse focus and X11 mouse focus use: left_CTRL+left_ALT

To ensure that you use kqemu kernel module in user mode hit left_CTRL+left_ALT+2 and type info kqemu

Note: If everything is ok you will see:

kqemu support: enabled for user code

if not you will see:

kqemu support: disabled

If it's disabled it will work, but terribly slow. You will be running a Pentium 75MHz on a host with an AthlonXP 1.66GHz.

To switch between qemu console and qemu OS emualtion use left_CTRL+left_ALT+2 to go to the console and left_CTRL+left_ALT+1 to go back to the emulation.

To enable the network on the emulated OS, use DHCP configuration inside the emulated OS to get an IP adress of 10.x.x.x.

After you shutdown your emulated OS (or using qemu console left_CTRL+left_ALT+2 and type quit) use this command to launch your emulated OS again:

# qemu -hda ~/qemu/win2000.img -m 256 -localtime

To enable sound in the qemu OS, you just need to launch qemu the way I listed above only with -soundhw sb16 or -soundhw es1370 to emulate Sound Blaster 16, or Sound Blaster 128. You can also enable the standard annoying BEEP with -soundhw pcspk. You can also enable all three of them like that: -soundhw sb16,es1370,pcspk, or just BEEP + one of them: -soundhw es1370,pcspk. For example:

# qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw pcspk
# qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw es1370,pcspk
# qemu -hda ~/qemu/win2000.img -m 256 -localtime -soundhw es1370,pcspk,sb16

There is also the following fluxbox add-on to ~/.fluxbox/apps:

# qemu
[app] (class=SDL_App)
  [Workspace]  {2}
  [Deco]       {BORDER}


  1. man qemu-img
  2. man qemu
  3. man aio
  4. man dd
  5. man cat
Note: The same schema works for Solaris 10 and WindowsXP, you only do not use -win2k-hack.

Other discussions:


Speak Your Mind