48 members have voted
Qemu is a free emulator for Linux, and it is powerful enough for everyday use with new features popping up with each new release.I'm not virtualizing to serve thin clients or anything fancy like that; I'm just doing the everyday hobbyist kind of emulation that one wants to do when one wants to try out the beta of an upcoming release, or when one wants to first with a distro that is not their own, or when one is doing a tutorial and needs a fresh install for pure screenshots, or whatever.Qemu at its best, IMHO, is a Command Line application. There is a GUI front-end called Qemu-Launcher. I find it unnecessary, partially because the command line options are powerful and quick enough to get your emulated host going, and partially because Qemu-Launcher doesn't seem to actually launch a host for me on my system. Not sure why -- but I'm not going to bother troubleshooting something that is redundant anyway. I find the command line interface quite enough to launch an emulated client.First thing's first: you need to install Qemu. This should be a simple su -c 'yum install' or a sudo apt-get away.
bash$ su -c 'yum install qemu'
Once that's finished, you can do a "man qemu" to see all the options that come along with qemu...or check out the qemu site for complete documentation.One of the first things I do is create a little fake harddrive for Qemu to use as its emulated harddrive. That is, if you want to actually install a distro (as opposed to just running it off of the cd) then you'll need a container file that Qemu can take over, pretend like it's a real harddrive, "format" and install onto. Since this is just a sandbox, I figure a 4gb image is quite enough:
bash$ qemu-img create -f qcow2 qEmu.qcow2 4G
Here's what we just did:qemu-img create # invokes qemu-create and tells it to create a new file-f qcow2 # the image format; qcow2 is qemu's native format; there are other choices if you're going to export this image to some other virtualizerqEmu.qcow2 # this is the name I've given my disk image...you can call yours anything you like; fedora11.qcow2 or debianSqueeze.qcow2 or whatever4G # the size of the container...give it more or less space as desiredNow, I typically use Qemu with an actual cdrom in my disc drive, because the distros I am test-driving are almost always the ones that come on the bundled disc in Linux Format or Linux Pro or Linux Identity magazines. Here's the one-liner for such an endeavour:
bash$ qemu -M pc -cpu qemu32 -cdrom /dev/cdrom -boot d -drive file=~/qEmu.qcow2
Switch by switch:qemu # invokes qemu-M pc # defines what kind of Machine you want to emulate; type -M ? to see a list of choices-cpu qemu32 # what kind of cpu to emulate; type -cpu ? for more choices. qemu32 is the one you'll probably want if you're trying out a modern OS-cdrom /dev/cdrom # this defines the location of your cdrom drive. Can be an .iso image saved on your harddrive, too!-boot d # where to boot from; the "d" option tells qemu to boot on CDROM rather than Network or Harddrive-drive file=~/qEmu.qcow2 # our qcow2 image, remember?After you issue the above command, you should see a window pop open, revealing your emulated host. First it will load its emulated BIOS and then it will boot from the actual cdrom. You can install the distro onto the harddrive image, which the emulated machine will believe is an actual harddrive (you'll know it's not your real harddrive by the size of the drive, if nothing else), or you can just run the distro as a Live distro if available.What if you didn't get a dvd with a magazine, but had just bit torrented the latest iso of a hot new release? That's quite similar; first, of course, have the iso on your harddrive. Have a qcow2 image established. And then run qemu thusly:
qemu -M pc -cpu qemu32 -no-acpi -cdrom ~/Download/F11-Preview-i686-Live/F11-Preview-i686-Live.iso -boot d -drive file=~/qEmu.qcow2
You might notice that I've added a -no-acpi flag here, simply because I've found that Fedora 11 won't boot without it. In an emulated machine, I'm not sure whether you ever really need acpi anyway, so it's probably a safe thing to turn off. Aside from that, the procedure is the same except that instead of point -cdrom to my /dev/cdrom I'm pointing it to the iso file.Some other important options you might want to define:-m 512 # allot 512mb of RAM to the emulated pc-usb # enable usb functionality in your emulated pcCheck the man page or just type "qemu" without any options for a full list of functions. There are a few video and sound and network settings that you might want to play around with.That's pretty much it. Emulation that is free and easy!