diff --git a/README.md b/README.md index c82d57e..6bc04f0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build_kernel.sh b/build_efi_kernels.sh similarity index 64% rename from build_kernel.sh rename to build_efi_kernels.sh index 26af513..5084202 100755 --- a/build_kernel.sh +++ b/build_efi_kernels.sh @@ -1,15 +1,30 @@ -#!/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 @@ -17,18 +32,18 @@ for k in $BOOTDIR/vmlinuz*; do 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 diff --git a/hook/efi-kernel-update.hook b/hook/efi-kernel-update.hook new file mode 100644 index 0000000..77c8c08 --- /dev/null +++ b/hook/efi-kernel-update.hook @@ -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 diff --git a/hook/efi-kernel-update.sh b/hook/efi-kernel-update.sh new file mode 100755 index 0000000..e7a80c7 --- /dev/null +++ b/hook/efi-kernel-update.sh @@ -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 diff --git a/install.sh b/install.sh index 558e9cd..24e79ce 100755 --- a/install.sh +++ b/install.sh @@ -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..." diff --git a/kernel-update.hook b/kernel-update.hook deleted file mode 100644 index 6eadebf..0000000 --- a/kernel-update.hook +++ /dev/null @@ -1,11 +0,0 @@ -[Trigger] -Type = Package -Operation = Upgrade -Operation = Install -Target = linux* -Target = intel-ucode - -[Action] -Description = Updating EFI kernel images -When = PostTransaction -Exec = /bin/bash /opt/build_kernel.sh