Print View

Using Virtual Machines with QEMU
Created: 01/06/2007


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.

Requirements

  1. Root/sudo access.

Installation

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)
[X] CDROM_DMA      IDE CDROM DMA
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
EOF

Configuration

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

Usage

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}
[end]

Resources

  1. man qemu-img
  2. man qemu
  3. man aio
  4. man dd
  5. man cat
  6. http://kidsquid.com/cgi-bin/moin.cgi/QuickStartGuide
  7. http://qemu-forum.ipi.fi/qemu-snapshots/
  8. http://qemu-forum.ipi.fi/
  9. http://qemu.org/user-doc.html
  10. http://en.wikipedia.org/wiki/QEMU

Note:  The same schema works for Solaris 10 and WindowsXP, you only do not use -win2k-hack.

Other discussions:

  1. http://bsdforums.com/forums/showthread.php?t=46399
  2. http://forums.bsdnexus.com/viewtopic.php?id=1536
  3. http://forums.pcbsd.org/viewtopic.php?p=42072

Author: vermaden
vermaden at interia dot pl



Copyright 2003 - 2010 BSD Guides.  All rights reserved.

About | Terms of Use | Privacy | Contact