« Previous 1 2 3 Next »
Virtualization with KVM
All for One
Wake-Up Call
Now that you have an image, you can launch a virtual machine directly:
qemu -hda windows.img -cdrom /dev/cdrom U -boot once=d -m 512M
Some distributions, including OpenSUSE call this program qemu-kvm
, but the parameters stay the same (see the "Double Trouble" box):
qemu-kvm -hda windows.img U -cdrom /dev/cdrom -boot once=d -m 512M
Double Trouble
Qemu is actually a genuine emulator that emulates a complete PC including a processor. To accelerate the execution of x86 programs, Qemu's inventor, Fabrice Bellard, also developed the commercial kqemu
kernel module. Shortly after the introduction of Intel-VT and AMD-V, the KVM project was launched in parallel. KVM delivered a modified version of Qemu along with its driver, which made the kqemu
module obsolete. The Qemu developers pulled the plug, first placing kqemu
under the GPL and finally dropping it entirely in favor of KVM.
As of version 0.10.0, Qemu officially supports KVM, and as of version 0.12.0, kqemu
is history. However, the KVM developers still build their own version based on the official Qemu, but they do at least keep to the same versioning scheme as Qemu. To find out which version you have on your disk, type qemu -version
. The KVM variant will report back as qemu-kvm
.
Qemu not only creates virtual machines with x86 processors, but it can also emulate PowerPC, ARM and MIPS systems – although they do not benefit from acceleration on x86 hardware. You can see the full list in the Qemu documentation [4]. Distributors tend to release these additional emulators in a separate package; on Ubuntu, the package name is qemu-kvm-extras
. openSUSE 11.3 even bundles the complete, official Qemu system into its qemu
package, which leads to curious situation where you can launch Qemu by typing either qemu-kvm
or qemu
. The first of these programs comes from the KVM project and automatically accesses KVM. With the second, you need to explicitly enable acceleration using the additional -enable-kvm
command-line parameter.@KE:
Qemu mounts the image that you created as the first hard disk (-hda) then mounts the physical CD-ROM drive (which uses a device called /dev/cdrom
in the sample). Qemu immediately boots from the CD-ROM (-boot once=d
; to boot from the first hard disk, you would need once=c
). Then Qemu opens a new window in which all the screen output from the virtual machine is displayed. If you do not want to use the physical CD drive, you can integrate an ISO image instead :
qemu -hda windows.img U -cdrom /home/tim/debian.iso U -boot once=d -m 512M
This process provides a fairly simple way to try out a new distribution without needing to waste a CD.
By default, Qemu gives virtual machines just 128MB of RAM – state of art operating systems will just laugh at this. To assign more RAM, you need the -m
parameter; the example assigns 512MB. You will need at least 1GB Windows 7. You should avoid assigning all of your physical memory resources to the virtual machines. Doing so would leave the host system and Qemu without enough air to breathe. The amount of RAM needed depends on the distribution. Ubuntu and openSUSE will need at least 512MB.
Modulo
Qemu output shows important status messages to the terminal window (Figure 4). In Figure 5, the output is complaining about a lack of support from KVM. In a case like this, you should first check whether the driver is loaded correctly. The driver comprises the kvm.ko kernel module, which provides some basic functionality to Qemu, and a processor specific module, kvm-intel.ko or kvm-amd.ko. Issuing the following command should provide your current combination:
lsmod | egrep '(kvm)'
Otherwise, the following commands will let you load the module manually:
sudo modprobe kvm sudo modprobe kvm-intel
or for an AMD model:
sudo modprobe kvm sudo modprobe kvm-amd
If this approach doesn't work, the messages in your kernel log will provide more information about the problem. The KVM FAQ [5] is also useful if you need help, and questions are answered on the KVM mailing list or the forum [6].
Grabbers
You can install the operating system in the normal way on the virtual machine. Clicking the window with the mouse captures the mouse cursor and lets you use it on the guest system. Pressing Ctrl+Alt gives the mouse back. Some Linux distributions detect Qemu and do without mouse cursor integration. You can then use Qemu like any normal application on the host system.
Besides a Cirrus CLGD 5446 PCI graphics adapter, Qemu emulates older standard hardware for which nearly any operating system will have matching drivers. However, you can't run 3D applications, especially not games.
If the desired operating system refuses to launch, you can try switching off KVM by executing qemu with the -no-kvm parameter. You can also try replacing the virtual graphics adapter with a simple model by adding a -std-vga switch. For Windows XP, you also need to disable the power saver function by adding -no-acpi.
« Previous 1 2 3 Next »