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 os: name: fedora version: 13 hardware: partitions: "/": size: 2 packages: includes: - 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