BuildingOnEC2

Revision 3 as of 2009-02-20 18:44:47

Clear message

I've been experimenting with building kernels on instances in the Amazon EC2 cloud. In most cases this isn't going to give better performance than building locally on a fast build server, it's an option if you don't have any fast hardware available.

This work was done during the Jaunty alpha releases.

Here's the basic recipe for how to do it:

Set up you Amazon account and sign up for the Ubuntu Beta

You'll need to set up an Amazon account and sign up for the Ubuntu beta testing, in order to get access to ubuntu images on EC2.

To do that, follow the instruction here:

https://help.ubuntu.com/community/EC2StartersGuide

Once you've done that make sure you can start, stop, and access instances as described.

About the EC2 Instances

The EC2 instance is started with storage mounted on /mnt. Since there isn't much storage space on the instance otehr than on this mount point, some of the steps below are done in order to link the 'normal' directories used for kernel builds to that mount point.

Since the instance storage is non-persistent, this example shows how to recreate the chroots used for building and the kernel git trees every time. For actual production use, these should be stored on Amazon persistent storage and mounted on the instance. Since I was only testing kernel build speed, I didn't bother.

How to build a kernel on the EC2 Instance

Create an Instance

This instance uses Amazon's XXXXXXXXX

sconklin@XPS-1:~$ ec2-run-instances ami-a84aaec1 -k ec2-keypair -t c1.xlarge
RESERVATION     r-a0cb75c9      581779666099    default
INSTANCE        i-599c0b30      ami-a84aaec1                    pending ec2-keypair     0               c1.xlarge       2009-02-20T18:21:27+0000        us-east-1c      aki-d314f0ba    ari-d014f0b9    

sconklin@XPS-1:~$ ec2-describe-instances
RESERVATION     r-a0cb75c9      581779666099    default
INSTANCE        i-599c0b30      ami-a84aaec1    ec2-67-202-42-150.compute-1.amazonaws.com       domU-12-31-39-00-70-91.compute-1.internal       running ec2-keypair     0               c1.xlarge       2009-02-20T18:21:27+0000        us-east-1c      aki-d314f0ba    ari-d014f0b9    

ec2-describe-instances shows that the instance is started - the instance identifier is i-599c0b30 and the name used to access it is ec2-67-202-42-150.compute-1.amazonaws.com

ec2-authorize default -p 22 # This only has to be done once

Log in once as root and select the default configuration

sconklin@XPS-1:~$ ssh -i ./ec2-keypair.pem root@ec2-67-202-42-150.compute-1.amazonaws.com
Linux ubuntu 2.6.27-13-xen #1 SMP Sat Nov 8 23:30:17 UTC 2008 x86_64

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/

======================================================
CONFIGURATION OF YOUR UBUNTU EC2 IMAGE
======================================================
Your EC2 image is about to be finished to be set up.

------------------------------------------------------
New password for ubuntu account: abcd1234
Password changed.
Setting up ssh public keys for the ubuntu account.

------------------------------------------------------
Please select software that you wish to install:

------------------------------------------------------

We are now going to log you out of the root account.
To perform administrative tasks please use the ubuntu account
in combination with sudo using the password: abcd1234

======================================================

Connection to ec2-67-202-42-150.compute-1.amazonaws.com closed.

Make a note of the password supplied for the 'ubuntu' account. You'll need it for using sudo later.

Log in to the EC2 Instance

sconklin@XPS-1:~$ ssh -i ./ec2-keypair.pem ubuntu@ec2-67-202-42-150.compute-1.amazonaws.com

On the instance, perform the following:

ubuntu@ubuntu:~$ sudo mkdir -m 775 /mnt/chroots 
ubuntu@ubuntu:~$ sudo mkdir -m 755 /mnt/src
ubuntu@ubuntu:~$ sudo ln -s /mnt/chroots /var/chroots
ubuntu@ubuntu:~$ sudo mkdir /home/ubuntu/src
ubuntu@ubuntu:~$ sudo chown ubuntu:ubuntu /home/src
ubuntu@ubuntu:~$ sudo ln -s /mnt/src /home/ubuntu/src

ubuntu@ubuntu:~$ sudo apt-get install debootstrap schroot git-core

ubuntu@ubuntu:~$ cd src
ubuntu@ubuntu:~$ git clone git://kernel.ubuntu.com/ubuntu/buildscripts.git
ubuntu@ubuntu:~$ vim buildscripts/setup-chroots

Edit the binds= line and add 'mnt' to the list