Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packer + Vagrant - create AMI from ISO

Is it possible to create an AMI from an ISO?

I am implementing a build system which uses the base iso, modifies it, installs stuff and then outputs it in .ovf and AMI.

.ovf works. But for AMI, all I could figure out is it needs pre existing AMI. Is this correct?

Is there any way to use an iso and generate an AMI?

Thanks.

like image 656
MavWolverine Avatar asked Oct 13 '14 16:10

MavWolverine


2 Answers

When you say from ISO that tells me you're looking to create a trusted base VM. You want to install from scratch locally first and import that to ec2 as a trusted private AMI. If you don't mind using veewee there's an awesome post using veewee instead of packer here: veewee It's all setup for CentOS. All you need to do is clone it and tweak it for your use case.

But since you're looking for packer like I was then what you need is the virtualbox-iso builder in packer and some aws-cli commands to upload and create an AMI out of the OVA. Packer doesn't have a post-processor for this unfortunately. Then you can use vagrant to reference the new AMI for ec2 based development and use the vagrant-aws plugin to create new ami's out of your trusted base ami.

Here are the steps to follow:

1.) Create an S3 bucket for image imports.

2.) Set up your AWS account. Create 'vmimport' IAM role and policy as well as X509 key and cert pair in case you don't have it. You'll need this to register a private AMI. You will also reference the bucket's name for the policy.

3.) Build a VM with VirtualBox using packer's virtualbox-iso builder and have it output an image in ova format.

4.) use aws-cli with your aws account to upload the OVA to the bucket you created. aws s3 cp command.

5.) Register the OVA as an ami. You will use the aws ec2 import-image command for this. (This part can take a long time 30 min - 1 hour).

You can track progress with: aws ec2 describe-import-image-tasks The AMI will appear in your Private AMI list when it's done.

like image 168
Ryan B. Avatar answered Oct 04 '22 23:10

Ryan B.


Vagrant includes a useful little plugin called vagrant-ami which lets you create EC2 custom AMIs:

$ vagrant create-ami new_image --name my-ami --desc "My AMI"

Then you can replace the AMI ID in your Vagrantfile with your custom one.

like image 42
Mayur Nagekar Avatar answered Oct 04 '22 23:10

Mayur Nagekar