Open source virtualisation with qemu

Virtualisation is ultra-cool. For the uninitiated, virtualisation is being able to have a virtual computer running on top of a real one. It's a great way to run two operating systems at the same time, or test out the latest stuff without committing a physical machine.

There are a couple of open source virtualisation solutions, xen and qemu. I might be taking a look at xen in a future tutorial, because today, it's qemu time!

First of all, you'll need to install qemu. For most Linux distributions, that is a simple case of opening up your package management or software management tool and search for qemu and choose to install it. There's a Windows build here (note that I have not tested it though) and a very nice Mac port with a GUI here (which I have tested and is very good).

Once you've got it installed it is pretty much ready to use.

One of my favourite uses for qemu is to run live distributions of Linux and other OSes. Unlike solutions like VMware, you don't need to create a virtual hard drive (although you can, of course) to run a VM. This makes it ideal for testing out live CDs, without even burning the .iso file to disc.

To do this, open up a terminal and run the following:

$ qemu -cdrom /path/to/live/cd.iso

Obviously, replace the path in there with your live CD .iso that you downloaded.

If you do want to make a virtual hard drive however, you'll first have to make a hard drive image file, with dd.

$ dd if=/dev/zero of=myharddrive.img bs=1024k count=500

That will make a 500 MB disk image. Change the count=500 to your desired megabyte number if you want a larger one. Once you've made the image, tell qemu to use it:

$ qemu -hda myharddrive.img

So, if you want to boot your installation CD with your virtual hard drive attached, just stick those two switches together (and you'll need to add a -boot c to force it to boot from CD).

$ qemu -hda myharddrive.img -cdrom /path/to/live/cd.iso -boot c

Once the OS is installed, you don't need to mount the CD anymore and you can also lose the boot setting (the same command as I showed you before this one). Anything you save to the VM hard drive should be saved in that image file, so don't lose the image file or you will lose your VM.

Now you should have a fairly easy, completely free and very nice virtualisation solution. You can make as many different hard drive images as you have disk space, and that way you can have multiple virtual machines!

As always, there's a ton more configuration options, so take a look at the man page for more information.

Have fun!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Open source virtualisation with qemu

  1. # Posted on 11 April 2007 at 11:13 AM

    [...] few days ago, I took a look at qemu as an open source virtualisation solution. I’m also hopefully going to take a look at Xen at [...]

Home » Articles » Open source virtualisation with qemu