Windows – Is it possible to create an EBS AMI for windows EC2 instance

amazon ec2snapshotwindows

We have a Windows server (EBS backed) running in EC2. We make regular snapshots for data backups. I'd like to create a new EC2 instance from one of these snapshots.

Yes, I realise this is the same as yanking out the power and turning a machine on, but I want to test how reliable the data is within the snapshots for recovery purposes.

I've tried using the web console, command line tools and ruby sdk to create an AMI image from a snapshot of our Windows boot drive (EBS) – they all create an AMI that shows the platform as Linux instead of Windows and paravirtual virtualisation instead of hvm. A new EC2 instance created from this AMI fails to ever come online, I'm supposing it crashes because it's running on the wrong virtualisation platform.

Of all the googling I've done, I've only come across Linux instructions, or instructions for making a Windows EBS from an Instance backed EC2 instance – not an EBS backed one, or a snapshot.

Best Answer

Background

Launching an Instance from a Snapshot is not available for Windows AMIs (as you have meanwhile discovered yourself):

Important

Registering a snapshot works only for Linux/UNIX AMIs; although you can register a snapshot to create a Windows AMI, the AMI isn't launchable. [emphasis mine]

Alternative

While not specified, one should be aware of the possibility to simply clone an Amazon EBS-Backed Instance as outlined in Creating an Image from a Running Instance - when doing this via the AWS Management Console like so, EC2 attempts to cleanly shut down the instance before image creation and reboots the instance afterwards. This is obviously generally preferable, however, it can be avoided via the command line, if so desired:

If you prefer the instance not be rebooted, you can use the Amazon EC2 command line tools to create the image [...]. The ec2-create-image command has a --no-reboot option.

Solution

The alternative approach mentioned above obviously won't help to create a new EC2 instance from one of these snapshots as specified - a solution useful to be aware of anyway is outlined in section Moving to a New Instance of Eric Hammond's article Move a Running EBS Boot Instance to New Hardware on Amazon EC2 (which has a different use case, but applies regardless) and boils down to these steps in your case:

  1. Create a new instance with the same startup parameters as the original one.
  2. Wait until the new instance is running and then stop (not terminate) it.
  3. Detach the EBS boot volume from the new instance and delete this detached volume, as it is not required anymore.
  4. Create a new volume from the snapshot and attach it to the new instance.
  5. Restart the new instance which is now going to boot with the volume created from your snapshot.

This technique has been used by Colin Percival to enable running FreeBSD on EC2 via defenestration as well btw. (which includes some hints towards the virtualization issues):

EC2 Windows instances, on the other hand, are launched in HVM (Hardware Virtual Machine) mode — which FreeBSD supports very well. If we can somehow trick EC2 into launching FreeBSD the same way as it launches Windows, we can run FreeBSD on a wide range of instance types. How can we trick EC2? Take advantage of the fact that Elastic Block Store disks can be detached from EC2 instances and reattached to different instances, and replace the boot disk of a "Windows" instance with a disk containing FreeBSD.