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 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. Other good tutorials and information sources can be found at:
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:
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-184.108.40.206.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-220.127.116.11.img seek=300 obs=1MB count=0 where 300 is new size to resize hdd.img in MB
host #> e2fsck rt_linux-18.104.22.168.img host #> qemu-img info rt_linux-22.214.171.124.img to see the new virtual size, in my case it was 286M host #> resize2fs /root/rt_linux-126.96.36.199.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 usershost #> qemu -m 200 rtmk_linux-188.8.131.52.img&
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
host #> cat > qemu-ifup.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
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