Installation of qemu
You will need a dedicated group that will contain users (other than
root) allowed to access the KVM device. Create this group by
running the following command as the
groupadd -g 61 kvm
Add any users that might use the KVM device to that group:
usermod -a -G kvm
Install qemu by running the
Qemu is capable of running many targets. The build process is
also capable of building multiple targets at one time in a comma
delimited list assigned to
--target-list. Run ./configure --help to get a
complete list of available targets.
if [ $(uname -m) = i686 ]; then
mkdir -vp build &&
cd build &&
../configure --prefix=/usr \
unset QEMU_ARCH &&
To run the built in tests, run make
V=1 -k check.
Now, as the
You will also need to add an Udev rule so that the KVM device gets
cat > /lib/udev/rules.d/65-kvm.rules << "EOF"
KERNEL=="kvm", GROUP="kvm", MODE="0660"
Change the permissions and ownership of a helper script, which is
needed when using the “bridge” network device (see below):
chgrp kvm /usr/libexec/qemu-bridge-helper &&
chmod 4750 /usr/libexec/qemu-bridge-helper
For convenience you may want to create a symbolic link to run the
installed program. For instance:
ln -sv qemu-system-`uname -m` /usr/bin/qemu
Since using qemu means using a virtual computer, the steps to set
up the virtual machine are in close analogy with those to set up a
real computer. You'll need to decide about CPU, memory, disk, USB
devices, network card(s), screen size, etc. Once the
“hardware” is decided,
you'll have for example to choose how to connect the machine to
internet, and/or to install an OS. In the following, we show basic
ways of performing those steps. But qemu is much more than this,
and it is strongly advised to read the qemu documentation in
It is standard practice to name the computer running qemu
“host” and the emulated
machine running under qemu the “guest”. We'll use those notations in the
The following instructions assume the optional symbolic link,
qemu, has been created.
must be run from an X Window System based terminal (either
locally or over ssh).
A virtual disk may be set up in the following way:
qemu-img create -f qcow2 $VDISK_FILENAME $VDISK_SIZE
The virtual disk size and filename should be ajusted as desired.
The actual size of the file will be less than specified, but will
expand as needed, so it is safe to put a high value.
To install an operating system, download an iso image from your
prefered Linux distribution. For the purposes of this example,
Fedora-16-x86_64-Live-LXDE.iso in the current
directory. Run the following:
qemu -enable-kvm \
-drive file=$VDISK_FILENAME \
-cdrom Fedora-16-x86_64-Live-LXDE.iso \
-boot d \
Follow the normal installation procedures for the chosen
option specifies the boot order of drives as a string of drive
letters. Valid drive letters are: a, b (floppy 1 and 2), c (first
hard disk), d (first CD-ROM). The
-m option is the amount of memory to
use for the virtual machine. The choice depends on the load of the
host. Modern distributions should be comfortable with 1GB. The
-enable-kvm option allows
hardware acceleration. Without this switch, the emulation is much
Defining the virtual hardware
The virtual machine hardware is defined by the qemu command line.
An example command is given below:
qemu -enable-kvm \
-smp 4 \
-cpu host \
-m 1G \
-drive file=$VDISK_FILENAME \
-cdrom grub-img.iso \
-boot order=c,once=d,menu=on \
-net nic,netdev=net0 \
-netdev user,id=net0 \
-soundhw ac97 \
-vga std \
-serial mon:stdio \
Meaning of the command line options
-enable-kvm: enable full
KVM virtualization support. On some hardware, it may be necessary
to add the undocumented
smm=off option in order to enable KVM.
-smp <N>: enable
symmetric multiprocessing with <N> CPUs.
simulate CPU <model>. the list of supported models can be
file=<filename>: defines a virtual disk whose
image is stored in
defines an iso formated file to use as a cdrom. Here we use a grub
rescue disk, which may turn handy when something goes wrong at boot
order=c,once=d,menu=on: defines the boot order for the
nic,netdev=<netid>: defines a network card
connected to the network device with id <netid>.
user,id=<netid>: defines the network
“user” device. This is a
virtual local network with addresses 10.0.2.0/24, where the host
has address 10.0.2.2 and acts as a gateway to internet, and with a
name server at address 10.0.2.3, and an smb server at address
10.0.2.4. A builtin DHCP server can allocate addresses between
10.0.2.15 and 10.0.2.31.
defines the soundcard model. The list may be obtained with
-vga <type>: defines
the type of vga card to emulate.
-serial mon:stdio: sends
the serial port of the guest (
/dev/ttyS0 on linux guests), multiplexed with the
qemu monitor, to the standard input and output of the qemu process.
-name <name>: sets
the name of the guest. This name is displayed in the guest window
caption. It may be useful if you run several guests at the same
Controling the Emulated Display
It may happen that the guest window displayed by qemu does not
correspond to the full capability of the emulated vga card. For
example, the vmware card is 1600x900 capable, but only 1024x768 is
displayed by default. A suitable Xorg configuration on the guest
allows to use the full size (Note that the Xorg video driver to use
is Xorg VMware Driver-13.2.1):
cat > /usr/share/X11/xorg.conf.d/20-vmware.conf << "EOF"
# cvt 1600 900
# 1600x900 59.95 Hz (CVT 1.44M9) hsync: 55.99 kHz; pclk: 118.25 MHz
Modeline "1600x900" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
Option "PreferredMode" "1600x900"
Identifier "VMware SVGA II Adapter"
Option "Monitor" "default"
Identifier "Default Screen"
Device "VMware SVGA II Adapter"
Modes "1600x900" "1440x900" "1366x768" "1280x720" "800x480"
New sizes will be available besides the native ones. You need to
restart X in order to have the new sizes available.
The above solution for networking allows the guest to access the
local network through the host (and possibly to access internet
through the local routers), but the converse is not true. Not even
the host can access the guest, unless port forwarding is enabled.
And in the case several guests are running, they cannot communicate
with each other. Other network devices can be used for this
purpose. For example, there is the “socket” device, which allows several guests to
share a common virtual network. In the following, we describe in
more details how to set up the “bridge” device, which allows the guests to
appear as if connected to the local network. All the commands below
should be run as the
Set up bridging with bridge-utils-1.6. Only the physical
interface(s) should be set up at boot. The virtual interface(s)
will be added as needed when qemu is started.
Set up a required configuration file:
install -vdm 755 /etc/qemu &&
echo allow br0 > /etc/qemu/bridge.conf
In the command above, replace the switch
-netdev user,... with