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 13:06] – 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 and building QEMU ==== | ||
+ | |||
+ | Qemu is not part of Slackware, but it is easily built from source, and [[http:// | ||
+ | |||
+ | //NOTE// Building qemu and kqemu has changed with qemu 0.8.1.\\ | ||
+ | Until qemu 0.8.0, if you want to use kqemu you need to | ||
+ | - unpack the qemu source archive | ||
+ | - change into the ' | ||
+ | - unpack the kqemu archive in this subdirectory | ||
+ | - move up one directory level to the top of the qemu source tree and run the < | ||
+ | ./configure | ||
+ | make | ||
+ | make install</ | ||
+ | - download and unpack qemu sources | ||
+ | - configure and build qemu with kqemu support (this is the default if you run '' | ||
+ | - install qemu on your computer using '' | ||
+ | - download, unpack kqemu archive | ||
+ | - configure and build kqemu, and install it on your computer using '' | ||
+ | |||
+ | ==== 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 ==== | ||
+ | |||
+ | In this section, we're going to install a Guest Operating System in QEMU. Since my guess is that many people use QEMU to run a copy of Windows on a Linux host, I will use Windows XP as an example. The hardware that QEMU emulates (see the [[# | ||
+ | The instructions and tips that are documented in this section will mostly apply to the installation of any other Operating System. | ||
+ | |||
+ | 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. So, 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 ./ | ||
+ | </ | ||
+ | qemu -localtime -m 256 -hda winxp.img -cdrom /dev/cdrom -boot d</ | ||
+ | |||
+ | 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 < | ||
+ | The installation of XP is a process that I'm not going to repeat, I am assuming you'll know how to proceed. What you need to be aware of, is that the installation of Windows 2000/XP in QEMU still has a couple of annoyances. These are:\\ | ||
+ | * Excruciatingly slow progress from time to time, especially during the stage where Windows tries to detect the hardware in your system. | ||
+ | * Errors of "disk full" half-way the install. QEMU even knows a separate commandline parameter '' | ||
+ | * Windows XP sometimes installs without a problem but at the first boot displays the following message: < | ||
+ | A problem is preventing Windows from accurately checking the | ||
+ | license for this computer. Error code: 0x800703e6.</ | ||
+ | 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. For user-mode networking, you don't need to configure anything on your host. I will probably document user-mode networking sometime later, but for now I suggest you read [[slackware: | ||
+ | |||
+ | ==== Advanced topics ==== | ||
+ | |||
+ | So far we have been through the bare minimum to get your Guest OS installed and working on your host computer and interacting with the network. Much more is possible with QEMU, and I will dedicate this chapter to the advanced topics that are most interesting or least wel-documented in other places. I will also assume you're running a recent version of QEMU. The emulator advances in great strides, and some of the features and command line switches I talk about are not available in all releases. Generally speaking, try to upgrade to the latest official release. At the point of writing, I am using 0.8.1. | ||
+ | |||
+ | |||
+ | === 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 "" | ||
+ | You can then create a QCOW file that is based on the '' | ||
+ | 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, QEMU will do all file writes to the QCOW image, thus treating the original RAW file as a // | ||
+ | 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 don't delete the QCOW file, bit instead commit the changes recorded in that file back to the base image 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 the guest OS running inside the virtual machine. | ||
+ | |||
+ | == Changing a CD/floppy in the virtual machine == | ||
+ | |||
+ | An 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 well as on the guest. In the guest, you need to run a keyboard sequence containing < | ||
+ | sendkey ctrl-alt-f6 | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Mounting a QEMU disk image on the Host === | ||
+ | |||
+ | 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 - under 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 | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Printing to the Host's CUPS server === | ||
+ | |||
+ | The Guest OS can print to a CUPS printer that you configured on the Host. No other software on the Host or the Guest is needed. The Guest' | ||
+ | |||
+ | If your Guest is Windows 2000/XP, you need to do the following: | ||
+ | - Click on "add printer" | ||
+ | - Select " | ||
+ | - Pick " | ||
+ | - Install the driver for your printer (you will need to have the driver setup program ready if it is not supported by Windows by default);\\ \\ The URL for your CUPS printer will look like < | ||
+ | http:// | ||
+ | |||
+ | If your Guest is Slackware Linux, then you need to setup the CUPS client in the Guest. I assume that you already installed the CUPS package when you installed Linux in the Guest. This is what you should do: | ||
+ | - Edit the file ''/ | ||
+ | - Make the CUPS init script executable so that CUPS will start automatically when the Guest boots: < | ||
+ | - Reboot the Guest or (re-) start CUPS: < | ||
+ | - Your Guest should now be able to use your Host CUPS printer. | ||
+ | |||
+ | <note tip> | ||
+ | In case you configured your Host's CUPS server to make it visible to other CUPS clients on your network (read my [[slackware: | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Sound support in the Guest === | ||
+ | |||
+ | QEMU has pretty good sound support. It emulates several sound hardcards. You can print a list of the emulated cards by running < | ||
+ | |||
+ | For sound output, QEMU uses SDL which in turn uses OSS. Slackware uses the ALSA sound driver which has OSS emulation support. Since version 0.8.0, QEMU can use ALSA directly for sound output, but you will have to explicitly enable this when building the sofware. Add < | ||
+ | The scripts in the final section of this Wiki page show you how to setup your environment so that you can actually hear the sound that QEMU outputs. The requirement for sound to come from your speakers is the environment variable '' | ||
+ | '' | ||
+ | |||
+ | |||
+ | === Using an USB device in QEMU === | ||
+ | |||
+ | USB devices that are connected to the host machine can be accessed directly inside the Virtual Machine. QEMU needs an aditional parameter '' | ||
+ | qemu -usb -usbdevice host:< | ||
+ | </ | ||
+ | qemu -usb < | ||
+ | </ | ||
+ | usb_add host:< | ||
+ | </ | ||
+ | |||
+ | * An example: You have a HP Scanjet 3300C connected to the USB port of your computer. The output of '' | ||
+ | # lsusb | ||
+ | Bus 003 Device 002: ID 03f0:0205 ScanJet 3300C | ||
+ | </ | ||
+ | qemu -usb -usbdevice host: | ||
+ | |||
+ | <note important> | ||
+ | The important thing to consider with using real USB devices, is that the Host must not have any driver loaded for the USB device. If your hotplug loads drivers automatically, | ||
+ | </ | ||
+ | |||
+ | === Copy/paste text between Host and Guest === | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | |||
+ | === Sharing files between Host and Guest === | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | * __IRC__: the #qemu channel on Freenode. |