Compiling 2.6.21 Kernel Modules from Source for Amazon EC2

Though it is not possible to compile and run your own kernels on Amazon EC2, it is possible to compile and run your own kernel modules and bundle them with your EC2 images. The trick is that the kernel modules need to be compiled with exactly the same kernel source and compiler versions as were used to build the original kernel.

The steps below were used to build the updated 2.6.21 kernel modules for the Ubuntu and Debian AMIs listed at

Run an instance of the Fedora 8 AMI from Amazon:

  • 32-bit: ami-f51aff9c
  • 64-bit: ami-f21aff9b

Upgrade and install required packages:

yum upgrade -y
yum install -y rpmdevtools sparse

Download kernel source, patch, and configure:

arch=x86_64  # for 64-bit (large, xlarge)
arch=i686    # for 32-bit (small, medium)

curl -LO \

rpm -ivh kernel-xen-2.6- 2>&1 |
  egrep -v '(user|group) mockbuild does not exist'

cd /usr/src/redhat/SPECS/

rpmbuild -bp --target=$arch kernel.spec

mv /usr/src/redhat/BUILD/kernel-2.6.21/linux-2.6.21.$arch \
   /usr/src/linux-$(uname -r)

cd /usr/src/linux-$(uname -r)/
mv .config .config.orig
cp /boot/config-$(uname -r) .config
echo "-2.fc8xen" > localversion-ec2

Build and install the kernel modules:

time make modules # 70 minutes

make INSTALL_MOD_STRIP=1 modules_install

Download, build, and install the latest fuse kernel module source:

curl -L -O
tar xvzf fuse-2.7.3.tar.gz
cd fuse-2.7.3
./configure --enable-kernel-module
make INSTALL_MOD_STRIP=1 install

Package up the new kernel modules:

tar cvzf /tmp/ec2-kernel-modules-2.6.21.$arch.tar.gz \

Copy the kernel modules to where you are building your new AMI instance and unpack:

cd /
tar xvf /tmp/ec2-kernel-modules-2.6.21.$arch.tar.gz
depmod -a

If you are using the ec2ubuntu-build-ami script, you can specify the URL of the kernel modules with the --modules option

Article originally published here: