Installing Windows 7 as a KVM virtualized guest on Debian 6.0 Squeeze

First check that your CPU supports hardware virtualization.

Then double ckeck that your BIOS has virtualization support enabled, should look similar to this one:

[][1]Then install kvm following this excellent tutorial (this is for Debian 5.0 Lenny but worked fine for me on 6.0 squeeze).

Triple check dmesg now for any error related to kvm:

# dmesg | grep kvm

should report nothing!

Now create the LVM logical volume:

lvcreate -L30G -n lv4 vg0

and start installing the new virtual machine:

virt-install --connect qemu:///system --arch=x86_64 -n vm4 -r 2048 --vcpus=1 --disk path=/dev/vg0/lv4 -c /mnt/Iso/win_7_professional_amd64.iso --vnc --noautoconsole --os-type windows --os-variant win7 --network=bridge:br0

In this way you’ll be using the plain IDE drivers. I don’t agree with the statement “Installing Windows 7 with IDE drivers require about 12 hours” found here: the entire process took less than 1 hour for me.

I wish I could start the installation from a virtio disk like this:

virt-install --connect qemu:///system --arch=x86_64 -n vm7 -r 2048 --vcpus=1 --disk path=/dev/vg0/lv7,device=disk,bus=virtio,boot=on -c /mnt/Iso/win_7_professional_amd64.iso --vnc --noautoconsole --os-type windows --os-variant win7 --network=bridge:br0 --disk path=/mnt/Iso/virtio-win-1.1.11-0.iso,device=cdrom,perms=ro

unfortunately virt-install does not support the kvm-specific boot=on option required, and without that, the installation stops because Windows 7 can not boot from the virtio disk.

Edit: thanks a tip by kpoorman on the IRC #virt channel, here is how to install using the (supposedly faster) virtio block device drivers for the system disk: first start the installation from a virtio disk like this (you’ll have to download the latest signed virtio drivers from RedHat here):

  virt-install --connect qemu:///system --arch=x86_64 -n vm7 -r 2048 --vcpus=1 --disk path=/dev/vg0/lv7,device=disk,bus=virtio -c /mnt/Iso/win_7_professional_amd64.iso --vnc --noautoconsole --os-type windows --os-variant win7 --network=bridge:br0 --disk path=/mnt/Iso/virtio-win-1.1.11-0.iso,device=cdrom,perms=ro

then abort (it will otherwise fail because Windows 7 can not boot from the virtio disk yet).

Now edit the xml configuration file with:

virsh -c qemu:///system edit vm7

and add the line <boot dev='hd'/> after <boot dev='cdrom'/>, in the <os> section:

<type arch='i686' machine='pc-0.12'>hvm</type>
<boot dev='cdrom'/>
<boot dev='hd'/>

Now exit the virsh edit session, reboot the machine with virt-manager or virsh, and enter the Windows 7 installation procedure – you’ll see that W7 won’t find any hard drive to install on:

So click on the “Browse for drivers” button at the bottom left, and browse to E:\viostor\Win7\amd64 if you are installing the 64-bit version or E:\viostor\Win7\x86 of you are installing the 32-bit one (the E: drive is the 2nd CD-ROM we attached with the –disk path=/mnt/Iso/virtio-win-1.1.11-0.iso,device=cdrom,perms=ro part of the virt-install command above):

after the scan is completed, you should see your drive and proceed.

More about the actual performance improvement later…

NOTE 1: this is tested on Debian 6.0 squeeze, so libvirt 0.8.3 and kvm 0.12.5.

NOTE 2: It can happen that virt-manager screws up things, in these cases stop all virtual machines using the text-based console virsh then (actually you dont’need to stop all virtual machines because they survive a libvirtd restart) stop, wipe and restart the libvirtd service:

Stopping libvirt management daemon: libvirtd.
# ps aux | grep virt
root      1809  0.1  0.0 268704 10496 ?        Sl   10:03   0:12 /usr/sbin/libvirtd -d
root      2030  0.0  0.0  10588  1372 ?        Ss   10:08   0:00 bash -c nc -q 2>&1 | grep -q 'requires an argument';if [ $? -eq 0 ] ; then   CMD='-q 0';else   CMD='';fi;nc $CMD -U /var/run/libvirt/libvirt-sock
root      2033  0.0  0.0   9412   560 ?        S    10:08   0:01 nc -q 0 -U /var/run/libvirt/libvirt-sock
# kill -9 1809
# /etc/init.d/libvirt-bin start```