Welcome to the new location of Alien's Wiki, sharing a single dokuwiki install with the SlackDocs Wiki.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
slackware:qemu [2006/04/12 07:48] – alien | slackware:qemu [2007/11/16 09:10] – Conform to current udev syntax: change KERNEL="kqemu" to KERNEL=="kqemu" alien | ||
---|---|---|---|
Line 49: | Line 49: | ||
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. | 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 | |
- | ==== Obtaining QEMU software | + | |
Qemu is not part of Slackware, but it is easily built from source, and [[http:// | 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 '' | ||
Line 85: | Line 99: | ||
</ | </ | ||
# kqemu | # kqemu | ||
- | KERNEL=" | + | KERNEL==" |
# kqemu | # kqemu | ||
- | KERNEL=" | + | KERNEL==" |
+ | </ | ||
* To make the kqemu module load on boot, you should add the following line to the file ''/ | * To make the kqemu module load on boot, you should add the following line to the file ''/ | ||
Line 93: | Line 108: | ||
</ | </ | ||
- | 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 // | + | 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 -kernel-kqemu <other parameters> | ||
- | </ | + | </ |
qemu -no-kqemu <other parameters> | qemu -no-kqemu <other parameters> | ||
</ | </ | ||
Line 106: | Line 121: | ||
==== Installing an Operating System in QEMU ==== | ==== 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 | + | 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 | ||
dd if=/ | dd if=/ | ||
</ | </ | ||
Line 116: | Line 134: | ||
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' | 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 ./ | ||
- | </ | + | </ |
- | 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' | + | 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 < | + | 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. | ||
+ | * Excruciatingly | ||
+ | * 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. | 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 '' | + | When you're done with installing from CD, do not forget to at least remove the '' |
==== Networking your virtual machine ==== | ==== 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, | + | 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 ==== | ==== 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 === | === 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 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 | 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 '' | + | 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 can commit the changes to the base image file and get rid (if you want) of the now emptied QCOW file: < | + | 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 |
qemu-img commit winxp.qcow | 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!). | Read the qemu-img man page if you want to know more about the supported image file formats (some support compression and encryption!). | ||
Line 150: | Line 178: | ||
* Freeze/ | * Freeze/ | ||
* Inspect the virtual machine state without an external debugger. | * Inspect the virtual machine state without an external debugger. | ||
- | * Send key presses to OS running inside the virtual machine. | + | * Send key presses to the guest OS running inside the virtual machine. |
== Changing a CD/floppy in 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: | + | 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 < | - Suppose you want to install Slackware in QEMU. You start QEMU with something like < | ||
qemu -localtime -m 256 -hda slackware.img -cdrom ./ | qemu -localtime -m 256 -hda slackware.img -cdrom ./ | ||
Line 177: | Line 205: | ||
</ | </ | ||
- | - You're running X on the host as wellas | + | - You're running X on the host as well as on the guest. In the guest, |
sendkey ctrl-alt-f6 | sendkey ctrl-alt-f6 | ||
- | </ | + | </ |
- | === Mounting | + | === Mounting |
- | 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: | + | 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! | - QEMU most **not** be running when you mount the virtual disk partitions! | ||
Line 221: | Line 249: | ||
ln -s lp0 parport0 | 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 === | === 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, | ||
+ | </ | ||
+ | |||
+ | === PXE booting your QEMU virtual machine === | ||
+ | |||
+ | In [[: | ||
+ | Yet there are times when you'd want your QEMU virtual machine were able to use PXE to boot from the network, if only to test your network setup without sacrificing real hardware. There is only one problem, the emulated QEMU network card (Realtek 8029, a NE2000 clone) does not support booting from the network (it does not emulate a boot ROM). | ||
+ | |||
+ | There are two ways to overcome this problem. | ||
+ | |||
+ | * The first is to use the [[http:// | ||
+ | * Select //latest production release// | ||
+ | * Choose NIC/ROM type **ns8390: | ||
+ | * Choose ROM output format **ISO bootable image without legacy floppy emulation (.iso)** | ||
+ | * To generate and download a ROM image press: < | ||
+ | * Save the generated ISO file on your local hard disk (for instance as // | ||
+ | qemu -cdrom qemu_pxeboot.iso -boot d <other options> | ||
+ | </ | ||
+ | |||
+ | * The other option you have is available since QEMU 0.9.0 and that is to use the //'' | ||
+ | * / | ||
+ | * / | ||
+ | * / | ||
+ | qemu -localtime -m 256 -hda slackware.img -boot n -option-rom / | ||
+ | |||
+ | |||
+ | <note tip> | ||
+ | If you read the [[slackware: | ||
+ | DNSMASQ_OPTIONS=" | ||
+ | * QEMU sees your //host// as having the IP Address '' | ||
+ | * Your //host// has a TFTP server setup so that ''/ | ||
+ | </ | ||
+ | |||
+ | <note tip> | ||
+ | If your TFTP server is not installed on the //host// but somewhere on the " | ||
+ | Actually, there is no problem if you are using VDE for the network support. The '' | ||
+ | We need a some extra work on the iptables firewall here, to let the TFTP traffic pass along. Add the following commands to the '' | ||
+ | modprobe ipt_state | ||
+ | modprobe ipt_helper | ||
+ | modprobe ip_conntrack_tftp | ||
+ | modprobe ip_nat_tftp | ||
+ | iptables -A INPUT -m helper --helper tftp -j ACCEPT | ||
+ | iptables -A OUTPUT -m helper --helper tftp -j ACCEPT | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Copy/paste text between Host and Guest === | ||
FIXME | FIXME | ||
- | === The VNC patch and other user contributions | + | === Sharing files between Host and Guest === |
FIXME | FIXME | ||
- | === A QEMU start script === | + | '' |
+ | |||
+ | ==== 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 | 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 | ||
Line 244: | Line 369: | ||
# Qemu can use SDL sound instead of the default OSS | # Qemu can use SDL sound instead of the default OSS | ||
export QEMU_AUDIO_DRV=sdl | export QEMU_AUDIO_DRV=sdl | ||
+ | |||
# Whereas SDL can play through alsa: | # Whereas SDL can play through alsa: | ||
Line 295: | Line 421: | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | * [[http:// | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | * __IRC__: the #qemu channel on Freenode. |