#!/bin/bash # # This is a simple kernel hook to populate the systemd-boot entries # whenever kernels are added or removed. # # Our kernels. KERNELS=() FIND="find /boot -maxdepth 1 -name 'vmlinuz-*' -type f -print0 | sort -rz" while IFS= read -r -u3 -d $'\0' LINE; do KERNEL=$(basename "${LINE}") KERNELS+=("${KERNEL:8}") done 3< <(eval "${FIND}") # There has to be at least one kernel. if [ ${#KERNELS[@]} -lt 1 ]; then echo -e "\e[2msystemd-boot\e[0m \e[1;31mNo kernels found.\e[0m" exit 1 fi LATEST="${KERNELS[@]:0:1}" echo -e "\e[2msystemd-boot\e[0m \e[1;32m${LATEST}\e[0m" objcopy \ --add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \ --add-section .cmdline=/etc/kernel/cmdline --change-section-vma .cmdline=0x30000 \ --add-section .linux=/boot/vmlinuz-${LATEST} --change-section-vma .linux=0x2000000 \ --add-section .initrd=/boot/initrd.img-${LATEST} --change-section-vma .initrd=0x3000000 \ /usr/lib/systemd/boot/efi/linuxx64.efi.stub \ /boot/efi/EFI/Linux/ubuntu.efi # Success! exit 0