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/07 08:42] – 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, | ||
+ | |||
+ | 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:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Performance ==== | ||
+ | |||
+ | Recent developments in the kqemu module bring performance of QEMU on par with the commercial VMware. VMware offers quite a few extra features compared to QEMU however, and 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 of course!). | ||
+ | |||
+ | Running an operating system directly on the hardware will of course always be faster than running the same operating system inside a virtual machine, because of the processor overhead that 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. | ||
+ | |||
+ | |||
+ | ==== Installing QEMU ==== | ||
+ | |||
+ | Qemu is not part of Slackware, but it is easily built from source, and [[http:// | ||
+ | The qemu virtualizer has two parts: the //qemu// program(s) which is under the GPL license, and a separate kernel module called // | ||
+ | If you installed my kqemu package, several files in ''/ | ||
+ | mount /dev/shm | ||
+ | modprobe kqemu | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Getting your PC ready to run QEMU and kqemu ==== | ||
+ | |||
+ | 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 kqemu module works most efficiently when you follow these instructions (this will automatically be setup for you in case you install my Slackware packages from the URL I provided in the [[# | ||
+ | |||
+ | * Add this line to ''/ | ||
+ | none / | ||
+ | </ | ||
+ | none / | ||
+ | </ | ||
+ | |||
+ | <note tip> | ||
+ | </ | ||
+ | |||
+ | * The installation of kqemu creates a device node ''/ | ||
+ | A couple of lines are added to your ''/ | ||
+ | |||
+ | <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 '' | ||
+ | </ | ||
+ | Now that the necessary conditions are met, we will proceed to the next section where we install a real Operating System in QEMU! Well.... " | ||
+ | |||
+ | |||
+ | ==== 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 | ||
+ | </ | ||
+ | |||
+ | == 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. | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Running with ' | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | === 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:// |