Creating a new EC2 AMI from within VMware (英文)

Creating a new EC2 AMI from within VMware or from VMDK files

I've used VMware for many years to allow me to test and develop various server configurations and distributions. It's where I played with Linux-VServer, User Mode Linux (UML), Kernel Based Virtual Machine (KVM) and Xen. The relevent part to EC2 here is obviously that EC2 is also Xen based.

So far when using EC2 I've stood on the shoulders of giants and taken existing AMIs and used them as they are or with modification. Always the control freak, I wanted to create my own AMI from scratch. Having slimmed down my hardware inventory (I got complaints about the various half built towers lying around!) then my only option was to either create an image in a loopback device on EC2 or return to my trusty steed of VMware.

Creating the AMI from VMware was easier than I thought - but just in case anyone else is looking to do it then I thought it worthy of a blog post.

There are two options for migration - one is to create the image from within the running VMware machine, the other is to convert the VMDK file into a RAW image.

I plan to create some base 'clean' images from which I can then create specific appliances - for example a base Centos i386 and x64 install which I will then layer additional software on to create specific appliance images.

My preferred method is to create the AMI from within the running VMware machine - the resulting AMI is much smaller in size (as I think that during conversion of a VMDK the resulting RAW image is the size of the volume rather than the data - although you can probably override this with options). I've given instructions for both methods so you can make your own mind up.

Converting VMDK files for use on EC2

Create your machine in VMware as usual and when ready shut it down. Then, grab yourself a copy of QEMUas we need to use it to convert the VMDK files.

Basic usage is:

qemu-img convert -O raw input.vmdk output.raw

The VMDK file will then be converted into a RAW file - we've specified the output format with the -O tag andqemu-img is intelligent enough to figure out the input format.

Your image may span several VMDKs in which case you'll need to run a simple shell loop, for example:

for file in `ls *[0-9].vmdk`; do qemu-img convert -O raw $file $file.rawdonecat *.raw >> output.raw

Depending on the number of files you have for your VMware image you might need to modify the ls - my example is purely by way of demonstration.

Either way, you should now have your VMware disk image in RAW format in the file output.raw. Given this is a RAW image it should also be bootable by a local Xen, QEMU or KVM installation.

The next step is to bundle this into an AMI using ec2-bundle-image:

ec2-bundle-image -i output.raw -r x86_64 -c ~/.amazon/cert.pem -k ~/.amazon/pk.pem --user <user id>

The exact values for the -c, -k and --user parameters will depend on the location of your certificate, private key and Amazon AWS account number respectively.

You might also want to look closely at the documentation for the --block-device-mapping parameter to ensure you get a bootable machine with a valid fstab.

After the image has finished bundling it will (by default) be in your /tmp directory, so the next step is to upload it to an S3 bucket:

ec2-upload-bundle -b <bucket name> -m /tmp/image.manifest.xml -a <access id> -s <secret access id>

With the bundled image in S3 (it will take a while depending on your connection) then you can register the image:

ec2-register <bucket name>/image.manifest.xml

The AMI should then appear when you request a list of your images:

ec2-describe-images

The only remaining thing then is to start up an instance and give it a try!

Creating the EC2 AMI from within VMware

As mentioned, creating the AMI in this way seems to result in a smaller file - I prefer it as it's also quicker to complete as you don't need to convert and create bundle - you can just create the bundle.

You'll need to boot your VMware machine and make sure you have the pre-requisites installed to run the EC2 and AMI tools - i.e. ruby, java > 1.5, etc.

For CentOS I needed to disable the MAC address being specified for my Ethernet device by commenting out the HWADDRESS line of the network script.

Check the amount of disk space you're using - for me it was 1.2Gb for my basic Centos 5.2 install.

You're then ready to bundle your volume, making sure you specify a size big enough to fit your volumes into along with any software you might want to install in future:

ec2-bundle-vol -c ~/.amazon/cert.pem -k ~/.amazon/pk.pem --user <user id> -d /image -e /image -r x86_64 -s 4096 --no-inherit

Depending on your install you may also need to specify an alternative fstab to use via the --fstab option. The-s parameter specifies the size - 4Gb in this example - you can set this up to 10Gb which is the current limit imposed by EC2. The --no-inherit parameter is required because we're not bundling from within an EC2 instance.

After the image has finished bundling it will be in your /image directory (because we specified this in our command) - so the next step is to upload it to an S3 bucket:

ec2-upload-bundle -b <bucket name> -m /image/image.manifest.xml -a <access id> -s <secret access id>

With the bundled image in S3 (it will take a while depending on your connection) then you can register the image:

ec2-register <bucket name>/image.manifest.xml

The AMI should then appear when you request a list of your images:

ec2-describe-images

You can then launch an instance using your new AMI (the AMI id will have been provided on completion of the registration, or from the output of the describe command).

时间: 2024-08-19 07:01:52

Creating a new EC2 AMI from within VMware (英文)的相关文章

亚马逊EC2可直接导入VMware虚拟机镜像

亚马逊网络服务(AWS)周五表示,将提供一个新的VMware管理平台插件,方便IT人员将虚拟机镜像转移到AWS云应用中. 亚马逊EC2 VM Import Connector是为VMware vCenter Server提供的一个专用插件.该插件基于亚马逊在去年推出的VMImport,它允许IT人员将现有VMware环境下的虚拟机镜像转移到亚马逊Elastic Compute Cloud(EC2)中.亚马逊还表示,新款插件的操作界面与之前的产品十分相似. 导入虚拟机的时间取决于两个因素:磁盘镜像

关于EC2的AKI和ARI(英文)

Amazon has released an updated version of the Elastic Compute Cloud (EC2) API with the version name 2008-02-01. This release includes a number of new features that were not available in the 2007-08-29 version of the API that I discussed in the book P

用 Amazon Web Services 进行云计算,第 3 部分: 用 EC2 根据需要提供服务器

学习基本的 Amazon SimpleDB (SDB) 概念,研究 boto(一个用于与 SDB 交互的开放源码 Python 库)提供的一些功能.在这个 "用 Amazon Web Services 进行云计算" 系列中,学习如何使用 Amazon Web Services 进行云计算.了解这些服务如何为设计和构建可伸缩.可靠的应用程序提供一种可选方案.本文介绍 Amazon Elastic Compute Cloud (EC2) 提供的虚拟服务器.了解 EC2 如何帮助动态地配置应

玩转云镜像制作之packer篇

1.DevOps之基础设施即代码(Infrastracture as Code)         什么是DevOps呢?按照维基百科的定义,DevOps(Development和Operations的组合词)是一种重视"软件开发人员(Dev)"和"IT运维技术人员(Ops)"之间沟通合作的文化.运动或惯例.透过自动化"软件交付"和"架构变更"的流程,来使得构建.测试.发布软件能够更加地快捷.频繁和可靠.         在缺乏

微服务实战(六):选择微服务部署策略

本文讲的是微服务实战(六):选择微服务部署策略,[编者的话]这篇博客是用微服务建应用的第六篇,第一篇介绍了微服务架构模板,并且讨论了使用微服务的优缺点.随后的文章讨论了微服务不同方面:使用API网关,进程间通讯,服务发现和事件驱动数据管理.这篇文章,我们将讨论部署微服务的策略. 本系列文章: 微服务实战(一):微服务架构的优势与不足 微服务实战(二):使用API Gateway 微服务实战(三):深入微服务架构的进程间通信 微服务实战(四):服务发现的可行方案以及实践案例 微服务实践(五):微服

从Visual Studio中生成Linux设备

本文讲的是从Visual Studio中生成Linux设备,[IT168 云计算频道]近日Novell发布了SUSE Studio:一个用于创建Linux设备(appliance)的工具.与此同时,Mono小组创建了一个插件以从Visual Studio中生成支持SUSE的设备. SUSE Studio的项目经理Nat Friedman将软件设备(software appliance)定义为:所谓软件设备,实际上就是一个完整的应用栈,包括操作系统.应用软件.所需的任何依赖以及与操作相关的配置与数

快速安装Eucalyptus

从Eucalyptus System网站看到一条新闻,得知Eucalyptus和rPath进行了合作.而rPath是一家提供系统软件打包安装的公司.笔者接触到不少软件系 统都是通过rPath的方式进行的打包.rPath可以把Linux操作系统以及相关的软件一起打成一个安装包.安装包可以是基于虚拟机(比如 VMware/ESX)的,也可以是基于裸机的安装包.基本上用户只需要简单的确认一下,就可以快速的完成操作系统和应用系统的安装.大大改进了用户的安 装体验. Google了一下rPath和Euca

如何通过提前Bake Docker镜像加快基础设施的启动速度

本文讲的是如何通过提前Bake Docker镜像加快基础设施的启动速度[编者的话]本文介绍了如何预热Docker镜像来减少基础设施的启动时间,比如通过Ansible工具.删除key.json文件和Docker PID文件等等. 我之前概述过加速AWS基础设施启动的方法.本文中谈到的方法可以进一步减少大约50%的时间,即在应用运行前,预先bake(pre-bake)所需服务. 我们的微服务应用托管于Docker容器,可以从Docker仓库或私有仓库中拉取(pull).不像在Ubuntu服务器上使用

红帽推出Ansible Tower 3,为企业IT自动化扩展提供了更强能力

精简的接口.智能通知和更简单的权限有助于DevOps团队扩展自动化能力,并避免重复任务 (2016年7月27日,北京)世界领先的开源解决方案供应商红帽公司(纽交所代码:RHT)日前宣布全面推出Ansible Tower 3 --这是红帽企业级无代理自动化平台的最新版本.红帽Ansible Tower 3为DevOps团队提供了在企业内扩展自动化的能力,包括精简的接口.更强大的通知能力以及明确的权限授予等.Ansible Tower使用户能够将自动化解决方案推广给整个团队,帮助他们在培养DevOp