Table of Contents
This page presents: <o:p></o:p> 1 QuemuSetup#Introduction_and_Disclaimer_][Introduction<o:p></o:p> 1 QuemuSetup#Installation][Installation <o:p></o:p> 1 QuemuSetup#Disk_Images][Disk images <o:p></o:p> 1 QuemuSetup#NewImage][New image <o:p></o:p> 1 QuemuSetup#ResizeImage][Resize created images <o:p></o:p> 1 QuemuSetup#Network_Configuration][Network configuration <o:p></o:p> 1 QuemuSetup#Configuring_the_client_][Client configuration <o:p></o:p> 1 QuemuSetup#For_every_day_use][Every day use <o:p></o:p> ---++++ Introduction <o:p></o:p>
Qemu is a virtualization tool that started, and is maintained by [[http://en.wikipedia.org/wiki/Fabrice_Bellard][Fabrice Bellard]], the main pages are http://fabrice.bellard.free.fr/qemu/][QEMU, http://fabrice.bellard.free.fr/qemu/kqemu-doc.html][KQEMU and http://kvm.qumranet.com/kvmwiki][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. <o:p></o:p>
What we will discuss here is 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. <o:p></o:p>
Other good tutorials and information sources can be found at:<o:p></o:p> * http://www.debian-administration.org/articles/545][Using kvm, or kqemu, to speed up qemu <o:p></o:p> * <o:p></o:p> * <o:p></o:p> * http://wiki.freaks-unidos.net/qemu-debian][QEMU Debian <o:p></o:p> * http://qemu-forum.ipi.fi/][QEMU forum <o:p></o:p> * http://ubuntuforums.org/][Ubuntu forums <o:p></o:p>
<o:p> </o:p>
Conventions: <o:p></o:p>
- host #>: denotes commands executed in the real machine, the host machine <o:p></o:p>
- virtual #>: denotes commands executed in the virtual machine, the exemplified one <o:p></o:p> ---++++ Installation<o:p></o:p>
- 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:
host #> sudo aptitude update
host #> sudo aptitude install kqemu-common kqemu-source
host #> sudo aptitude install module-assistant
host #> sudo m-a prepare
host #> sudo m-a build kqemu
host #> sudo m-a install kqemu
host #> sudo aptitude install qemu
host #> depmod -a
host #> modprobe kqemu
To see if every thing it is OK
host #> /sbin/lsmod|grep kqemu ##Comment## The kqemu should appear here. <o:p></o:p> ---++++ Disk Images<o:p></o:p> - 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. <o:p></o:p>
- To create a new image
host #> qemu-img create -f raw rtmk_linux-2.6.16.49.img 3G <o:p></o:p> - Let me say you do have an 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 <o:p></o:p> - 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 ;) <o:p></o:p> - To resize the image IF needed <o:p></o:p>
- Ok you already have an image but it is start to get really small, to resize it: <o:p></o:p>
- 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 <o:p></o:p>
- The image people let at the QEMU website is small, only 20MB, if I recall well, let me say we need to resize it
- To Use with the image <o:p></o:p>
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&<o:p></o:p> ---++++ Network Configuration<o:p></o:p>
- 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. <o:p></o:p>
host #> tunctl -d tap0 Set 'tap0' persistent and owned by uid 1000<o:p></o:p>
<o:p> </o:p>
- To configure the nat <o:p></o:p>
host #> iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE host #> echo 1 > /proc/sys/net/ipv4/ip_forward<o:p></o:p>
<o:p> </o:p>
- Create a file, for example qemu-ifup.sh <o:p></o:p>
host #> cat > qemu-ifup.sh<o:p></o:p>
#!/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<o:p></o:p>
- To Start the Bridge <o:p></o:p>
-
insert the tuntap module
host #> modprobe tun <o:p></o:p> - insert the bridge module
host #> modprobe bridge <o:p></o:p> - insert the kqemu module
host #> modprobe kqemu major=0 <o:p></o:p> - 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 <o:p></o:p> - 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& <o:p></o:p> ---++++ Configuring the client <o:p></o:p> - Everything now happens INSIDE the virtual machine <o:p></o:p>
- 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 <o:p></o:p> - To restart configurations
virtual #> /etc/init.d/networking restart <o:p></o:p> - 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 <o:p></o:p> ---++++ For every day usage<o:p></o:p>
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.<o:p></o:p>
- 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& <o:p></o:p> - 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 <o:p></o:p>
<o:p> </o:p>-- User.DanielCamara - 21 Dec 2007 ---+++ ---+++