Welcome to the new location of Alien's Wiki, sharing a single dokuwiki install with the SlackDocs Wiki.
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | slackware:qemu [2006/04/12 07:48] – alien | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Hardware virtualization with QEMU ===== | ||
+ | If you want to experience the kick of looking at a Windows boot screen in a desktop window while you're working in Slackware, read this article on the advancements in open source solutions for hardware virtualization - aka //running a computer inside a computer//. | ||
+ | |||
+ | ==== Virtualization in Linux ==== | ||
+ | |||
+ | One of the often cited reasons people have for not completely switching to Linux, is the fact that for some Windows applications, | ||
+ | The most prominent is the commercial [[http:// | ||
+ | |||
+ | |||
+ | ==== QEMU ==== | ||
+ | |||
+ | The new kid on the block is [[http:// | ||
+ | |||
+ | QEMU virtualizes a complete hardware environment, | ||
+ | Supported operating systems include for instance Linux and BSD distributions, | ||
+ | |||
+ | Because QEMU source code is licensed under the GPL, a third party has used it to develop an enhanced version they sell under the name [[http:// | ||
+ | The qemu PC emulator can be made a lot faster by loading a special driver which is able to accelerate the Virtual Machine on x86 hosts. This driver is implemented as a separate kernel module called //kqemu//. Qemu can use this to run the virtual machine (the //guest//) at nearly the raw speed of the host machine. The kqemu software has a proprietary license, but nevertheless, | ||
+ | |||
+ | The strengths of QEMU are that it's evolving quite fast, it is uncomplicated to setup and use, and there is no requirement to patch your kernel in order to get it running. The fact that this is free software does not relieve you of the requirement to own valid licenses of any software - like MS Windows - you want to install in QEMU. | ||
+ | |||
+ | <note warning> | ||
+ | Unlike [[http:// | ||
+ | </ | ||
+ | |||
+ | ==== Emulated hardware and supported Guest OS-es ==== | ||
+ | |||
+ | The QEMU Virtual Machine emulates a set of hardware components that is independent of the real hardware on which it is running. Since Slackware runs on x86 architecture, | ||
+ | |||
+ | * IDE-Controller supporting up to 4 drives (the drives are disk images on the host computer | ||
+ | * IDE CDROM device (in the form of a CD ISO image, or a real CDROM device) | ||
+ | * Floppy disk controller supporting up to 2 drives (floppy disk images) | ||
+ | * Graphics card (either a Cirrus Logic GD5446 PCI, or VGA-VESA) | ||
+ | * PS/2 Mouse | ||
+ | * Ethernet network card (Realtek RTL8139 PCI or NE2000 PCI) | ||
+ | * A serial port (COM 1) | ||
+ | * A parallel port (LPT 1) | ||
+ | * Soundcard (Soundblaster 16 and/or ES1370) | ||
+ | * A USB-UHCI host controller (the Intel SB82371) | ||
+ | |||
+ | The list of Operating Systems that run inside QEMU is quite long. Here is an unofficial [[http:// | ||
+ | |||
+ | |||
+ | ==== Performance ==== | ||
+ | |||
+ | Recent developments in the kqemu accelerator module bring performance of QEMU on par with the commercial VMware. However, VMware offers quite a few extra features compared to QEMU. Now that you can get certain VMware software versions for free, VMware has again become a compelling alternative (although Open Source lovers will still prefer QEMU naturally!). | ||
+ | |||
+ | You should realize that running an operating system directly on the hardware is always faster than running the same operating system inside a virtual machine, because of the processor overhead that the virtualization of all hardware dictates. Even so, the guest operating system inside the QEMU virtual machine feels suprisingly responsive if you have a decent CPU and lots of RAM. | ||
+ | |||
+ | |||
+ | ==== Obtaining QEMU software ==== | ||
+ | |||
+ | Qemu is not part of Slackware, but it is easily built from source, and [[http:// | ||
+ | |||
+ | |||
+ | ==== Running QEMU and kqemu ==== | ||
+ | |||
+ | Running QEMU is as easy as just... running '' | ||
+ | mount /dev/shm | ||
+ | modprobe kqemu | ||
+ | </ | ||
+ | |||
+ | You should prepare your Slackware system for the kqemu module so that it can operate as efficiently as possibble. Your computer will automatically have been setup in case you installed my Slackware packages from the URL I provided in the [[# | ||
+ | |||
+ | * The acceleration that kqemu offers works best if kqemu can map the Virtual Machine' | ||
+ | none / | ||
+ | </ | ||
+ | none / | ||
+ | </ | ||
+ | |||
+ | <note tip> | ||
+ | </ | ||
+ | |||
+ | * The installation of kqemu creates a device node ''/ | ||
+ | ## For 2.6 kernels, as long as udev does not re-create the ## | ||
+ | ## /dev/kqemu device node automatically, | ||
+ | ## the lines below: | ||
+ | ## ## | ||
+ | # Create the KQEMU device | ||
+ | if ! [ -e /dev/kqemu ]; then | ||
+ | mknod /dev/kqemu c 250 0 | ||
+ | chmod 666 /dev/kqemu | ||
+ | fi | ||
+ | </ | ||
+ | # kqemu | ||
+ | KERNEL=" | ||
+ | # kqemu | ||
+ | KERNEL=" | ||
+ | |||
+ | * To make the kqemu module load on boot, you should add the following line to the file ''/ | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | This concludes the alterations needed for a performance boost of your Virtual Machines inside QEMU. As I said earlier, running qemu is really simple - it is a single binary with a lot of optional commandline parameters that customize the virtual machine it will setup for use. QEMU will use the kqemu accelerator if it finds the kernel module loaded in memory (and if it's built with support for kqemu). The newer versions of QEMU and kqemu (at the time of writing, it's only available in the CVS repository of QEMU, but it will be released as QEMU 0.8.1) provide an additional layer of acceleration called // | ||
+ | qemu -kernel-kqemu <other parameters> | ||
+ | </ | ||
+ | qemu -no-kqemu <other parameters> | ||
+ | </ | ||
+ | |||
+ | <note important> | ||
+ | QEMU uses SDL for it's output (video as well as sound), and you need to run QEMU in an X Window session. There is an option to the qemu binary called '' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Installing an Operating System in QEMU ==== | ||
+ | |||
+ | Remember that QEMU builds a virtual computer around the Operating System you're going to use inside of it. So, the hard drives are virtualized as well. Before starting QEMU, we will create a big file that QEMU can then use as the virtual hard disk: < | ||
+ | dd if=/ | ||
+ | </ | ||
+ | dd if=/ | ||
+ | </ | ||
+ | |||
+ | Now, to install Windows, you need a Windows installation CD (and a valid license key of course). You have two options; if you have a " | ||
+ | |||
+ | This is the big moment... we're going to fire up QEMU and tell it to use the 4GB empty file we have just created as the virtual computer' | ||
+ | qemu -localtime -m 256 -hda winxp.img -cdrom ./ | ||
+ | </ | ||
+ | The '-boot d' parameter instructs QEMU to let the virtual machine boot from the (virtual) CD-ROM drive we've specified using //-cdrom//. The '-hda winxp.img' | ||
+ | |||
+ | When you run the above command, you'll see a new window appear, and you'll actually see the Windows XP installer boot (assuming you didn't mess up during one of the previous steps)! To use the mouse in QEMU, you need to click in the window to give it focus. QEMU grabs the mouse, and to give it back to your other applications you press < | ||
+ | Even though the slow pace of the Windows installation can make you wonder if you did the right thing installing QEMU, these annoyances will be gone once Windows installation has finished and you reboot into the OS for the first time. | ||
+ | |||
+ | When you're done with installing from CD, do not forget to at least remove the '' | ||
+ | |||
+ | |||
+ | ==== Networking your virtual machine ==== | ||
+ | |||
+ | By default, QEMU uses a feature which is called //user-mode network//. QEMU will run an internal DHCP server that can assign an IP address to the virtual computer in case that is configured to use DHCP. The network range and gateway are hard-coded into QEMU but it allows your virtual machine to call out to your host machine and beyond, if you setup your host. I will probably document user-mode networking sometime later, but for now I suggest you read [[slackware: | ||
+ | |||
+ | ==== Advanced topics ==== | ||
+ | |||
+ | === Using copy-on-write files === | ||
+ | |||
+ | QEMU uses a disk image file containing your installed Operating System. We created that image file in a previous section as a //raw// image, meaning the file has no special format. QEMU knows of several disk image formats, and one of them I want to introduce to you: the //QCOW// or "" | ||
+ | qemu-img create -b winxp.img -f qcow winxp.qcow | ||
+ | </ | ||
+ | When you tell QEMU to use the QCOW file instead of the RAW image file (something like '' | ||
+ | So, this is ideal for testing stuff out - in fact, this is how I test and build my new Slackware packages. When you're happy with the result, you can commit the changes to the base image file and get rid (if you want) of the now emptied QCOW file: < | ||
+ | qemu-img commit winxp.qcow | ||
+ | </ | ||
+ | Read the qemu-img man page if you want to know more about the supported image file formats (some support compression and encryption!). | ||
+ | |||
+ | |||
+ | === The qemu monitor === | ||
+ | |||
+ | Besides the graphical screen, QEMU has a //monitor// screen. You can toggle the QEMU output from graphics to monitor mode (after giving the window focus by clicking in it with the mouse) by pressing < | ||
+ | |||
+ | * Remove or insert removable medias images (such as CD-ROM or floppies) | ||
+ | * Freeze/ | ||
+ | * Inspect the virtual machine state without an external debugger. | ||
+ | * Send key presses to OS running inside the virtual machine. | ||
+ | |||
+ | == Changing a CD/floppy in the virtual machine == | ||
+ | |||
+ | The most interesting feature of the monitor from an end user perspective is the ability to change removable media images. Two scenarios: | ||
+ | - Suppose you want to install Slackware in QEMU. You start QEMU with something like < | ||
+ | qemu -localtime -m 256 -hda slackware.img -cdrom ./ | ||
+ | </ | ||
+ | eject -f cdrom | ||
+ | change cdrom ./ | ||
+ | </ | ||
+ | - You are running QEMU and decide you need a CDROM to install a piece of software on the currently running OS. Unfortunately, | ||
+ | eject -f cdrom | ||
+ | </ | ||
+ | change cdrom /dev/cdrom | ||
+ | </ | ||
+ | |||
+ | Switch back out of the monitor to the Guest using < | ||
+ | |||
+ | == Send key presses == | ||
+ | |||
+ | In some cases, the host OS, or the host hardware, won't let you use certain keyboard combinations. Two examples: | ||
+ | |||
+ | - You own an Apple computer. The PowerBook for instance does not have the < | ||
+ | sendkey ctrl-alt-delete | ||
+ | </ | ||
+ | |||
+ | - You're running X on the host as wellas on the guest and in the guest, want to switch to a console using < | ||
+ | sendkey ctrl-alt-f6 | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Mounting filesystems inside the virtual disk image === | ||
+ | |||
+ | On the host, you can mount filesystems created in partitions that are present in QEMU's virtual disk image - and access the files contained in there - on certain conditions: | ||
+ | |||
+ | - QEMU most **not** be running when you mount the virtual disk partitions! | ||
+ | - The disk image must have a //RAW// format. Other formats, such as QCOW for instance, can not be accessed from outside QEMU. | ||
+ | |||
+ | A QEMU disk image file will contain one or more partitions. We need to find out at what location in the file these partitions start, so that we can tell the '' | ||
+ | You must set cylinders. | ||
+ | You can do this from the extra functions menu. | ||
+ | |||
+ | Disk slack102.img: | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | |||
+ | Device Boot Start | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | The output shows a disk image consisting (apart from a swap partition) of two //Linux// partitions, which probably contain the / and /home filesystems. The first partition starts at sector 63 while the other data partition (partition #3) starts at sector 401625. These are the offsets we have to multiply with 512 (the sector byte size) to get the offset number we will feed to the '' | ||
+ | mkdir -p / | ||
+ | mount -o loop, | ||
+ | mount -o loop, | ||
+ | </ | ||
+ | Once mounted, you can copy files from and to the disk image. | ||
+ | |||
+ | <note tip> If you //do// want to be able to access your data stored in a QEMU partition, and still use QCOW for the advantages that file format offers, I suggest you create two disk image files, and use QCOW on the disk image where you will install your Guest Operating System. Create the second disk image as a RAW file, and use this to for a filesystem where you will keep your data. That way, at least the data remains accessible in the Host. | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Accessing the host parallel port === | ||
+ | |||
+ | If you need to print to a printer that is attached to the host computer' | ||
+ | qemu -parallel / | ||
+ | </ | ||
+ | cd /dev | ||
+ | ln -s lp0 parport0 | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Using an USB device in QEMU === | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | |||
+ | === The VNC patch and other user contributions === | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | |||
+ | === A QEMU start script === | ||
+ | |||
+ | For ease of use, we will create a script that will start QEMU with a lot of default options. The script will write the output into a //.log// and //.err// file and then change into a background process, so that you can just start the script | ||
+ | #!/bin/sh | ||
+ | # | ||
+ | # Start Windows XP Pro in QEMU | ||
+ | |||
+ | PARAMS=$* | ||
+ | |||
+ | # Qemu can use SDL sound instead of the default OSS | ||
+ | export QEMU_AUDIO_DRV=sdl | ||
+ | |||
+ | # Whereas SDL can play through alsa: | ||
+ | export SDL_AUDIODRIVER=alsa | ||
+ | |||
+ | # Change this to the directory where _you_ keep your QEMU images: | ||
+ | IMAGEDIR=/ | ||
+ | |||
+ | # Change this to the directory where _you_ keep your installation CDROM' | ||
+ | ISODIR=/ | ||
+ | |||
+ | # Now, change directory to your image directory | ||
+ | cd $IMAGEDIR | ||
+ | |||
+ | # If you want the WinXP CD available, use a ' | ||
+ | qemu -net user,vlan=0 -net nic,vlan=0 -m 256 -localtime -soundhw all -hda winxp.img -cdrom ${ISODIR}/ | ||
+ | </ | ||
+ | |||
+ | A script that uses [[slackware: | ||
+ | #!/bin/sh | ||
+ | # | ||
+ | # Start Windows XP Pro in QEMU using VDE for better network support | ||
+ | |||
+ | PARAMS=$* | ||
+ | |||
+ | # Qemu can use SDL sound instead of the default OSS | ||
+ | export QEMU_AUDIO_DRV=sdl | ||
+ | |||
+ | # Whereas SDL can play through alsa: | ||
+ | export SDL_AUDIODRIVER=alsa | ||
+ | |||
+ | # Change this to the directory where _you_ keep your QEMU images: | ||
+ | IMAGEDIR=/ | ||
+ | |||
+ | # Change this to the directory where _you_ keep your installation CDROM' | ||
+ | ISODIR=/ | ||
+ | |||
+ | # Now, change directory to your image directory | ||
+ | cd $IMAGEDIR | ||
+ | |||
+ | # If you want to boot from the WinXP CD add a '-boot d' parameter to the commandline; | ||
+ | # if you don't need the CDROM present in the VM, leave ' | ||
+ | # I made the MAC address up - make sure it is unique on your (virtual) network. | ||
+ | |||
+ | # This command returns to the command prompt immediately, | ||
+ | # and QEMU's error output is redirected to files. | ||
+ | vdeqemu -net vde,vlan=0 -net nic,vlan=0 -m 256 -localtime -soundhw all -hda winxp.img -cdrom ${ISODIR}/ | ||
+ | </ | ||
+ | |||
+ | ==== Further info and pointers ==== | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | * [[http:// |