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:

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:

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

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:

# /etc/init.d/libvirt-bin stop
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

About paolog

homo technologicus cynicus
This entry was posted in Howtos. Bookmark the permalink.

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

  1. Pingback: Long Term Storage » Installing Win Server 2008 R2 as a KVM Guest with VirtIO

  2. Pingback: Install Windows Server 2008 on KVM/VirtIO - mafflog

  3. Pingback: KVM Quick Start Howto - KVM Virtualization Tutorial

  4. Pingback: Installing Windows 7 as a KVM virtualized guest on Debian - KVM Virtualization Tutorial

  5. Larry says:

    I have windows 7. But I want to setup KVM on my desktop and virtualize either RedHat or the nearest equivalent of it on my desktop (ie. would that be CentOs or Scientific Linux or Debian?)

    How can you do that? Using the KVM is part of the RHCSA exam i think (at least everyone says it is LOL) so learning how to use it is important.

    Regards.

    Larry

  6. paolog says:

    KVM is a virtualization technology that only works with Linux as host operating system; if your host operating system is Windows 7 this post is not very useful for you.

    If your objective is to run Debian or any other linux under Windows 7, then you should give a try to VirtualBox, a desktop virtualization tool that also supports Windows 7 as host. I’m pretty sure any linux can run as guest OS under VirtualBox.

    If on the other hand you want to exercise KVM, then you need to set up a linux box for that.

  7. Pingback: kvm上にWindows 7を入れました(XPからのアップグレード) | まったりとlog残し

Leave a Reply

Your email address will not be published. Required fields are marked *