-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernal-param-gen.sh
More file actions
executable file
·55 lines (48 loc) · 1.44 KB
/
kernal-param-gen.sh
File metadata and controls
executable file
·55 lines (48 loc) · 1.44 KB
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
54
55
#!/usr/bin/env bash
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
echo "Kernel updated at $(date)" >> /var/log/kernel-update.log
scaling_f="/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"
pstate_supported=false
driver=""
if [ -d /sys/devices/system/cpu/intel_pstate ]; then
driver="intel_pstate"
pstate_supported=true
elif [ -d /sys/devices/system/cpu/amd_pstate ] || [ -d /sys/devices/system/cpu/amd-pstate ]; then
# kernel docs and kernels may expose amd_pstate/amd-pstate; accept either
driver="amd_pstate"
pstate_supported=true
elif [ -r "$scaling_f" ]; then
# fallback: read scaling_driver and normalise
rawdrv=$(cat "$scaling_f" 2>/dev/null || true)
case "$rawdrv" in
*intel*)
driver="intel_pstate"
pstate_supported=true
;;
*amd*)
driver="amd_pstate"
pstate_supported=true
;;
*) driver="$rawdrv" ;;
esac
fi
pstate_param=""
if [ "$pstate_supported" = true ]; then
if [ "$driver" = "intel_pstate" ]; then
pstate_param="intel_pstate=active"
elif [ "$driver" = "amd_pstate" ]; then
pstate_param="amd_pstate=active"
fi
fi
extra_params="fsck.repair=yes zswap.enabled=0"
[ -n "$pstate_param" ] && extra_params="$extra_params $pstate_param"
for f in /boot/efi/loader/entries/*; do
opts=$(sed -n 's/^options[[:space:]]\+//p' "$f")
for p in $extra_params; do
echo "$opts" | grep -Fq "$p" ||
sed -i "/^options[[:space:]]\+/ s/$/ $p/" "$f"
done
done