Skip to content

Creation of an Ubuntu 12.04 foundation AMI

Michael Ossareh edited this page Jan 25, 2014 · 6 revisions

Warning, this is an early draft and likely won't work

Purpose

Provide a method for creating a foundation image suitable for amination that doesn't depend on publicly released AMIs. We're using Ubuntu cloud-images but this procedure should work on anything that you can get an image for.

Setup

Overview

  • We're going to launch an EC2 instance so that we can create and manipulate EC2 volumes and AMIs
  • Install chef-solo and a Chef recipe to get our instance configured to run ec2-api-tools and provide some scripts
  • We'll use the ec2-api-tools to manage our EC2 resources. IAM credentials make this simpler as tools such as ec2-api-tools already know how to pull the proper credentials from the instance meta-data
  • Create an EBS volume, dd an image to it, umount, snapshot and register an AMI from the snapshot
  • This AMI is now our foundation AMI that we can run aminate on to layer the components of a Base AMI on top of
  • The Base AMI will be used later by other aminator jobs to build Application AMIs which layer specific application components on top of the Base AMI

Prerequisites

  • AWS account
  • IAM profile with proper EC2 credentials (e.g. Power User)

Steps

Run an instance we can use to build a foundation image

  • First, we need to be running in EC2 so that we can easily manipulate EC2 resources.
1
  • Let's launch it. t1.micro is ok for this purpose, but we tend to use m1.xlarge
2
  • Note the IAM profile setting. This profile should be able to manage EC2 resources
3
  • Prepare to launch. Security Group is just the default ssh group.
4 + Once you have a running instance ssh into it using the ubuntu@ Don't forget to setup your key-pair
ubuntu@ip-10-252-62-202:~$ sudo mkdir -p /var/chef/cookbooks/netflix/recipes
ubuntu@ip-10-252-62-202:~$ curl -s https://gist.github.com/kvick/2e775e5e533c75c0708f/raw/fdff0f55f34cdf1d259ff5647f26cf23ccdaa782/aminator.rb | sed 's!git@github.com:Netflix/aminator.git!https://github.com/Netflix/aminator.git!' > aminator.rb
ubuntu@ip-10-252-62-202:~$ sudo mv aminator.rb /var/chef/cookbooks/netflix/recipes/aminator.rb

ubuntu@ip-10-252-62-202:~$ sudo mkdir /opt/chef/foundation-cookbook-master
ubuntu@ip-10-252-62-202:~$ sudo curl https://gist.github.com/kvick/774b764d99901a0210a5/raw/7a4bb6df75c1420f36e5048f1bfb92fef7dc6704/aminator.json -o /opt/chef/foundation-cookbook-master/aminator.json
ubuntu@ip-10-252-62-202:~$ sudo curl https://gist.github.com/kvick/0f7a04459e66d368ea78/raw/535004a96fab3f615491ae2949f73288f96b96e9/solo.rb -o /opt/chef/foundation-cookbook-master/solo.rb
ubuntu@ip-10-252-62-202:~$ sudo /opt/chef/bin/chef-solo -j /opt/chef/foundation-cookbook-master/aminator.json -c /opt/chef/foundation-cookbook-master/solo.rb

ubuntu@ip-10-252-62-202:~$ curl -O http://cloud-images.ubuntu.com/releases/precise/release/ubuntu-12.04-server-cloudimg-amd64-root.tar.gz
ubuntu@ip-10-252-62-202:~$ tar xvzf /ubuntu-12.04-server-cloudimg-amd64-root.tar.gz

ubuntu@ip-10-252-62-202:~$ ec2-create-volume --region us-west-2 -s 10 -z us-west-2a
VOLUME  vol-4fe1de76    10              us-west-2a      creating        2013-03-07T23:00:50+0000 standard

ubuntu@ip-10-252-62-202:~$ ec2-attach-volume --region us-west-2 vol-4fe1de76 -i i-54723f66 -d
/dev/xvdf
ATTACHMENT      vol-4fe1de76    i-54723f66      /dev/xvdf       attaching 2013-03-07T23:33:49+0000

ubuntu@ip-10-252-62-202:~$ time sudo dd if=precise-server-cloudimg-amd64.img of=/dev/xvdf
conv=sync,noerror bs=1M
1408+0 records in
1408+0 records out
1476395008 bytes (1.5 GB) copied, 81.6868 s, 18.1 MB/s

real    1m21.818s
user    0m0.140s
sys     0m3.040s


ec2-detach-volume --region us-west-2 vol-4fe1de76
ATTACHMENT      vol-4fe1de76    i-54723f66      /dev/xvdf       detaching 2013-03-07T23:33:49+0000
ubuntu@ip-10-252-62-202:~$ ec2addsnap --region us-west-2 vol-4fe1de76
SNAPSHOT        snap-d3656bea   vol-4fe1de76    pending 2013-03-08T00:11:29+0000 471318250990    10
ubuntu@ip-10-252-62-202:~$ ec2reg --region us-west-2 -n "ubuntu-foundation" -d "12.04.2" -a  x86_64 -b /dev/sda1=snap-d3656bea::true --kernel aki-fa37baca
IMAGE   ami-285bce18

ubuntu@ip-10-252-62-202:~$ ec2-run-instances --region us-west-2 ami-285bce18 -k kvick-foundation -t
t1.micro -g kvick-default --kernel aki-fc37bacc
RESERVATION     r-a40db096      471318250990    kvick-default
INSTANCE        i-06b5fa34      ami-285bce18                    pending kvick-foundation        0

TODO

  • Create a tarball of our chef recipe and host it somewhere (box?) so we don't need to do the zip install step
  • Test with CentOS
  • Install aminate on our runing instance to create a base AMI using

Tips

  • You can configure ssh to use a different private key when ssh-ing into your instance [~/.ssh/config] Host .us-west-2.compute.amazonaws.com IdentityFile ~/.ssh/kvick-foundation.pem