Qemu on Ubuntu

From ConShell
Jump to: navigation, search

(Updated 2007/10/29 for Gutsy)

The easy way to get and use qemu on Ubuntu is simply install the package from Synaptic. This will give you the precompiled version that runs fairly well.

aptitude install qemu kqemu-common kqemu-source

Now compile the kqemu kernel module that accelerates qemu significantly.

module-assistant auto-install kqemu
modprobe kqemu

This Ubuntu forum topic is also helpful as it shows how to ensure kqemu module loads at boot time.

Once you have qemu installed, it is time to play with some other operating systems. I chose to install CentOS 4.2 into a virtual machine, on top of which I plan to install Xen.

After downloading the CentOS-4.2-Server.iso prepare my disk (image). (Luckily I have 12G free in /home)

qemu-img create -f qcow centos-4.2-xen-3.0.img 6G
Formating 'centos-4.2-xen-3.0.img', fmt=qcow, size=6291456 kB

Then invoke qemu to fire up the VM in install mode.

qemu -cdrom CentOS-4.2.ServerCD-i386.iso -m 512 -boot d centos-4.2-xen-3.0.img

Also after booting the VM I see this output from ifconfig on my host.

> ifconfig tun0
tun0      Link encap:Ethernet  HWaddr 4A:2D:55:50:E9:20  
         inet addr:  Bcast:  Mask:
         inet6 addr: fe80::482d:55ff:fe50:e920/64 Scope:Link
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:500 
         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

This information will be helpful to configure the networking in the guest VM, which should use the following values...

  • IP Address:
  • Netmask:
  • Gateway:
  • DNS Server: (Whatever your host uses)

After installation of CentOS, shutdown and run qemu like this.

 qemu -m 512 centos-4.2-xen-3.0.img

There are a few more commands to run on the host, to get the VM fully networked.

 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 echo "1" >/proc/sys/net/ipv4/ip_forward

Now the VM should be able to reach the network and Internet.

Next step is to install Xen from the RPMs that XenSource provides for RHEL-4.1 This /should/ work on CentOS-4.2 but I will download the source RPMs and recompile just in case.

(Time passes...) It worked! I have the RPMs installed and was able to boot into the Xen kernel, run xm list and xm info. Here is the grub entry (which needed some slight modifications).

title Xen (
       root (hd0,0)
       kernel /xen-3.gz com1=115200,8n1 dom0_mem=128000
       module /vmlinuz- root=LABEL=/ ro maxcpus=1 console=tty1 console=ttyS0,115200n8
       module /initrd-