26/11/2012 - Gérard Dethier (@gdethier)
Building and managing gold images (AMI on EC2) can quickly become a nightmare. Each cloud vendor has its own requirements and tools in terms of image creation, most of the time different than the standard tools provided by the distro.
In this post, we’ll show you that it is actually possible to install a machine on Amazon EC2 using a kickstart (CentOS/Redhat), preseed (Debian/Ubuntu) or autoyast (OpenSuse). This enables you to re-use tools and recipes you know well, accross physical, virtual and cloud platforms. The same technique has been tested and can be used on other public clouds such as Rackspace, and private cloud such as Eucalyptus, Openstack and Cloudstack.
This post will explain the steps required to install a CentOS using a kickstart on Amazon EC2, but you can use the same technique on pretty much every platform. The key idea is to use a minimal instance that fetches the install kernel/image, write a grub.conf file, and reboot the machine, such that it installs itself on the disk from which it booted.
We assume that you have an EC2 account and that you have created an SSH key pair. If you don’t have one, go get it. Amazon has a free-tier that allows you to experiment with micro instances for free (there is a limit of the number of free hours).
The kickstart you want to use must be available publicly through HTTP. An easy way to publish your kickstart is to paste its content in a service like Pastie and then use the URL to RAW content as value for kernel’s ‘ks’ parameter (see user data in step 2).
Paste the following content into Pastie, adapt it to better fit your needs (change repositories, set root password, etc.), select ‘Plain text’ in language list-box and finally click on ‘Paste’.
Copy the download link for later use (should be like ‘http://pastie.org/pastes/1234567/download’).
Log inside your AWS dashboard and take the following actions:
Click on ‘Launch Instance’ button.
Choose ‘Classic Wizard’ and click on ‘Continue’.
In ‘Community AMIs’ tab, select ‘All images’ in list-box and type ‘comodit’ in text field. You should see an entry named ‘comodit-boostrap-*’, click on ‘select’ button.
Choose your instance type and availability zone (you may use default values).
Set user data with the following content and replace
KS_URL with the URL you obtained on step 1. Do not hesitate to replace
kernel and initrd URLs with closer locations. Click on ‘Continue’.
Proceed to key pair selection and select one, click on ‘Continue’.
Actually create your instance by clicking on ‘Launch’.
If the security group of your instance allows incoming TCP traffic on port 5901, you should be able to monitor the installation using a VNC client (unless you disabled this in the kickstart). Just connect to the instance using its public DNS and port 5901. Note that the installation can last around 10-15 minutes.
At the end of installation process, the instance reboots. After it successfully rebooted, you should be able to connect to it through SSH (your security group must allow incoming TCP traffic on port 22) with user ‘ec2-user’ and the private key you selected, e.g:
ssh -i ~/.ssh/id_rsa ec2-user@PUBLIC_DNS
PUBLIC_DNS is the public DNS of your instance and
is the private key of selected key pair.
blog comments powered by Disqus