Updating an AMI's Kernel and Ramdisk

Articles & Tutorials>Updating an AMI's Kernel and Ramdisk
In order to upgrade your AMI to the latest kernel you will have to launch your existing AMI and rebundle it explicitly overriding thedefault bundling tools behavior - which is to use the instance meta-data service to determine your current kernel and ramdiskcombination OR overriding the launch time kernel and ramdisk parameters.

Details

Submitted By: ian@aws
AWS Products Used: Amazon EC2
Created On: September 30, 2009 12:06 AM GMT
Last Updated: September 30, 2009 12:11 AM GMT

By way of example let's use the previous Fedora 8 release (v1.09).

An ec2-describe-images call would look as follows:

IMAGE  ami-520d2526
   ec2-public-images-eu/fedora-8-i386-base-v1.07.manifest.xml amazon
   available  public i386machine  aki-7e0d250a ari-7d0d2509

Note the versions of the kernel 'aki-7e0d250a' and the ramdisk 'ari-7d0d2509'.

aki-7e0d250a    ec2-public-images-eu/ec2-vmlinuz-2.6.21.7-2.fc8xen.i386.manifest.xml
ari-7d0d2509    ec2-public-images-eu/ec2-initrd-2.6.21.7-2.fc8xen.i386.manifest.xml

But we want the updated kernel and ramdisk:

aki-02486376   ec2-public-images-eu/vmlinuz-2.6.21-2.fc8xen-ec2-v1.0.i386.aki.manifest.xml
ari-aa6348de   ec2-public-images-eu/initrd-2.6.21.7-2.fc8xen-ec2-v1.0.i386.ari.manifest.xml

What we'll do is launch the instance using the standard tools, but override it's default kernel and ramdisk parameters.

ec2run --key my-keypair --instance-type m1.small --kernel  aki-02486376
   --ramdisk ari-aa6348de ami-520d2526

So we're launching our old AMI but overriding the default kernel and ramdisk parameters with our new kernels.

Once the instance is up and running, we can perform our normal bundling operation as outlined in the documentation.

Now if you have an existing instance that we want to bundle, but it's running on an older/different kernel we can do that by using the following flags for bundlevol:

bundlevol --kernel aki-02486376 --ramdisk  ari-aa6348de --exclude
   /root/.ssh  ...[rest of parameters as above]

TIP: Don't forget to clean up before bundling, you want to remove things like host keys, and logs. Here is a destructive example. DO NOT use it on live instances that you want to continue using.

# Remove logs
   find /var/log -type f -exec rm "{}" \;

# Remove history files
   rm -f /root/.viminfo /root/.lesshst /root/.bash_history

# Remove host ssh keys
   rm —rf /etc/ssh/ssh_host_*key*

# Set firstrun flag on Amazon images
   touch /root/firstrun
©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.