Running Windows on Eucalyptus

This post has now been superseded.  See here for the update.

This post details how to create a Microsoft Windows image to run on a Eucalyptus instance with nodes running running KVM. In my example, I’ve created an XP image; a similar methodology can be used for Server 2003 and other NT versions.

The approach should theoretically also work on paravirtualised Xen nodes, though I haven’t tried it!

Windows XP running on Eucalyptus

Windows XP running on Eucalyptus

Create the base image

You first need to create a Windows base image using KVM.  There are already plenty of how-tos around explaining this process, so I won’t go into any detail here.  The critical part is that the install should be onto a SCSI disk image, as this is what Eucalyptus expects.

Generate the bootloader kernel

For this step, you’ll need to download and compile the memdisk component of syslinux.

Syslinux can be downloaded from http://www.kernel.org/pub/linux/utils/boot/syslinux/ .  I just grabbed the latest version.  Extract the archive, switch to the syslinux-<version>/memdisk directory, and compile memdisk using make.  You’ll need to install nasm first, as this is a dependency; to do this on Ubuntu, type:

# sudo apt-get install nasm

Make will compile a number of files into the memdisk directory – you’ll just need the one called memdisk

Create the bootloader ramdisk

This is the interesting part.  Basically, we’re going to create a Windows boot image, which will then launch the Windows virtual machine itself.

First, create a blank virtual floppy disk, using:

# dd bs=512 count=2880 if=/dev/zero of=win-boot.img

Now, attach this image as a floppy drive to the Windows VM you created above, and start the instance.  Format the disk either by right-clicking on the floppy drive icon in My Computer, or through a terminal using format a: (mkfs.msdos doesn’t work here, as the resulting file system isn’t bootable).

Finally, copy the following 4 files from the root of the windows c:\ to the floppy disk:

ntldr
ntdetect.com
boot.ini
Ntbootdd.sys

(for the above in greater depth, see: http://support.microsoft.com/kb/305595 )

Bundle the image

Create the eucalyptus bundles using the same method as for a linux image.  You’ll need the memdisk and win-boot.img files you’ve just created, together with the hard disk image file from the Windows KVM virtual machine.

The command sequence (assuming you have the EC2 tools set up correctly) should be:

mkdir kernel
ec2-bundle-image -i /path-to/memdisk -d ./kernel --kernel true
ec2-upload-bundle -b kernel -m ./kernel/memdisk.manifest.xml
EKI=`ec2-register kernel/memdisk.manifest.xml | awk '{print $2}'`
echo $EKI
mkdir ramdisk
ec2-bundle-image -i /path-to/win-boot.img -d ./ramdisk --ramdisk true
ec2-upload-bundle -b ramdisk -m ramdisk/win-boot.img.manifest.xml
ERI=`ec2-register ramdisk/win-boot.img.manifest.xml | awk '{print $2}'`
echo $ERI
mkdir image
ec2-bundle-image -i path-to/<windows_disk>.img -d ./image --kernel $EKI --ramdisk $ERI
ec2-upload-bundle -b image -m ./image/<windows_disk>.manifest.xml
EMI=`ec2-register image/<windows_disk>.manifest.xml | awk '{print $2}'`
echo $EMI

And that’s it!

Advertisements

Tags: , ,

17 Responses to “Running Windows on Eucalyptus”

  1. choc Says:

    love the article what interface are use using in pic? Thanks choc

  2. A Lorenzo Says:

    Hi,
    I have follow your instructions on how to add windows xp to eucalyptus and the xp image (which is running on standard virt-manager) is not getting an IP when instantiated. These are the errors:
    ================================
    [Wed Aug 19 00:25:37 2009][005160][EUCAINFO ] preparing images for instance i-3C650658…
    [Wed Aug 19 00:25:37 2009][005160][EUCAINFO ] adding key/tmp/sckey.W1A2IB to the root file system at /var/lib/eucalyptus/i
    nstances/admin/i-3C650658/disk using (//usr/share/eucalyptus/euca_rootwrap //usr/share/eucalyptus/add_key.pl //usr/share/eu
    calyptus/euca_mountwrap)
    [Wed Aug 19 00:25:37 2009][005160][EUCAINFO ] vrun(): [//usr/share/eucalyptus/euca_rootwrap //usr/share/eucalyptus/add_key
    .pl //usr/share/eucalyptus/euca_mountwrap 32256 /var/lib/eucalyptus/instances/admin/i-3C650658/disk /tmp/sckey.W1A2IB]
    [Wed Aug 19 00:25:37 2009][005160][EUCAERROR ] system(//usr/share/eucalyptus/euca_rootwrap //usr/share/eucalyptus/add_key.p
    l //usr/share/eucalyptus/euca_mountwrap 32256 /var/lib/eucalyptus/instances/admin/i-3C650658/disk /tmp/sckey.W1A2IB) failed
    with 256
    [Wed Aug 19 00:25:37 2009][005160][EUCAERROR ] ERROR: key injection / tune2fs command failed
    [Wed Aug 19 00:25:37 2009][005160][EUCADEBUG ] system_output(): [//usr/share/eucalyptus/euca_rootwrap //usr/share/eucalyptus/gen_kvm_libvirt_xml –ramdisk –ephemeral]
    [Wed Aug 19 00:25:37 2009][005160][EUCAINFO ] currently running/booting: i-3C650658
    [Wed Aug 19 00:25:37 2009][005160][EUCAINFO ] doDescribeResource() invoked
    [Wed Aug 19 00:25:38 2009][005160][EUCAINFO ] started VM instance i-3C650658
    [Wed Aug 19 00:25:41 2009][005160][EUCAINFO ] doDescribeResource() invoked
    [Wed Aug 19 00:25:42 2009][005160][EUCADEBUG ] no publicIp detected, trying to discover
    [Wed Aug 19 00:25:42 2009][005160][EUCADEBUG ] no privateIp detected, trying to discover
    ================================
    could you tell what’s the problem?
    Thanks!

    • ajmf Says:

      It’s a bit difficult to see from the above trace alone where the problem lies. The two failures seem to be the Eucalyptus components that a) add a public / private key, and b) add a journal to an ext2 file system; neither are relevant to a Windows install, hence their failing.

      As a quick ‘trick’ to help out: on the Eucalyptus node controller add the following line to the /usr/share/eucalyptus/gen_kvm_libvirt_xml file at the end of the devices section

      graphics type=’vnc’ port=’-1′ autoport=’yes’ listen=’127.0.0.1′

      (start and finish the line using the correct xml tags, which seem to be stripped off by wordpress. Take a look at http://libvirt.org/formatdomain.html#elementsGraphics for greater detail).

      This allows you to connect to the running virtual image console using virt-manager, which will give more debugging information. My best guess would be that something’s going wrong in the syslinux boot chain, which you should be able to see using virt-manager.

      • A Lorenzo Says:

        How can I link the virt-manager console with the ec2-run-instances? I am able to run the image OK under the virt-manager but not under eucalyptus.
        When I enter ec2-run-instances emi-xxxxxxx -k mykey -t m1.large, the status from pending to shuting down to terminate is pretty fast that I don’t have time to start virt-manager, could you tell how?
        thanks!

  3. etienneg Says:

    That’s a very clever hack with syslinux. Bonus point for solving it at the AMI creation level. Bookmarked! 🙂

    The two problems I can see preventing this technique getting into widespread use is license and user/password management. Eventually, we will need some kind of hook in Eucalyptus to change the Windows product key at boot time (and eventually, to manage licensing restrictions such as limit the number of instances that can be run), and to create a new user.

  4. EtienneG Says:

    After much, much experimentation, I was able to make it work. A couple notes:

    – You do not have to compile syslinux, it is in the software archive (it was actually installed on my 9.04 machine). On Ubuntu, memdisk is located in /usr/lib/syslinux/memdisk.

    – I used the instructions at http://support.microsoft.com/kb/325879 to create the boot disk (for Windows 2003). However, as opposed to what the article, changing “multi” for “scsi” is not required; actually, on my test system here, it would not boot if I used “scsi”. Also, the SCSI driver that you need to copy to the floppy as Ntbootdd.sys is C:\Windows\system32\drivers\sym_hi.sys.

    – Think about turning on Remote Desktop in Windows so that you can connect.

    And finally, the *critical* bit is that, when you prepare your disk image by installing Windows, you need to create more than one partition on the virtual disk. You do not have to format or do anything with the second partition you create, it just needs to be there. The reason is that Eucalyptus would otherwise try to massage the disk image for running on KVM, the partition table would get clobbered and your AMI would hang in the boot loader (but still show as “running” in ec2-describe-instances). You can read the code of /usr/share/eucalyptus/partition2disk to understand exactly what the node controller is trying to do with the AMI, and why it will leave it alone if the disk image have two partitions or more.

    Hope that was useful …

    • ajmf Says:

      Etienne,

      Many thanks for this, all useful stuff, and glad it worked for you. I hadn’t even thought to look on my own machine for memdisk – and there it is!

      I’d taken the approach of just copying the 4 files directly from the c:\ root, the logic being that the linking statements are all in place and working from the initial installation. Therefore, the contents of boot.ini (multi vs scsi and the like) should be correct, and you’re not left at the mercy of M$ technotes!

      Regarding the image preparation: at least for me, Eucalyptus didn’t harm the partition table with only a single partition defined, but the instance does log the failure of the tune2fs process. So it’s probably good practice to add more than one partition, as suggested.

      I’ll have to try to put these instructions somewhere more permanent, perhaps in the Eucalyptus section of the Ubuntu wiki. My expertise is primarily in Linux and the open source world – only dealing with Windows by necessity(!) – so am very happy for suggestions and improvements!

      Coming soon: I’ve put together a way to enable unique user creation on launch…

    • samof76 Says:

      I tried create using your suggestions. But the second install stage where it would need necessarily boot from the hd, the installation just stops saying “computer disk hardware configuration problem”. Just curious how did you people go about doing this SCSI based install.

  5. Etienne Goyer (etienneg) 's status on Saturday, 12-Sep-09 00:09:41 UTC - Identi.ca Says:

    […] Running Windows on Eucalyptus « Ajmf’s Weblog a few seconds ago from web […]

  6. Etienne Goyer (etienneg) 's status on Saturday, 12-Sep-09 00:13:22 UTC - Identi.ca Says:

    […] Running Windows on Eucalyptus « Ajmf’s Weblog a few seconds ago from web […]

  7. Running Windows on Eucalyptus (Improved) « Ajmf’s Weblog Says:

    […] By ajmf I’ve previously written about running Windows on Eucalyptus here, using a method that involved using parts of the Windows boot chain to create a Eucalyptus […]

  8. OpenQuality.ru | Eucalyptus: поднятие гостевых Windows-машин Says:

    […] например, в Ubuntu и последних версиях RHEL. В KVM создается образ Windows-машины, далее создается memdisk и ramdisk, и все три […]

  9. Barrow Kwan Says:

    How did you create the image on scsi disk image. I can’t really get the installation work. After the first pass of installation, windows reboot but it started the CD install again. If I stopped it and have it boot from C, it reported “No bootable device”. I did some research and all the results said we can’t boot qemu/kvm on scsi disk image. It has to be IDE. So i am curious how you guys install Windows in KVM on Scsi disk image. any tricks? thanks

  10. data backup storage Says:

    This is absolutely so cool!!! Thankyou for making this available!

  11. freemind Says:

    Were you able to attach volumes and take snapshots ?

  12. БaйaчaБeбe Says:

    Согласен с автором . У меня точно такое же мнение 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: