Disclaimer: I resume here what I have learned
about the virtualization with the QEMU/KQEMU/KVM
tools. I DO NOT assume any responsibility about rights and wrongs of what you
find
here. These are my understandings of the tool, they can be
right or
wrong, so if you are using the information, evaluate it by yourself first.
Other
thing is that, this is a "hands on" kind of tutorial, so if you are
searching why and how... maybe here is not the best place to search for
them,
sorry :(.
Qemu is
a virtualization tool that started, and is maintained by Fabrice Bellard, the main pages
are QEMU,
KQEMU
and KVM.
There are many, really many, information sources about these tools. I
think these tools became even MORE popular after the linux kernel
introduce support
for them (kvm) by default.
What
we will discuss here are related to debian based distributions, what
does
include ubuntu. Attention that KVM will work ONLY if you have a newer
processor
with support to virtualization (e.g. Intel Core duo or AMD Athlon or
Turion), other thing is that KVM is based in QEMU, but is an
independent project. The
basic difference, for the user point of view, between KVM, Kqemu and
Qemu is the perceived
speed but the procedures are basically the same.
Other good tutorials and information sources
can be found at:
host #> : denotes commands executed in
the real machine, the host machine
virtual #>: denotes commands
executed in the virtual machine, the exemplified one
Installation
At first add the repository to
/etc/apt/sources.list for edgy:
host #>
cat >> /etc/apt/sources.list
deb http://ubuntu.tolero.org/ edgy main
deb-src http://ubuntu.tolero.org/ edgy
main
Or that lines if you are running dapper:
host #>
cat >> /etc/apt/sources.list
deb http://ubuntu.tolero.org/ dapper main
deb-src http://ubuntu.tolero.org/ dapper
main
I, personally, prefer to do the installation from the console
package manager, rather than with the graphical one (synaptic for
instance). Ensure that you have also ubuntu universal repository is
included to the sources.list. If so, cross your fingers and pass one by
one to the console the next commands:
To see if every thing it is OK
host #> /sbin/lsmod|grep
kqemu ##Comment## The kqemu
should appear here.
Disk
Images
To run Qemu you need first to
have an image of the system you want to run. You probably can find many
different images already made in the internet, or you can create your
own.
Let me say you do have a iso of
the desired Linux distribution, let us call here of
"ubuntu-7.04-desktop-i386.iso", if you do not have you can download
from the distributor site or buy a CD. host #> qemu
-boot d -cdrom ubuntu-7.04-desktop-i386.iso
rtmk_linux-2.6.16.49.img -m 400
If you have problems with the
designed memory size host #>
umount /dev/shm host #>
mount -t tmpfs -o size=416m none /dev/shm
Well.... in truth, as much memory you have the better, but remember
that you need to keep your own machine running ;)
Ok you already have an image but it is start to
get really small, to resize it:
The image people let at the QEMU website is
small, only 20MB, if I recall well, let me say we need to
resize it host #> dd
if=/dev/zero of=rt_linux-2.6.16.49.img seek=300 obs=1MB count=0
where 300 is new size to resize hdd.img in MB
host #> e2fsck
rt_linux-2.6.16.49.img host #> qemu-img
info rt_linux-2.6.16.49.img
to see the new virtual size, in my case it was 286M host #> resize2fs
/root/rt_linux-2.6.16.49.img 286M
To Use with the image
host
#> modprobe
kqemu host #> rm -rf /dev/kqemu host #> mknod /dev/kqemu c
250 0 host #> /bin/chmod 666
/dev/kqemu ##Comment##
make it accessible to all users host #> qemu -m
200 rtmk_linux-2.6.16.49.img&
Network Configuration
Ok I don't think you will want to use the
virtual machine without network, so we need to setup it. There are many
different ways to do this we will use tap interfaces using a bridge.
host
#> tunctl -d
tap0 Set 'tap0' persistent
and owned by uid 1000
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
#sleep 2
To Start the Bridge
# insert the tuntap module host #> modprobe tun
insert the bridge module host #> modprobe
bridge
insert the kqemu module host #> modprobe
kqemu major=0
To configure the
bridge : host #> ifconfig eth0
down host #> brctl addbr
br0 host #> ifconfig eth0
up host #> brctl addif
br0 eth0 host #> ifconfig br0
192.168.12.102 up ##comment## Change for your bridge
address host #> ifconfig eth0
down host #> ifconfig eth0
0.0.0.0 up host #> route add
default gw 192.168.12.100 ##comment## Change for your
gateway
To start QEMU using the network host #> qemu -m 200
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=qemu-ifup.sh
YourImage.img&
Configuring the client
Everything now happens INSIDE the virtual
machine
Put insite
/etc/network/interfaces the following lines:
auto eth0
iface eth0 inet static
address 192.168.12.102 ##comment## Change for your
bridge address netmask 255.255.255.0
gateway 192.168.12.100 ##comment## Change for your
gateway
To restart configurations virtual #> /etc/init.d/networking
restart
To solve the names put in the /etc/resolv.conf
file virtual #> cat
> /etc/resolv.conf
nameserver 192.168.12.100 ##comment## Change for
your real name server
For every day usage
If you are following this as a
step by step
tutorial, up to here it is one time only, you will need to do every
thing that
is below only once, here we will discuss the every day use, what you
need to do
daily make the thing work.
To start the virtual machine using the network host #> qemu -m 200
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=qemu-ifup.sh
YourImage.img&
If the kqemu doesn't work try host #> modprobe kqemu host #> rm -rf
/dev/kqemu host #> mknod
/dev/kqemu c 250 0 host #> /bin/chmod
666 /dev/kqemu ##comment## to make it
accessible to all users