Last active
October 6, 2019 03:46
-
-
Save Justinzobel/ce58f27a00fbb33b9ef163360f240eeb to your computer and use it in GitHub Desktop.
systemd-boot loader entries creation script (used on elementary OS 5.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This is a simple custom kernel hook to populate the systemd-boot entries | |
# whenever kernels are added or removed during an update. | |
# | |
distroid=$(cat /etc/lsb-release | grep DISTRIB_ID | cut -d "=" -f 2) | |
distroname=$(cat /etc/lsb-release | grep DISTRIB_DESCRIPTION | cut -d "\"" -f 2) | |
# The name of your root partition | |
partition=$(cat /etc/fstab | grep "/ was on" | cut -d " " -f 5) | |
vmlinuz=$(find /boot -maxdepth 1 -name "vmlinuz-*-generic") | |
version=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | head -n -1) | |
latest=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | tail -n 1) | |
mkdir -p /boot/loader/entries/${distroid}/ | |
echo ">> COPYING ${latest}-generic. LATEST VERSION." | |
cat << EOF > /boot/loader/entries/${distroid}.conf | |
title ${distroname} - Current Kernel | |
linux /${distroid}/vmlinuz-generic | |
initrd /${distroid}/initrd.img-generic | |
options root=${partition} rw rootflags=subvol=@ | |
EOF | |
for file in initrd.img vmlinuz; do | |
cp "/boot/${file}-${latest}-generic" "/boot/loader/entries/${distroid}/${file}-generic" | |
done | |
for ver in $version; do | |
echo ">> COPYING ${ver}-generic." | |
cat << EOF > /boot/loader/entries/${distroid}-${ver}.conf | |
title ${distroname} - Kernel ${ver} | |
linux /${distroid}/vmlinuz-${ver}-generic | |
initrd /${distroid}/initrd.img-${ver}-generic | |
options root=${partition} rw rootflags=subvol=@ | |
EOF | |
for file in initrd.img vmlinuz; do | |
cp "/boot/${file}-${ver}-generic" "/boot/loader/entries/${distroid}/${file}-${ver}-generic" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use at your own risk, etc.