Installing a Windows 7 KVM with virt-manager wasn't too difficult, but I thought I ought to record my procedures in case I need to do it again. (This was hosted on a Fedora 20 system, but virt-manager is much the same on any host).
Next I downloaded virtio-win-0.1-74.iso. That was the latest version when I installed. Newer ones are likely to appear in the future. You probably want to check the download directory for newer iso files:
That created a qcow2 format disk image that will look like a 50GB disk to Windows7, but be stored in the much more compact qcow2 format on my host (about 13GB when fully installed and configured). Lots of different disk formats are available, but I like to keep my image sizes down for easier backup. You can create this directly in virt-manager, but I find the interface there more confusing than just doing it manually.
Then I cranked up virt-manager and pressed the button to create a new virtual machine. I told it I was installing Windows 7. I pointed the CD to the windows7.iso file, and the disk to the windows7.img file. I checked the Customize before install option so I could fiddle with the virtual machine definition before trying to install.
In the KVM configuration, I set the Disk bus to VirtIO, I set the Performance options Cache mode to writeback. I set the display type to Spice server. I set the Video Model to QXL. I made sure an EvTouch USB Graphics Tablet was defined for use as an absolute pointing device. In the networking setup, I had to use advanced mode to set it to use my bridge device rather than the default tap device. I also set the network device model to virtio. Most everything else came up with good defaults for Windows.
I tried to add a 2nd CDROM drive to point to the virtio iso image, but in the preinstall state, I kept getting python errors about variable 'disk' not defined. So I let it start the install, killed it, then tried to edit the virtual machine once it was fully defined. At this point, I could add a 2nd CDROM. Just to be paranoid, I moved the windows7.iso image to the 2nd CD, and put the virtio-win-0.1-74.iso on the 1st CD, but set the boot order to boot from the 2nd CD (I've had other versions of windows in the past refuse to look for drivers anywhere but the 1st CD :-).
Another thing I tried was setting the CPU topology to look like a multi-core processor (which is what I have), but it turns out that the i7-4770K in my host is only 1/2 a Haswell. Some of the features qemu wants for the topology emulation don't exist, so I had to settle for a single processor Windows7 Home installation.
This configuration did indeed boot OK, and when the Windows installer said there were no disks, I was able to browse to the WIN7\AMD64 directory on the 1st CD and select the redhat virtio driver (VIOSTOR) for the disk (I'm installing 64 bit Windows7). This enabled the install to proceed directly on to the virtio disk, which I'm sure ran much faster than a fake IDE disk would run.
When selecting the driver, I always told windows not to search, I'll select the driver, no really I don't want to search, yes I have a disk, no really, I'll select the driver, etc. After much convincing, I can finally drill down to find the driver I know I want. Perhaps this is paranoid, but I've had many experiences of Windows blue screens after I let it search, then had it work perfectly when I pointed directly at the one I wanted, so I tend to never let it search.
Later, I was also able to get the network to function by pointing at the redhat virtio network driver and configure the more obscure ballon and virtio serial drivers from the same WIN7\AMD64 directory on the CD:
Right click the items with the yellow error icon in the device manager and pick the update driver option. For Ethernet Controller use the NETKVM driver. For PCI Device use the BALLOON driver. For PCI Simple Communications Controller use the VIOSER driver. (COM2 just isn't connected to anything, so it will always show an error as near as I can tell).
That gets Windows7 installed, but feeble. The next thing to do is grab spice-guest-tools-0.74.exe from the downloads on -space.org/. (Again, a newer version will be worth searching for in the future).
You run that installer inside the Windows7 virtual machine, and it installs the QXL video driver and various other bits (like the spice agent which allows cut & paste to work across the KVM and host machines). Once these guest tools are installed, you can get good quality video and sound from the virtual machine using virt-viewer or virt-manager, and you can make the screen higher resolution.
I also successfully activated Windows7 at this time, so that seemed like a good place to stop and make a copy of the KVM definition (via virsh dumpxml) and the virtual machine disk image. If it all goes wahoonie-shaped someday, I'll be able to get back to square one and start again.
Since Windows7 has been around for a while, it is now time to install updates for many hours, find that new updates are available to update the updates you just installed, and repeat the process again and again. I lost track, but I think I went through about 7 rounds of this.
I created a 12G raw format disk image (raw images have better performance than qcow2 and that is probably a good thing for swap area and cache files). I attached it to the virtual machine as a new virtio disk. I then booted Windows again and finally found the deeply hidden storage management app with many google searches and pixel hunts in the control panel. I scrolled down to the new disk, initialized it, formatted it as NTFS, and labeled it TEMP.
After many more searches, I finally found the advanced performance app in the computer properties and was able to turn on the swap space on the new TEMP drive and turn swap off on C:. Somewhere in the same vicinity, I found the environment settings and pointed TMP and TEMP to a new Temp directory I created on the TEMP disk (I did this both for the system and my user). I also went into Internet Explorer and found the cache directory setting and moved it to the TEMP disk.
Having gotten as much junk off C: as possible, I started trying to clean it up. In disk properties, I ran the cleanup disk tool to clean temp files and wot-not. I then ran it again and clicked the cleanup system files button to cleanup all the zillion restore points created while doing all the rounds of updates. Finally I ran the defrag tool to consolidate files and leave larger chunks of free space.
Now you can do a nifty trick to reduce the size of the qcow2 image: Download the SDelete tool (if it has moved, just search for Windows 7 sdelete and the right link will probably be at the top of the list) inside the Windows 7 KVM, install it somewhere convenient, and in a administrator command window run:
That will take a while (depending on the size disk you defined, on my system it took 10 or 15 minutes), and will fill all free space on the disk with zeroes. This will also expand the qcow2 disk image to the max possible size. Once that finishes, shutdown the Windows7 machine.
That will convert the qcow2 image for the virtual machine (window7.img) to a new qcow2 image (windows7-base.img). Because it is smart enough to not use space for blocks of all zeroes, the windows7-base.img file winds up much smaller (it should be about the 13G that Windows was reporting inside the virtual machine for the used space on C:).
At this point, you have two choices: You can rename the files, saving windows7.img as old-windows7.img (in case something goes wrong) and moving windows7-base.img to windows7.img. This is the simplest and you sould be able to boot the KVM again and have it run as well as it was before, but with a much more compact disk image file.
That creates a really tiny (to start with) windows7.img file that is "backed" by the windows7-base.img file. When you run the virtual machine with this image, all changes to the disk go into the windows7.img file and the windows7-base.img file retains all the original content. So any time you want to get back to the original system (to eradicate a stubborn virus perhaps), you can simply remove windows7.img and re-run the create command above to make a new clean image that will start from the base again.
After my virtualbox post I decided I would try the RHEL standard for virtualization, KVM. In this little scribble I'll be using the libvirt interface via the command line, as I don't feel that a GUI is acceptable on any server install.
Next you will need to examine some of the network configuration possibilities. There are multiple methods of getting your virtual machine on-line or on your network. Most of which are described here but for the purposes of this article I will be creating a network bridge and directly attaching the virtual machine(s) to the local network. In order for that to happen we need to create the network bridge on the host machine:
If you would like details on what the above commands do you can examine the official RedHat documentation here. My network takes advantage of DHCP, so I won't have to assign IP addresses. If your network configuration uses statically assigned IP addresses, you will have to apply those addresses to your new bridge. Please note that the last command will essentially remove the network connection you are effectively using if you are connecting remotely. You will need to either reload the network configuration at the terminal, schedule it to restart after you have finished reconfiguring the network, or restart the system to regain access.
Next we need to create a virtual drive to store our data. There are a few different formats to choose from each with their own advantages and disadvantages. You can read about them all here. For now, I'm going to take advantage of the 'qcow2' format. So let's go ahead and create our storage:
We will also have to have some media to boot from to install our operating system. I like to create a directory called /var/lib/libvirt/isos and copy my install media there, but if you do, you need to set the proper selinux context to give libvirt access. Luckily, this is not an un-common practice and a proper context is already configured you just have to restore it on your newly created directory.
e59dfda104