Index ¦ Archives ¦ Atom

DigitalOcean Debian kernel

DigitalOcean offers some fantastic KVM powered virtual machines for low prices, however the technical decisions they've made in various places leaves something to be desired.

One of the problems which you may face at some point is that you're stuck with whatever kernel they provide, you can't use your own bootloader. They've attempted to solve this by providing kernels from every Linux distribution they support - but sadly this isn't the solution which I'd expect a KVM provider to use.

To work around this, we can use kexec to change the kernel on boot. Install kexec:

$ sudo apt-get install kexec-tools

Move /sbin/init to /sbin/init.distrib:

$ dpkg-divert --add --local --rename /sbin/init creates=/sbin/init.distrib

And create a script to replace /sbin/init


if grep -qv " kexeced$" /proc/cmdline; then
    /sbin/kexec --load /vmlinuz \
        --reuse-cmdline \
        --initrd=/initrd.img \
        --append="init=/sbin/init.distrib kexeced" \
    && /bin/mount -o ro,remount / \
    && /sbin/kexec --exec

exec /sbin/init.distrib "$@"

Make it executable:

$ sudo chmod 755 /sbin/init

And then you can reboot. Next time your server restarts, the script will run before any other init scripts and will change the running kernel with kexec. You can change the kernel parameters in this file if you need custom options, or just leave it as is - and you'll be able to stick with your standard Debian kernel.

Credit to Joe Johnston for the original script.


A couple of years later, DigitalOcean eventually created new images which use the virtual machines bootloader - which means this hack is no longer needed for newer Linux distributions.

© Alex Tomkins.