How to download private ubuntu AWS EC2 AMI for local use

We have a large number of ubuntu servers currently hosted on AWS EC2. Many of these servers are accessed infrequently and for cost-saving we now want to move these over to our local site and terminate them on Amazon.

Most of the servers are EBS-backed and we have created AMI images of these using the Management Console.

I was hoping to download the existing AMI's and then use these images to build the new servers locally so that we don't have to re-install the application stack and configurations from scratch. 1) Is this possible? 2) How would one go about downloading this AMI? (I was hoping that it would be possible from the management console somehow.) 3) How would the AMI need to be changed so that it can be used for installation?

How can I run the Ubuntu EC2 AMI images locally? seems to suggest an answer, but the article that it links to contains important links that are no longer accessible. It also seems to suggest a rather elaborate process.

https://forums.aws.amazon.com/message.jspa?messageID=204881 seems to suggest that it is possible to do this, but doesn't go into any explanation of how to actually download the image while https://stackoverflow.com/questions/5145286/boot-ec2-ebs-volume-locally suggests that it is not possible.


Solution 1:

From what I've found in researching bits and pieces, it's not easy to do.

To get the image, you can take a snapshot, and mount it to a running instance then just copy down the contents to a local raw file with something like dd over ssh. Then disconnect the volume from the instance, verify you have the image locally stored, and delete the EBS block. That part isn't too difficult if you know how to use DD/compression/ssh to transfer the image and mount it as a local loopback to examine the raw disk image. Tutorials are available for that.

The hard part is getting it to boot. Depending on how your instance was created, it seems that the kernels are usually stripped down Xen kernels, so they may lack hardware support for something like VMWare. You'd have to mount the disk image and install a more generic kernel along with modifying the boot manager. You also would have to iron out the networking, as Amazon had some tweaks put in for handling their virtual network management (DHCP assignments, firewall, routing).

This must be possible; there are tools and tutorials for uploading your own AMI's into the Amazon cloud, just there isn't too much out there on how to go the other way. By the time you're done figuring out how to unravel the spaghetti of configuration hassles you might be better off just getting a list of dependencies for your applications and transferring the configurations and installing dependencies as a new local machine.

Bottom line...it's probably possible, it's possible to go the other way in the conversion, but with the hassle involved unless you're skilled at Linux surgery on the kernel and configuration you might as well use your EC2 instances as a template for rebuilding from the bottom up.