blob: 37355249166c68551bc2d40caf3a33d6a1101d9a (
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
54
55
56
57
|
#!/bin/bash
set -e
echo ">>> [fix-bootentry] Running INSIDE target system"
ENTRYDIR="/boot/loader/entries"
[ -d "${ENTRYDIR}" ] || { echo ">>> [fix-bootentry] No ${ENTRYDIR}, skipping."; exit 0; }
ROOT_UUID="$(findmnt -no UUID / || true)"
if [ -z "${ROOT_UUID}" ]; then
ROOT_UUID="$(awk '$2 == "/" && $1 ~ /^UUID=/ {print $1; exit}' /etc/fstab | sed 's/^UUID=//')"
fi
if [ -z "${ROOT_UUID}" ]; then
echo ">>> [fix-bootentry] Could not determine root UUID, leaving entries untouched."
exit 0
fi
SWAP_UUID="$(awk '$3 == "swap" && $1 ~ /^UUID=/ {print $1; exit}' /etc/fstab | sed 's/^UUID=//')"
ROOT_OPTS="$(awk '$2 == "/" {print $4; exit}' /etc/fstab)"
SUBVOL="$(echo "$ROOT_OPTS" | tr ',' '\n' | grep '^subvol=' | head -1 || true)"
echo ">>> [fix-bootentry] root UUID: ${ROOT_UUID} | swap UUID: ${SWAP_UUID:-nincs} | subvol: ${SUBVOL:-nincs}"
for f in "${ENTRYDIR}"/*.conf; do
[ -f "$f" ] || continue
grep -qE '^options[[:space:]]' "$f" || continue
if grep -qE '^options[[:space:]].*\broot=' "$f"; then
sed -i -E "s#root=[^[:space:]]*#root=UUID=${ROOT_UUID}#" "$f"
else
sed -i -E "s#^options[[:space:]]+#options root=UUID=${ROOT_UUID} #" "$f"
fi
if [ -n "${SWAP_UUID}" ]; then
if grep -qE '\bresume=' "$f"; then
sed -i -E "s#resume=[^[:space:]]*#resume=UUID=${SWAP_UUID}#" "$f"
else
sed -i -E "s#^(options[[:space:]].*)#\1 resume=UUID=${SWAP_UUID}#" "$f"
fi
else
sed -i -E "s#[[:space:]]+resume=[^[:space:]]*##g" "$f"
fi
if [ -n "${SUBVOL}" ]; then
if grep -qE '\brootflags=subvol=' "$f"; then
sed -i -E "s#rootflags=subvol=[^[:space:]]*#rootflags=${SUBVOL}#" "$f"
else
sed -i -E "s#^(options[[:space:]].*)#\1 rootflags=${SUBVOL}#" "$f"
fi
fi
echo ">>> [fix-bootentry] Fixed: $f"
done
echo ">>> [fix-bootentry] Done."
exit 0
|