Tuesday, January 11, 2011

Cloud Life: Kernel Upgrades

One thing not mentioned in EC2StartersGuide is how to apply kernel patches. Technically, this isn't currently possible in the Amazon cloud, which is to say that the boot loader (e.g. grub) within an EC2 instance cannot load an arbitrary kernel; nonetheless, official kernel updates are available via package updates, though cloud servers won't automatically load the latest installed kernel when booted.

A fix was recently released for an ec2 kernel bug causing high load averages to be reported. The new kernel package was linux-image-2.6.32-309-ec2 and aptitude reports the exact version:

% aptitude show linux-image-2.6.32-309-ec2 | grep Version
Version: 2.6.32-309.18


We can get a list of available kernels with ec2-describe-images, official Ubuntu kernels are owned by account #099720109477. We can filter the results based on the image name, the following example (edited for brevity) shows stable kernels for Ubuntu Lucid:

% ec2-describe-images -o 099720109477 \
--filter name=ubuntu-kernels/ubuntu-lucid-i386\*
IMAGE aki-754aa41c ... linux-image-2.6.32-305-ec2 ...
IMAGE aki-5037dd39 ... linux-image-2.6.32-308-ec2 ...
IMAGE aki-3204f15b ... linux-image-2.6.32-308-ec2 ...
IMAGE aki-6603f70f ... linux-image-2.6.32-309-ec2 ...


While not shown above, the full version is displayed; however in this case there is only one kernel in the 2.6.32-309 series. This is easily seen by altering the example filter to ubuntu-kernels\*/ubuntu-lucid-i386\*, which will include images from ubuntu-kernels-testing, ubuntu-kernels-sandbox, etc. The second column lists the kernel ID, which may be used with ec2-modify-instance-attribute to actually change the kernel used by an EC2 instance:

ec2-modify-instance-attribute --kernel aki-6603f70f ${instance_id}


A list of your instances and the current kernels is conveniently displayed with ec2-describe-instances as well as the AWS Management Console.

Eventually the Ubuntu package maintainers would like to have the package manager (at a minimum) provide specific instructions whenever a new kernel is available; until they do, or Amazon adds such a feature to the AWS Console, this is the way to upgrade the kernel on EC2 instances.