# Windows 7 pro x64 under KVM

## jserink

Hi All:

I wasted about a day and a half trying to get windows 7 pro x64 installed under kvm...much more difficult that installing XP pro.

I generally followed these links:

http://www.linux-kvm.org/page/Windows7Install

http://element.edoceo.com/howto/kvm

The second link suggested using the qcow2 format for the image and having had to increase my raw images before I wanted to use Qcow2 as well since resizing is simple. I created the image using:

qemu-img create -f qcow2 ~/VMs/Win_7_Pro.qcow2 24G

Qcow2 is interesting as it grows as required so the actual image created in disk was only a few hundred kilo bytes initially.

Here is my install script:

export SDL_VIDEO_X11_DGAMOUSE=0

export QEMU_AUDIO_DRV=alsa

kvm -boot d -drive file=/home/jserink/VMs/Win_7_Pro.qcow2,if=virtio,index=0,media=disk -drive file=/home/jserink/CDs/virtio-win-0.1-15.iso,if=ide,index=1,media=cdrom -drive file=/home/jserink/CDs/Win7X64.iso,if=ide,index=2,media=cdrom -m 4000 -smp 2 -usb -net nic,vlan=0,model=virtio,macaddr=52:54:00:00:EE:07 -net vde -localtime -no-quit -vga cirrus -name Win7 -monitor telnet:127.0.0.1:12997,server,nowait,ipv4 &

Worked fine but was very slow and right at the end when the installation was finishing, windows BSOD's inside the VM. Tried again installing on the same image, went faster as the files were already there but BSOD'd again, same spot. Tried one more time deleting the image and recreating it as above but again, BSOD, exact same spot.

Dumped the qcow2 and went for raw:

qemu-img create -f raw /opt/kvm/Win_7_Pro.img 24G

Installation script:

export SDL_VIDEO_X11_DGAMOUSE=0

export QEMU_AUDIO_DRV=alsa

kvm -boot d -drive file=/home/jserink/VMs/Win_7_Pro.img,if=virtio,index=0,media=disk -drive file=/home/jserink/CDs/virtio-win-0.1-15.iso,if=ide,index=1,media=cdrom -drive file=/home/jserink/CDs/Win7X64.iso,if=ide,index=2,media=cdrom -m 4000 -smp 2 -usb -net nic,vlan=0,model=virtio,macaddr=52:54:00:00:EE:07 -net vde -localtime -no-quit -vga cirrus -name Win7 -monitor telnet:127.0.0.1:12997,server,nowait,ipv4 &

Installed perfectly.

It appears Qcow2 is not quite up to snuff yet.

If you're installing Win 7 Pro in a VM for use under qeum-kvm, save yourself some time, use raw for your image format.

Cheers,

john

----------

## jserink

Note that the fedora/redhat virtio 64 bit drivers are NOT under the Win7 subdirtory....a trick for new players no less.

You need to go to the WinVista-AMD64 directory and you will find the 64 bit network drivers there.

Cheers,

john

----------

## HolgerB

Hi John,

 *jserink wrote:*   

> 
> 
> It appears Qcow2 is not quite up to snuff yet.
> 
> If you're installing Win 7 Pro in a VM for use under qeum-kvm, save yourself some time, use raw for your image format.
> ...

 

Unfortunately I can not comment on KVM with Qcow2 under gentoo but be aware that we run multiple KVM machines with Win7 and Win2k8 as well which are stressfree using qcow2 images as virtual harddisks.

This is on a Debian-based virtualisation solution but to my best knowledge the behaviour of KVM is pretty reproduceable if you run identical versions (Kernel, KVM modules, etc).

If you have enough space on your harddisk you could do a simple crosscheck:

Convert the raw image with installed Windows 7 to qcow2 and try if that boots.

I would have not used virtio for network drivers from the beginning. Usually I set up systems with standard drivers first and switch to virtio afterwards. Plus installing virtio drivers for newer Windows version often becomes a PITA because they require digital signing.

Edit: I just saw the the guide over at the kvm page mentions to install virtio for hdd in order to speed up installation. I would suspect them to be the source of the problem. To those who wnat to install Win7, I would start with a pretty simple and clean qemu / kvm commandline. In the end kvm does not need more than RAM, virtual HDD, CROM ISO and which device to boot. After this you can go on installing virtio drivers and such.

qcow2 is most likely not the issue of those problems (unless in combination with virtio).

HTH,

Holger

----------

## jserink

Hi Holger:

I agree with your conclusion on Virtio disk drivers. As soon as I switched back to the normal IDE driver for my main VM disk, no BSODs.

That appeared to have been the problem as am back to the virtio network drivers since switching over to outlook 2010 x64 on my Win7 VM and for 2 weeks no BSODs.

Cheers,

john

----------

## HolgerB

On thing seems strange to me: One of the Windows 7 x64 VMs I set up a while ago use also the virtio drivers for HDD access (I change to virtio after installing Win7 with IDE drivers though). This machine is used as Test server for automated tests and runs rock-solid for over 6 month now without BSOD.

Just one final note on qcow2: All the flexibiity and great features of qcow2 come with a big speed penalty. I guess both the structural overhead as well as the dynamic diskspace allocation cause serious slowdown. You will mostly experience this on VMs with much disk I/O. A good compromise of speed (static diskspace allocation) and flexibility (option to simply resize your guest filesystem) is the usage of logical volumes (LVM). You can pretty simple allocate more diskspace to a logical volume when required. We had good experiences with logical volumes when we used a Xen virtualisation server a few years back from now.

----------

## salahx

I'm running Windows (but Vista, not 7) under KVM. Its generally recommended when installing an operating system image, to do it to either a RAW image or preallocated qcow2 image (qemu-img create -f qcow2 -o preallocation filq.qcow2 size). Use fallocate may help too. Once the install is done and all the patches have been applied, and applications installed and upgraded you can shutdown the VM and "qemu-image convert"

----------

## sipingal

There is a good link(testing) to introduce the KVM IO performance improving. 

http://www.ilsistemista.net/index.php/virtualization/11-kvm-io-slowness-on-rhel-6.html?showall=1

If use QCOW2, the cache=none or cache=writeback is recommended. It gets obvious improvement. 

i.e 

```
# qemu-img convert -O qcow2 -o preallocation=metadata <original img> <new img>
```

Another thing is the option to enable kvm in the /usr/bin/kvm is not correct, "--enable-kvm" should be "-enable-kvm". 

Cut from the manpage of the qemu-img

------------------------------------------------

```
       qcow2

           QEMU image format, the most versatile format. Use it to have smaller images (useful if your filesystem does not supports

           holes, for example on Windows), optional AES encryption, zlib based compression and support of multiple VM snapshots.

           Supported options:

------------8<--------------------

               Encryption uses the AES format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum

               protection.

           "cluster_size"

               Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster sizes can improve the image file size

               whereas larger cluster sizes generally provide better performance.

           "preallocation"

               Preallocation mode (allowed values: off, metadata). An image with preallocated metadata is initially larger but can

               improve performance when the image needs to grow.
```

i.e one of my guest(** note the cache=writeback **):

 *Quote:*   

> /usr/bin/qemu-system-x86_64 -S -M pc-0.14 -cpu core2duo,+lahf_lm,+rdtscp,+aes,+popcnt,+x2apic,+sse4.2,+sse4.1,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds -enable-kvm -m 512 -smp 4,sockets=4,cores=1,threads=1 -name OL6X64 -uuid ab0183b3-94c1-2e3f-9c7d-dc3abf333565 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/OL6X64.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -drive file=/data/kvm/OL6X64.img,if=none,id=drive-virtio-disk0,format=qcow2,cache=writeback -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=18,id=hostnet0 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=08:00:27:2e:2c:04,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -device usb-tablet,id=input0 -vnc 127.0.0.1:1 -k en-us -vga cirrus -device ES1370,id=sound0,bus=pci.0,addr=0x5 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6

 

----------

