Virtualize your operating system with qemu

August 2nd, 2008 mysurface Posted in qemu, qemu-img, vmware | Hits: 116548 | 7 Comments »

QEMU is a processor emulator, it allows you to run variety of unmodified guest operating systems such as Linux, Windows, Solaris, Dos etc just like Vmware and VirtualBox. In fact VirtualBox dynamic recompiler are based on QEMU. QEMU supports emulating several hardware platforms, including x86, AMD64, Alpha, MIPS, ARM, PPC, SPARC etc.

QEMU comes with command line interface, where you pass your configurations by parameters, but there are 3rd party GUI front end, such as Qemulator and Qemu-Launcher. To improves the performance of QEMU, we needs either KQEMU kernel module or KVM. Both of them are accelerator that to increase the execution speed of QEMU.

In this post, I covers installation of QEMU as well as KQEMU. As well as simple example of the use of QEMU command lines, how to create image files that allows to execute by both QEMU as well as Vmware.

Installation
I believes that you may download QEMU from your repository, which it may already comes with kqemu. You may also manually compile both qemu and kqemu. My Linux distro repository contains older version of qemu, therefore I choose to compile qemu and kqemu myself.

You can download both qemu and kqemu from http://bellard.org/qemu/download.html.

Compilation and Installation for qemu and kqemu are straight forward. You just need to do the steps below:
1. untar the archive.

2. compile

./configure
make

3. install using root permission

make install

kqemu is a kernel object, it may not auto reboot every time you reboot your machines, check out the kqemu installation for Linux HERE.

To manually load kqemu, do this in root:

mknod /dev/kqemu c 250 0
chmod 666 /dev/kqemu
/sbin/modprobe kqemu

Boot up live cd using QEMU
To check out the Live CD iso without have to burn it to CD, i usually use qemu. For this I really appreciate the flexibility of command line interface, without much clicks here and there, I boot up my Live CD with a single line of command.

For this illustration, I choose Myrinix. Myrinix is a multi purpose Portable Linux based on Debian SID. it can be in Live CD format ,USB drive as well as install in windows xp ntfs partition without modify the Master Boot Record (MBR). Myrinix also supply a series of application module that can be easily added later. You may download the latest Myrinix Live CD iso from HERE.

Lets boot up the Live CD ISO now!

qemu -cdrom myrinix-kde-200808.iso -m 512 -boot d

Short and simple! Specified your iso file path at -cdrom, in case you want to load up the Live CD from the physical CD, you may change to -cdrom /dev/cdrom ( depends on your cdrom dev). -m 512 is to force qemu to use 512Mb on RAM, by default qemu uses only 128Mb. At last -boot d option indicates that I want qemu to boot up from cdrom.

Verify kqemu is loaded
During loading the Live CD, you can verify whether kqemu is it loaded and in use. Press Ctrl+Alt 2, and type:

info kqemu
kqemu support: enabled for user mode

As long as I see the positive message, kqemu is successfully loaded and in used. Press Ctrl+Alt 1 to goes back the emulator screen.

Connects to the Internet in guest OS
By default, qemu will act as dhcp server and support internet sharing from your Host machine. Therefore as long as my host have internet access, my guest OS in qemu may have internet access too.

Myrinix does not acquire IP from DHCP by default, I think a lots of Linux Live CD doesn’t do that too. Therefore I have to do it manually. Login to root and run dhclient on eth0.

su -
dhclient eth0

Connects to Host Machines
I can obtain virtual IP for internet sharing from 10.0.2.2 by default, the same way I may also connect to my host machine by this IP.

ssh mysurface@10.0.2.2

If my guest Linux have KDE installed, I may use fish in Konqueror for file transferring from my host machine to my current guest Linux. Check out how to do that at HERE.

Qemu provides more options, just type qemu, you will get a full list of options it support, check out the user document for more details information.

Install a guest OS
To install a guest OS using qemu, first thing I need to do is to create an image file using qemu-img. qemu-img support various of file format including vmdk. qemu support loading vmdk image files. Vmware image file is in vmdk format. Bare in mind, load up vmdk files created by vmware at YOUR OWN RISK. (I have a bad experience on loading up Red Hat ES4 vmdk created by vmware server, which it fails to boot up X after booting it up by qemu. My guess is both qemu and vmware emulates different set of hardware drivers. Well, at last I manage to fix it by reinstall vmware tools in Red Hat ES4.)

To create a 10G disk image in vmdk format using qemu-img like this: (Don’t worry, 10G disk image do not actually eats 10G of your physical Hard disk space)

qemu-img create -f vmdk myos.vmdk 10G

Now I may load up your installer CD with disk image with qemu like this:

qemu -hda myos.vmdk -cdrom myrinix-kde-200808.iso -m 512 -boot d

After I have done the installation, I will boot up my guest OS from disk image like this:
( You may want to point your cdrom to physical cdrom as well as enable USB.)

qemu -hda myos.vmdk -cdrom /dev/cdrom -m 512 -usb -boot c

qemu-img allows me to convert disk image too, in case I have downloaded image disk from somewhere, I can convert it to vmdk like this:

qemu-img convert -f qcow freebsd.qcow -O freebsd.vmdk

To load up image disk with vmware, I need another file, with extension of .vmx. Vmx file is a text file that contains configuration for your disk image. To generate one using http://www.easyvmx.com/. Remember to point your disk image to ide0:0.filename in vmx, for example my case:

ide0:0.fileName = "freebsd.vmdk"

Performance
It seems even with kqemu, qemu performance in terms of execution speed is still slower than vmware. I compare the same disk image in both vmware server as well as qemu. It will be obvious when I access the GUI menu in my guest OS.

There are still a lots of options and tips I fails to covers here, in case you have any tips, please feel no hesitate to leave me comments.

7 Responses to “Virtualize your operating system with qemu”

  1. What is the performance difference of QEMU and virtualbox? Have you tried ?

  2. @farimi, Not yet, I haven’t install virtualbox.

  3. I have been using both QEMU and VirtualBox, and have found VirtualBox to be 3-5x as fast on nearly every task. QEMU seems far less mature, polished, more a project than a product. VirtualBox is quite mature, it’s now my default (and way cheaper than VMWare).

  4. After starting with this:

    qemu.exe -L . -m 512 -boot d -hda harddisk.img -cdrom slackware-10.0-install-d1.iso

    for qemu-0.9.1-windows I had to use this to change the cdrom disk image and install slackware:

    (qemu) change + TAB – to see the list of devices
    (qemu) change ide1-cd0 d2.iso (I renamed the disk image for the second disk)

    VirtualBox is great, but is free only for personal/educational purposes/evaluation. So if you are in a company and want to install some free os in a virtual environment, qemu is definitely the choice. It doesn’t have to work fast and have a great interface, it only has to work.

    Thanks

  5. Wrong! VirtualBox is GPL!
    VirtualBox is GPL since 2007.
    If you are interested in using VirtualBox — either for private or business use –, you have the choice between two versions:
    The full VirtualBox package is available in binary (executable)… for personal use and evaluation under the terms of the VirtualBox Personal Use and Evaluation License.

    The VirtualBox Open Source Edition (OSE) is the one that has been released under the GPL and comes with complete source code. It is functionally equivalent to the full VirtualBox package, except for a few features that primarily target enterprise customers. This gives us a chance to generate revenue to fund further development of VirtualBox.
    http://www.virtualbox.org/wiki/Editions

  6. This information was very sucky.

  7. VirtualBox was (in part) a rework of the qemu source code, at least at the beginning. As you can see, the licensing is pretty obscure right now, OSE? GPL? *Binary only* versions???
    Weird.

    The best solution today IMHO is kvm, and it comes with a lot of features.

    I recently discovered a very cool GUI to run Qemus or kvm:
    http://virtualbricks.eu/

    It is the successor of q-emulator.

Leave a Reply