-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild_kernel.sh
executable file
·42 lines (36 loc) · 1.21 KB
/
build_kernel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
TARGET=/boot
BOOTDIR=/boot
UCODE=$BOOTDIR/intel-ucode.img
EFISTUB=/usr/lib/systemd/boot/efi/linuxx64.efi.stub
echo "Updating EFI kernels..."
for k in $BOOTDIR/vmlinuz*; do
NAME=$(basename $k|sed 's/vmlinuz-//')
echo " Building $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."
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"
else
CMDLINE="$BOOTDIR/cmdline.txt"
if [ ! -f "$CMDLINE" ]; then
echo "CMDLINE missing. Extracting from running kernel..."
cat /proc/cmdline |sed 's/BOOT_IMAGE=[^ ]* \?//' > "$CMDLINE"
fi
fi
objcopy \
--add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=0x20000 \
--add-section .cmdline="$CMDLINE" --change-section-vma .cmdline=0x30000 \
--add-section .linux="$k" --change-section-vma .linux=0x40000 \
--add-section .initrd="$INITRDFILE" --change-section-vma .initrd=0x3000000 \
"$EFISTUB" "$TARGET/$NAME.efi"
done