{"id":73,"date":"2014-02-20T14:18:00","date_gmt":"2014-02-20T22:18:00","guid":{"rendered":"http:\/\/junsun.net\/wordpress\/?p=73"},"modified":"2020-03-20T14:19:59","modified_gmt":"2020-03-20T21:19:59","slug":"build-centos-6-ami","status":"publish","type":"post","link":"https:\/\/junsun.net\/wordpress\/2014\/02\/build-centos-6-ami\/","title":{"rendered":"Build CentOS 6 AMI"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>This is a faithful translation of the excellent\u00a0<a href=\"http:\/\/www.idevelopment.info\/data\/AWS\/AWS_Tips\/AWS_Management\/AWS_10.shtml\">tutorial<\/a>\u00a0by\u00a0<a href=\"mailto:jhunter@idevelopment.info\">Jeff Hunter<\/a>\u00a0to BASH script. However, the result is so useful that I felt it is meaningful to share. \ud83d\ude42<\/p>\n<p>If you are patient enough, you should read the tutorial for all the gory details. If you are not, just follow the steps below. If you are lucky, you can build a CentOS 6 AMI in a hurry.<\/p>\n<h2>Pre-requisites<\/h2>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>CentOS build host: Should have at 10GB extra space<\/li>\n<li>Install host tools:<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<pre>yum -y install e2fsprogs ruby java-1.6.0-openjdk unzip MAKEDEV<\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Install AWS tools:<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<pre><code>\n# mkdir -p \/opt\/ec2\/tools\n# curl -o \/tmp\/ec2-api-tools.zip http:\/\/s3.amazonaws.com\/ec2-downloads\/ec2-api-tools.zip\n# unzip \/tmp\/ec2-api-tools.zip -d \/tmp\n# cp -r \/tmp\/ec2-api-tools-*\/* \/opt\/ec2\/tools\n\n# curl -o \/tmp\/ec2-ami-tools.zip http:\/\/s3.amazonaws.com\/ec2-downloads\/ec2-ami-tools.zip\n# unzip \/tmp\/ec2-ami-tools.zip -d \/tmp\n# cp -rf \/tmp\/ec2-ami-tools-*\/* \/opt\/ec2\/tools\n<\/code><\/pre>\n<h2>The script<\/h2>\n<p>You can find the script\u00a0<a href=\"http:\/\/junsun.net\/old\/linux\/centos-ami\/build-centos-ami.sh\">here<\/a>.<\/p>\n<p>Note you need to configure the following parameters at the beginning the script. Most certainly you need to supply EC2_PRIVATE_KEY, EC2_CERT, AWS_ACCOUNT_NUMBER, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, EC2_KEYPAIR, EC2_SECURITY_GROUP.<\/p>\n<blockquote>\n<pre>export JAVA_HOME=\/usr\nexport EC2_HOME=\/opt\/ec2\/tools\n#export EC2_URL=https:\/\/ec2.amazonaws.com\nexport EC2_URL=https:\/\/ec2.us-west-1.amazonaws.com\nexport EC2_PRIVATE_KEY=\/home\/jsun\/files\/aws-nsp-x509-pk-4USZFXUMLDXAV5Q3BNUUYPURLA6VZWRH.pem\nexport EC2_CERT=\/home\/jsun\/files\/aws-nsp-x509-cert-4USZFXUMLDXAV5Q3BNUUYPURLA6VZWRH.pem\n\nexport AWS_ACCOUNT_NUMBER=XXXXXXXXXX\nexport AWS_ACCESS_KEY_ID=XXXXXXXXXX\nexport AWS_SECRET_ACCESS_KEY=XXXXXXXXXX\nexport AWS_AMI_BUCKET=vyatta-ami\/x86-64\/Linux\/CentOS\/6.5\n\nIMG_BASE_NAME=centos-6-x86_64\nS3_REGION=us-west-1\nAMI_PVGRUB=aki-f77e26b2\nEC2_KEYPAIR=XXXX\nEC2_SECURITY_GROUP=XXXX\n<\/pre>\n<\/blockquote>\n<p>Also note you may need to change AMI_PVGRUB depending on the region and architecture. Refer to the tutorial for details. Here is a list of them for us-west-1:<\/p>\n<blockquote>\n<pre>root@localhost ~]# ec2-describe-images --owner amazon --region us-west-1 | grep \"amazon\\\/pv-grub-hd0\" | awk '{ print $1, $2, $3, $5, $7 }'\nIMAGE aki-960531d3 amazon\/pv-grub-hd00_1.04-i386.gz available i386\nIMAGE aki-920531d7 amazon\/pv-grub-hd00_1.04-x86_64.gz available x86_64\nIMAGE aki-8e0531cb amazon\/pv-grub-hd0_1.04-i386.gz available i386\nIMAGE aki-880531cd amazon\/pv-grub-hd0_1.04-x86_64.gz available x86_64\nIMAGE aki-e97e26ac amazon\/pv-grub-hd00_1.03-i386.gz available i386\nIMAGE aki-eb7e26ae amazon\/pv-grub-hd00_1.03-x86_64.gz available x86_64\nIMAGE aki-f57e26b0 amazon\/pv-grub-hd0_1.03-i386.gz available i386\nIMAGE aki-f77e26b2 amazon\/pv-grub-hd0_1.03-x86_64.gz available x86_64\n<\/pre>\n<\/blockquote>\n<p>If you are lucky, run the scrip the following order, and you should have a CentOS instance running in AWS. \ud83d\ude42<\/p>\n<blockquote>\n<pre><code>\ncommands:\n  init     : perform teardown and create new img file\/dirs, set up yum\n  setup    : mount image, bind run-time dirs\n  install  : install centos image (after setup)\n  configure: configure the OS img (after install)\n  teardown : unbind and un-mount\n  bundle   : build img bundle for upload (after install\/configure\/teardown)\n  upload   : upload image (after bundle)\n  register : register AMI (after upload)\n  run &lt;id&gt; : run a small instance of the registered AMI\n<\/code><\/pre>\n<\/blockquote>\n<p>Find out the IP address of the new instance, and ssh into it<\/p>\n<pre><code>ssh -i my_aws.pem root@&lt;pub ip address&gt;<\/code><\/pre>\n<h2>Tricks and Tips<\/h2>\n<ol>\n<li>It takes long time (&gt;2 minutes) for the instance to boot up. Be patient. And don&#8217;t panic too soon.<\/li>\n<li>If somehow you cannot log into the instance with the key pair, you can always pre-create \/root\/.ssh directory in the OS image and pre-create the authorized_keys file underneath it.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Overview This is a faithful translation of the excellent\u00a0tutorial\u00a0by\u00a0Jeff Hunter\u00a0to BASH script. However, the result is so useful that I felt it is meaningful to share. \ud83d\ude42 If you are patient enough, you should read the tutorial for all the gory details. If you are not, just follow the steps below. If you are lucky, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/junsun.net\/wordpress\/2014\/02\/build-centos-6-ami\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Build CentOS 6 AMI&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3],"tags":[26,24,25],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":4,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/posts\/73\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junsun.net\/wordpress\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}