blob: 8d5c26e14ac843549db210d9d71a6751d9c21893 (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
|
#!/bin/bash
set -e
echo ">>> [microcode-fix] Running INSIDE target system"
VENDOR=$(awk -F: '/vendor_id/ {print $2; exit}' /proc/cpuinfo | xargs)
echo ">>> [microcode-fix] Detected CPU vendor: ${VENDOR}"
if [[ "${VENDOR}" == "GenuineIntel" ]]; then
PKG="intel-ucode"
UCODE_IMG="/boot/intel-ucode.img"
UCODE_LINE="initrd /intel-ucode.img"
elif [[ "${VENDOR}" == "AuthenticAMD" ]]; then
PKG="amd-ucode"
UCODE_IMG="/boot/amd-ucode.img"
UCODE_LINE="initrd /amd-ucode.img"
else
echo ">>> [microcode-fix] Unknown vendor, skipping."
exit 0
fi
echo ">>> [microcode-fix] Installing microcode package: ${PKG}"
pacman -Sy --noconfirm "${PKG}" || true
if [ ! -f "${UCODE_IMG}" ]; then
echo ">>> [microcode-fix] Missing ${UCODE_IMG}, skipping entry patch."
exit 0
fi
ENTRYDIR="/boot/loader/entries"
echo ">>> [microcode-fix] Entry dir: ${ENTRYDIR}"
[ -d "${ENTRYDIR}" ] || exit 0
for f in "${ENTRYDIR}"/*.conf; do
[ -f "$f" ] || continue
echo ">>> [microcode-fix] Patching: $f"
if grep -qE '^initrd[[:space:]]+/amd-ucode\.img$' "$f" || grep -qE '^initrd[[:space:]]+/intel-ucode\.img$' "$f"; then
echo ">>> [microcode-fix] Already has microcode initrd, skipping: $f"
continue
fi
tmp="$(mktemp)"
{
echo "${UCODE_LINE}"
cat "$f"
} > "$tmp"
cat "$tmp" > "$f"
rm -f "$tmp"
done
echo ">>> [microcode-fix] Done."
|