Skip to content

Commit

Permalink
Improve pacman hook
Browse files Browse the repository at this point in the history
The hook now reacts on updated files instead of updated packages, like
the `mkinitcpio` hook does.

This allows it to be triggered each time a kernel image is updated:
 - when a kernel package is updated (e.g. `linux`);
 - when a dependency is updated (e.g. `systemd`).

This also allows to only rebuild the kernel images that were actually
updated instead of always rebuilding all. The main script now accepts
kernel names as arguments for that.

Files have been renamed to be more consistent with the AUR package.
  • Loading branch information
julienfalque committed Aug 25, 2022
1 parent f31b91a commit 1c323f7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ If your EFI partition is mounted as /boot and your kernels are installed there,
sudo install.sh
```

If not, please edit build_kernel.sh and install it manually. You can do it by running
If not, please edit build_efi_kernel.sh and install it manually. You can do it by running

```
cp build_kernel.sh to /opt
mkdir -p /etc/pacman.d/hooks/
cp kernel-update.hook /etc/pacman.d/hooks
cp build_efi_kernel.sh to /opt
mkdir -p /etc/pacman.d/hooks
cp hook/* /etc/pacman.d/hooks/
```

## EFI boot entries
Expand Down
29 changes: 22 additions & 7 deletions build_kernel.sh → build_efi_kernels.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
#!/bin/bash
#!/bin/bash -e

TARGET=/boot
BOOTDIR=/boot
UCODE=$BOOTDIR/intel-ucode.img
EFISTUB=/usr/lib/systemd/boot/efi/linuxx64.efi.stub

echo "Updating EFI kernels..."
if [[ $# -gt 0 ]]; then
KERNEL_IMAGES=()
for KERNEL in "$@"; do
KERNEL_IMAGE="${BOOTDIR}/vmlinuz-${KERNEL}"

for k in $BOOTDIR/vmlinuz*; do
if [ ! -f "${KERNEL_IMAGE}" ]; then
echo "Kernel \"${KERNEL}\" not available."

exit 1;
fi

KERNEL_IMAGES+=("${KERNEL_IMAGE}")
done
else
KERNEL_IMAGES=($BOOTDIR/vmlinuz*)
fi

for k in "${KERNEL_IMAGES[@]}"; do
NAME=$(basename $k|sed 's/vmlinuz-//')
echo " Building $NAME"
echo "Updating EFI kernel $NAME..."
INITRD="$BOOTDIR/initramfs-$NAME.img"

if [ -f "$UCODE" ]; then
cat "$UCODE" "$INITRD" > /tmp/initrd.bin
INITRDFILE=/tmp/initrd.bin
else
# Do not fail on AMD systems
echo " Intel microcode not found. Skipping."
echo " Intel microcode not found. Skipping."
INITRDFILE="$INITRD"
fi

# Check for custom command line for the kernel.
CMDLINE="$BOOTDIR/cmdline-$NAME.txt"
if [ -f "$CMDLINE" ]; then
echo " Using custom command line $CMDLINE"
echo " Using custom command line $CMDLINE"
else
CMDLINE="$BOOTDIR/cmdline.txt"
if [ ! -f "$CMDLINE" ]; then
echo "CMDLINE missing. Extracting from running kernel..."
echo " CMDLINE missing. Extracting from running kernel..."
cat /proc/cmdline |sed 's/BOOT_IMAGE=[^ ]* \?//' > "$CMDLINE"
fi
fi
Expand Down
12 changes: 12 additions & 0 deletions hook/efi-kernel-update.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Trigger]
Type = Path
Operation = Upgrade
Operation = Install
Target = usr/lib/modules/*/vmlinuz
Target = usr/lib/initcpio/*

[Action]
Description = Updating EFI kernel images
When = PostTransaction
Exec = /etc/pacman.d/hooks/efi-kernel-update.sh
NeedsTargets
17 changes: 17 additions & 0 deletions hook/efi-kernel-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

while read -r updated_file; do
if [[ $updated_file == usr/lib/initcpio/* ]]; then
# all kernels images have been updated
build_efi_kernels

break
fi

pkgbase_file="${updated_file%/vmlinuz}/pkgbase"
if ! read -r kernel > /dev/null 2>&1 < "${pkgbase_file}"; then
continue
fi

build_efi_kernels "${kernel}"
done
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi

cp build_kernel.sh /opt/
cp build_efi_kernels.sh /opt/
mkdir -p /etc/pacman.d/hooks
cp kernel-update.hook /etc/pacman.d/hooks/
cp hooks/* /etc/pacman.d/hooks/

echo "Install completed. Building kernels..."

Expand Down
11 changes: 0 additions & 11 deletions kernel-update.hook

This file was deleted.

0 comments on commit 1c323f7

Please sign in to comment.