Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pacman hook #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = Install
Operation = Upgrade
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.