Regrettably, there are some software applications that just run better on Windows, specifically, Windows XP. Of course, Windows runs better on Linux, so I guess we can still hold to our axiom that “All things run better on Linux”. 😯 Ok, not really. 😀
In my case, I would like to run the full Office 2003 suite on Linux. Using Wine is an option, but it can be a bit buggy. CrossOver is a better option, but it costs money, and I am cheapskate. Plus, it’s like “double-taxation”. I have to pay somebody a tax, so I can pay my Microsoft tax. That ain’t right! Well, I am not really a Linux purist – I am just a practical cheapskate. And, I would like to learn about OS virtualization, and apparently, so do you! Otherwise, you would not be reading this. 😉
Installing KVM on Gentoo
KVM is just one of many possible virtualization methods, which is a way to run one OS inside of another OS. (Imagine a “window” that is running Windows XP inside, and it “thinks” it is the entire computer. It does not realize that it is running inside of another “computer”.)
Note: These instruction are for:
Host: Gentoo 2008.0 RAM: >= 1.5GB Kernel: 2.6.27 KVM: v79 Guest: Windows XP Pro
Of course, there these instructions may have to be varied slightly to accommodate your exact application.
Here are my modified instructions, based on the Gentoo Wiki:
1. Update the kernel with IN-KERNEL KVM (no need for module mayhem):
$ cd /usr/src/linux $ make menuconfig [*] Virtualization ---> --- Virtualization <*> Kernel-based Virtual Machine (KVM) support <*> KVM for Intel processors support < > KVM for AMD processors support <*> PCI driver for virtio devices (EXPERIMENTAL) <*> Virtio balloon driver (EXPERIMENTAL)
If you want to be able to do networking, you should also enable VLAN bridging and tapping, while you are here:
Device Drivers ---> [*] Network device support ---> <M> Universal TUN/TAP device driver support Networking ---> Networking options ---> <*> 802.1d Ethernet Bridging <*> 802.1Q VLAN Support
Copy new kernel into place. Update grub.conf. Reboot using new kernel. … You know the drill. 🙂
2. Ensure the latest version of KVM:
$ echo 'app-emulation/kvm ~amd64' >> /etc/portage/package.keywords
3. Activate useful USE flags:
$ echo 'app-emulation/kvm gnutls sdl' >> /etc/portage/package.use
4. Check emerge for weirdness and install:
$ emerge -pvt kvm usbutils bridge-utils usermode-utilities These are the packages that would be merged, in reverse order: Calculating dependencies... done! [ebuild R ] sys-apps/usermode-utilities-20040406-r1 0 kB [ebuild R ] net-misc/bridge-utils-1.4 0 kB [ebuild R ] sys-apps/usbutils-0.73 USE="zlib -network-cron" 0 kB [ebuild R ] app-emulation/kvm-79 USE="alsa esd gnutls modules ncurses sdl -havekernel -pulseaudio -test -vde" 0 kB
Looks ok to me. Does it look ok to you? Let’s go:
emerge -pvt kvm usbutils bridge-utils usermode-utilities
5. Setup access for non-root users:
For each non-root user, add them to the KVM group:
gpasswd -a <non-root-userid> kvm
Launching Guest for First Time and Installing Windows:
First, you need to create an “image” file, which will contain the entire Windows XP guest OS (think C:\ drive). Here’s the default way:
kvm-img create winxp_raw.img 30G
This will create a RAW image format that is 30 GB in size. This is the simplest and most portable image format. However, it is not the coolest!
kvm-img create -f qcow2 winxp.img 30G
This does the same thing, but it uses the latest QEMU format, which enables additional features, like image overlays.
Second, if you use ALSA for your host’s sound, then you can enable it like so:
Third, install Windows XP into image. Here’s the simplest method:
kvm -hda winxp.img -cdrom /dev/cdrom1 -boot d
This will do the same thing but it will use a local image of the install ISO (faster?), use 1GB of RAM (default is much less), use host’s local clock (helps Windows see the right time), emulate better VGA card (more colors and resolution), and allow access to 2 processors:
kvm -hda winxp.img -cdrom /winxp/ISO/WINXPSP2.ISO -m 1024 -localtime -vga std -smp 2 -boot d
Using The Virtualized Guest Windows XP
The emulated “box” will reboot once as part of the Windows XP installation process. After it comes back up, you should be good to go! You can now download programs, install programs, update the install, etc., just like you would with a regular Windows XP installation. Of course, there will be some limitations, because the emulated hardware is not exactly feature-rich.
At some point, you will “shut down” the emulated Windows XP machine. To restart it, use the a similar command – with the exception of not booting from the install disk (or ISO):
kvm -hda winxp.img -cdrom /dev/cdrom1 -m 1024 -localtime -vga std -smp 2
Accessing Host Drives
To access a local partition, first ensure that samba is installed – not running – just installed.
Then, simply add the path to the mounted partition, like so:
kvm -hda winxp.img -cdrom /dev/cdrom1 -m 1024 -localtime -vga std -smb /path/to/dir
Otherwise, you can add the share name, if you have samba already running and properly configured, like so:
kvm -hda winxp.img -cdrom /dev/cdrom1 -m 1024 -localtime -vga std -smb <share_name>
Inside the Windows guest OS, the mounted share is available at:
Also, from inside the guest OS, you can SSH, SCP, SFTP, FTP, or telnet to the host, depending on running host services, using this IP:
Other options are listed on the Arch Linux Wiki.
I have found that this process is not entirely stable. Some combinations of host hardware, host OS, emulated hardware, and guest OS, work better than others. If I tried to emulate too much hardware, the Windows XP installation would crash, so I typically had to install using the most modest, simplest emulation.
Also, I found that this process could be slow during “boot-up” and “installation”. Maybe disabling ACPI emulation would help?
Anyway, you can quickly make a wrong turn and wreck your “virtual machine”, basically ruining your created image, in which you spent so much time setting up and installing. Fortunately, there are 2 techniques to help mitigate this annoyance.
One, with the emulator shut-down, simply copy the image file to another location or file name to back it up, like so:
cp -fp winxp.img winxp_orig_install.img
Then you can always copy the good install back over a broken install, like so:
cp -fp winxp_orig_install.img winxp.img
Ta-Da! Of course, the downside of this approach is rampant disk-usage. You need double the disk space, possibly more, depending on how many backups you make.
Another technique is using “overlays”. You can create an “overlay” of a good image like so:
kvm-img create -b winxp.img -f qcow2 winxp_20081225.ovl
Then you can boot from the overlay, just like you would any other image, like so:
kvm -hda winxp.ovl -cdrom /dev/cdrom1 -m 1024 -localtime -vga std -smp 2
The overlay contains a “diff” of the new state and the original image, so it is much smaller, since it only contains what changed. If the overlay gets corrupted, you can simply delete the overlay, create another, and go again!
You can also stack overlays, but I think this can waste diskspace too, and it requires that you keep the whole “stack” in place. Pull out one overlay in the stack, or just move it, and the whole thing tumbles down! 🙁
Based on a tip from Bryan Murdock’s blog for resizing image files, you can combine an overlay stack into a new, single, independent image file, like so:
# create a new image file, which will be the consolidated image kvm-img create -f qcow2 winxp_new.img 30G
Download the latest clone-zilla LIve-CD (or DVD) ISO.
In a KVM session, boot from the downloaded ISO, and include your original overlay as HDA and your new image as HDB, like so:
kvm -cdrom clonezilla-live-1.2.1-17.iso -hda winxp.ovl -hdb winxp_new.img -m 1024 -vga std -boot d
Generally, you should accept the defaults, unless you know what you are doing, and of course, you do. 😉 The key is to choose the option for a “device-device disk/partition to disk/partition” clone, or something to that effect. (I don’t remember the exact wording.) Make sure you copy the complete contents, including the MBR. Your source is HDA, and your target is HDB. … The cloning takes a while. After it finishes, be sure to halt, and then start up a new KVM session, using the new image file:
kvm -hda winxp_new.img -cdrom /dev/cdrom1 -m 1024 -localtime -vga std
Try hiding the original image and overlay files to see if it works. It should!
The default network setup is good for surfing the web, downloading stuff, and checking email. However, if you want other devices on your LAN to “see” the guest OS as another machine, you will have to create a bridge and tap. This gets a little more complicated. See the references below for more details.
If the installation or something crashes, try restarting the machine – but, don’t boot from the installation disk. Many times the install process completed “good enough” before crashing. 😮 Yeah, I know. It smells funny to me too, but it works. 🙄 Just be sure to keep lots of backup copies of your images or overlays.