Recently I setup my work laptop to dual boot Arch Linux and Ubuntu server with syslinux as my bootloader. I setup the laptop with a dedicated /boot partition that would be shared between the two operating systems. I added this boot entry to /boot/syslinux/syslinux.cfg
.
LABEL ubuntu
MENU LABEL Ubuntu
LINUX ../vmlinuz-3.8.0-29-generic
APPEND root=LABEL=UBUNTU rw
INITRD ../initrd.img-3.8.0-29-generic
This worked great and allowed me to get booted into Ubuntu after installation. However, I realized that this would fail to boot the next time there was an Ubuntu kernel upgrade, since the kernel and initrd names contain the version. This isn't an issue on Arch, since there is only ever one kernel installed, and the name is always the same.
After some research, I learned about Debian kernel hooks. They are scripts under /etc/kernel/postinst.d/
that get executed with every kernel update, and passed the kernel version as an argument. This is what grub uses to update it's configuration. Instead of editing my syslinux.cfg
every time, I decided it would easier to create symbolic links and just change their target. Thus, I modified my syslinux.cfg
entry.
LABEL ubuntu
MENU LABEL Ubuntu
LINUX ../vmlinuz-ubuntu
APPEND root=LABEL=UBUNTU rw
INITRD ../initrd.img-ubuntu
Next I created /etc/kernel/postinst.d/syslinux
and marked it executable.
#!/bin/sh
version="${1}"
# passing the kernel version is required
[ -z "${version}" ] && exit 0
cd /boot
ln -sf vmlinuz-${version} vmlinuz-ubuntu
ln -sf initrd.img-${version} initrd.img-ubuntu
I forced a kernel reinstallation to test, and the hook was called and created the symbolic links. Future kernel upgrades have worked without issue.