Using Boxgrinder to build your own AMI for EC2

In my last article I showed on how to create your own AMI for EC2. The article basically demonstrated the whole process been done manually by executing commands. In this article I would like to cover Boxgrinder which reduces the manual effort completely and helps you get your own AMI registered on EC2 and in few minutes.

First thing is that we need to run boxgrinder on CentOS if we would like to build a CentOS AMI and on Fedora if we would like to build a Fedora AMI. The good thing about boxgrinder is that it uses the latest pvgrub kernel images provided by Amazon which basically lets you boot into your own kernel. So gone are the days when we had to use Amazon EC2 kernel. Thanks to Marek Goldmann for making this possible in boxgrinder 0.5

Without wasting much time let’s get started. I am going to build a Fedora 13 AMI for EC2 in this article but you can do the same stuff using CentOS. First of all we will have to install some required packages which are basically the dependencies.

# yum -y install git parted wget rpmdevtools appliance-tools \
sudo libguestfs ruby  rubygems ruby-libguestfs guestfish \
 yum-utils e2fsprogs

Next we need to install the EC2 AMI tools

#  rpm -Uvh http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm

Then we need to install couple of gems for boxgrinder which will let us build a AMI for EC2. The following are the gems

# gem install boxgrinder-build
# gem install boxgrinder-build-fedora-os-plugin
# gem install boxgrinder-build-ec2-platform-plugin
# gem install boxgrinder-build-s3-delivery-plugin

Now we need to create a appliance definition file which will be used to build our AMI. This file is basically written in YAML format. The following is the file which I used:

name: Fedora13EC2
summary: My Fedora on EC2
 name: fedora
 version: 13
     size: 2
   - bash
   - kernel-PAE
   - grub
   - e2fsprogs
   - passwd
   - policycoreutils
   - chkconfig
   - rootfiles
   - yum
   - vim-minimal
   - acpid
   - dhclient
   - iputils
   - openssh-server
   - openssh-clients
   - httpd
   - system-config-firewall-base

Save this file in a directory appliances/ with the name Fedora13EC2.appl. Now we need to create a file which will store our AWS credentials and other important paths to certificate and private key. These are required by boxgrinder to put the image in S3 and register it with EC2.

# vi $HOME/.boxgrinder/plugins/s3
access_key: yourawsaccesskey                        # required
secret_access_key: youawssecretkey             # required
bucket: myownfedora-box                               # required
account_number: youramazonaccountnumber  # required
path: /mnt/images                                 # default: /
cert_file: /root/.ec2/yourcertificate.pem   # required only for ami type
key_file: /root/.ec2/yourprivatekey.pem  # required only for ami type

We need to create the directory /mnt/images which will store the AMI.

# mkdir /mnt/images

Finally we can fire boxgrinder to build the AMI.

# boxgrinder-build appliances/Fedora13EC2.appl -p ec2 -d ami

It will run for few minutes and will end up with something like:

I, [2010-08-07T06:21:58.693095 #17381] INFO — : Image successfully registered under id: ami-

That’s it. So simple right? Now you run this AMI and enjoy !

I would like to encourage people to look into this project. This is really awesome. For more information you can go through the following links

In my next post I will cover my experience with passing user data scripts to EC2 AMI while starting the instance and much more to come. Happy hacking :-)

There's 4 Comments So Far

  • Marek Goldmann
    August 7th, 2010 at 10:46 AM

    Thank you for this tutorial!

    I have one comment: path specified in $HOME/.boxgrinder/plugins/s3 is used as a prefix in your bucket where you store your AMI. In your example it’ll be: myownfedora-box/mnt/images.

    If you want to move appliances to a local location (for example other partition), you can use Local delivery plugin (‘-d local’ switch), then path (specified in $HOME/.boxgrinder/plugins/local) will act as described in your post.


  • James Weir
    November 21st, 2010 at 11:13 AM

    Thanks for the tutorial.

    I would also like to mention UShareSoft’s UForge that provides a visual experience in building EC2 AMI images images as well as other image types (including ISO, VMware, ESXi, Hyper-V, VHD, QCOW2, Eucalyptus Machine Image, KVM, Xen and VirtualBox). The platform supports many operating systems types including Fedora, CentOS, Debian and Ubuntu.

    As a disclaimer I actually work for the company.


  • David Gómez
    April 24th, 2011 at 3:11 PM

    Iḿ having a big headache trying to use boxgrinder to build an AMI appliance for Elastix (CentOS 5.6) cus all the dependencies like appliance-tools, etc.

    Can you help me explaining how to do it with so old packages like those we can find in CentOS?

Who Linked To This Post?

  1. Tweets that mention /home/jeevanullas » Using Boxgrinder to build your own AMI for EC2 -- Topsy.com

Share your thoughts, leave a comment!