You are not logged in.
I've wrote a scrappy script that automates systemd-boot entries by parsing the compressed kernel files in /boot, then creating an entry for each one (it skips fallback since I can just manually edit an entry to boot into fallback if necessary). For clarity, the script is attached:
#!/bin/sh
if [ $EUID -ne 0 ]; then
echo "Requires root permissions, exiting..."
exit 1
fi
DEFAULT_PARAMETERS="quiet loglevel=3 systemd.show_status=auto rd.udev.log_level=3 zswap.enabled=0"
OS_NAME="$(hostnamectl --json=short | jq -r ".OperatingSystemPrettyName")"
MICROCODE="$(basename $(find /boot -type f -name "*-ucode.img"))"
OPTIONS="root=\"PARTUUID=$(findmnt -no PARTUUID /)\" rw"
basename -a $(find /boot -type f -name "vmlinuz-linux-*") | while read KERNEL; do
TYPE=$(awk -F"-" "{print \$3}" <<< "$KERNEL")
DEFAULT_IMAGE="initramfs-linux-$TYPE.img"
ENTRY_FILE="/boot/loader/entries/$(awk -F" " "{print tolower(\$1)}" <<< "$OS_NAME")-$TYPE.conf"
FILE_CONTENT=("title $OS_NAME (linux $TYPE)"
"linux /$KERNEL"
"initrd /$MICROCODE"
"initrd /$DEFAULT_IMAGE"
"options $OPTIONS $DEFAULT_PARAMETERS")
echo "" > $ENTRY_FILE
for line in "${FILE_CONTENT[@]}"; do
echo "$line" >> $ENTRY_FILE
done
done
In order to further automate this, I decided to try and make a Pacman Hook. My first attempt involved something like this:
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Path
Target = boot
[Action]
Description = Re-creating systemd-boot entries...
When = PostTransaction
Exec = /home/frontear/.local/bin/update-bootloader
I tried to test this by running pacman -S linux-hardened, but unfortunately it does not work.
I figure it's possible that since the target isn't actually being changed by the packages, but by another hook, pacman doesn't know to run it, so I modified the target to check for kernel module directories, which are (usually), only made when a kernel is installed
Target = usr/lib/modules
Unfortunately this did not fire either. I'm not sure how I should go about making this hook, I originally wanted to do Type = Package, Target = linux-*, but this would run on off packages like util-linux-libs, or archlinux-keyring, which I didn't want.
Last edited by Frontear (2023-09-26 21:29:41)
Offline
See how the mkinitcpio hooks do it, that's a better way.
Why, though? Arch kernel filenames don't change, so you set this up once and it's done, redoing the config every time the package is updated seems pointless.
Offline
The mkinitcpio hook uses
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/vmlinuz
Target = usr/lib/initcpio/*
which will cover the cases you'd want.
Edit: F5, F5
Last edited by V1del (2023-09-26 21:03:51)
Offline
See how the mkinitcpio hooks do it, that's a better way.
Why, though? Arch kernel filenames don't change, so you set this up once and it's done, redoing the config every time the package is updated seems pointless.
Upgrade is probably not needed yeah, I just wanted it for situations when I remove/install new kernels and it does it all automatically. I'll peek at the mkini hook, thanks
Offline
The mkinitcpio hook uses
[Trigger] Type = Path Operation = Install Operation = Upgrade Target = usr/lib/modules/*/vmlinuz Target = usr/lib/initcpio/*
which will cover the cases you'd want.
Edit: F5, F5
Thanks for this, it didn't occur to me to check the mkinitcpio hook
Offline
Well this is embarassing. I named the file .conf, and not .hook, so it never actually ever ran because pacman could never read it. Good to know i'm an idiot
Last edited by Frontear (2023-09-26 21:38:17)
Offline