Showing posts with label kvm. Show all posts
Showing posts with label kvm. Show all posts

Wednesday, March 2, 2011

FAST Win7 KVM VirtIO{Disk-Net} Install

Everyone who has to use Windows, please let's at least keep it contained inside a virtual machine! In this article I'll demo how to "Install Windows7 over Ubuntu 11.04 Natty, using KVM with System Disk over VirtIO". Quoting the libvirt wiki "Virtio is a Linux standard for network and disk device drivers where just the guest's device driver "knows" it is running in a virtual environment, and cooperates with the hypervisor. This enables guests to get high performance network and disk operations, and gives most of the performance benefits of paravirtualization"

Here's a little convenience script to download virtio Windows drivers and launch virt-install to Install Windows. Copy/Paste this script into an empty folder, chmod +x it, and run it.

#!/bin/sh
WINISO=/path/to/win7.iso    #Windows ISO
INSTALLDISK=win7virtio.img  #Disk location. Can be LVM LV
VFD=http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-1.1.16.vfd
DRVRISO=http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-1.1.16.iso

[ -e $(basename $VFD) ]     || wget $VFD
[ -e $(basename $DRVRISO) ] || wget $DRVRISO
[ -e $INSTALLDISK ]         || qemu-img create $INSTALLDISK 30G

sudo virt-install -c qemu:///system --virt-type kvm --name win7virtio --ram 1024 --disk path="$INSTALLDISK",bus=virtio \
--disk $(basename $VFD),device=floppy --os-variant win7 --cdrom $(basename $DRVRISO) --cdrom "$WINISO" --vcpus 2

et voila Windows installer kicks in, we're greeted with the usual

Screenshot-win7virtio - Virt Viewer
Screenshot-win7virtio - Virt Viewer-1
Next the welcome screen, and agree on the license agreement (if you want!)
Screenshot-win7virtio - Virt Viewer-2

In this next screenshot, we see how Windows Installer does not see any "disks". This is because Windows now does not have any drivers for the virtio disk that we attached!
Screenshot-win7virtio - Virt Viewer-3

Let's fix that, clicking "Load Driver" and clicking OK, Windows starts reading the VFD virtual floppy image we attached, and detects the driver
Screenshot-win7virtio - Virt Viewer-3
Screenshot-win7virtio - Virt Viewer-5
Clicking Next, Windows can now see the virtio disk
Screenshot-win7virtio - Virt Viewer-5
Then it's business like usual
Screenshot-win7virtio - Virt Viewer-7
After installation completes, be sure to check the device manager and confirm the disk (and network) are both using optimized virtio drivers
DeviceManager

et voila, Windows in its full glory running over optimized virtio drivers. The only part that sucks is desktop VNC performance, something that I'll probably write about very soon :)

Thursday, December 30, 2010

Cloud Instance with Cloud-Init on KVM

I wanted to run an Ubuntu server cloud instance locally on KVM hypervisor. I also wanted to run cloud-init on the local setup in order to experiment a bit with it. So that means, downloading a UEC image, booting it under KVM, and passing cloud-init parameters to it as it boots. Much to my surprise things were far easier than I expected, all thanks to our rocking Ubuntu cloud team. Here's the script I cobbled together, most of it is basically a rip off from this UEC Images wiki page.

So what this does is, it:
  • Downloads a UEC image of natty server daily i386 if it doesn't exist
  • Sets a few variables
  • Creates a qcow disk image, shadowing/cowing/differencing the downloaded image. This is to keep the originally downloaded image pristine
  • Downloads some sample user-data and meta-data (warning, this runs arbitrary commands and injects keys inside your VM, only use for testing!). To experiment with cloud-init you'd have to modify the user-data to your liking
  • Runs a local simple webserver (port 8000)
  • Boots the cow image in a local kvm. As it boots, you'll notice on your terminal the following two requests being made "GET /meta-data" and "GET /user-data". Cloud-init uses this data to customize the image as it boots
  • Once you close kvm, kills the web-server
So all you need to do, is create an empty directory, put this script in it and run it
uecnattyservercurrent=http://uec-images.ubuntu.com/server/natty/current/natty-server-uec-i386.tar.gz
tarball=$(basename $uecnattyservercurrent)
[ -f ${tarball} ] || wget ${uecnattyservercurrent}
contents=${tarball}.contents
tar -Sxvzf ${tarball} | tee "${contents}"
cat natty-server-uec-i386.tar.gz.contents
base=$(sed -n 's/.img$//p' "${contents}")
kernel=$(echo ${base}-vmlinuz-*)
floppy=${base}-floppy
img=${base}.img
qemu-img create -f qcow2 -b ${img} disk.img
wget http://smoser.brickies.net/ubuntu/uec-seed/meta-data
wget http://smoser.brickies.net/ubuntu/uec-seed/user-data
python -m SimpleHTTPServer &
websrvpid=$!
kvm -drive file=disk.img,if=virtio,boot=on -kernel "${kernel}" -append "ro init=/usr/lib/cloud-init/uncloud-init root=/dev/vda ds=nocloud-net;s=http://192.168.122.1:8000/ ubuntu-pass=ubuntu"
kill $websrvpid