-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrub2_mini-debian.sh
97 lines (79 loc) · 2.51 KB
/
grub2_mini-debian.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh -eu
## Maddes Mini-Debian GRUB release 2 script
if [ -z "${1:-}" ]; then
echo 'ERROR: No parameter given'
return 1 2>/dev/null || exit 1
fi
[ "${1}" = 'oldroot' -o "${1}" = 'mini' ] || { echo 'ERROR: parameter is not "oldroot" or "mini"'; return 1 2>/dev/null || exit 1; }
echo 'NOTE: Mini-Debian must be mounted to work correctly'
prefix='/usr'
exec_prefix="${prefix}"
libdir="${exec_prefix}/lib"
. "${libdir}/grub/grub-mkconfig_lib"
for SRC in /root/bin/luks_OLD*.inc ; do . "${SRC}" ; done
if [ -z "${OLDROOT:-}" ]; then
echo 'missing OLDROOT variable'
return 1 2>/dev/null || exit 1
fi
for SRC in /root/bin/luks_MINIDEB*.inc ; do . "${SRC}" ; done
if [ -z "${MINIDEB:-}" ]; then
echo 'missing MINIDEB variable'
return 1 2>/dev/null || exit 1
fi
if [ -z "$(which linux-boot-prober 2> /dev/null)" ]; then
echo 'missing linux-boot-prober'
return 1 2>/dev/null || exit 1
fi
LINUX="$(linux-boot-prober ${MINIDEB} | head -n 1)"
if [ -z "${LINUX}" ]; then
echo "linux-boot-prober ${MINIDEB} failed"
return 1 2>/dev/null || exit 1
fi
LROOT="$(echo "${LINUX}" | cut -d ':' -f 1)"
LBOOT="$(echo "${LINUX}" | cut -d ':' -f 2)"
LLABEL='Mini-Debian' # fix title
LKERNEL="$(echo "${LINUX}" | cut -d ':' -f 4)"
LINITRD="$(echo "${LINUX}" | cut -d ':' -f 5)"
LPARAMS="$(echo "${LINUX}" | cut -d ':' -f 6- | tr '^' ' ')"
if [ "${1}" = 'oldroot' ]; then
LBOOT="${OLDBOOT:-${OLDROOT}}"
else
LBOOT="${OLDBOOT:-${MINIDEB}}"
fi
if [ -n "${OLDBOOT}" ]; then
LKERNEL="${LKERNEL#/boot}"
LINITRD="${LINITRD#/boot}"
fi
cat > /boot/grub/custom.cfg << __EOF
### BEGIN grub2_mini-debian.sh (for ${1}) ###
menuentry "${LLABEL}" {
__EOF
if [ "${1}" = 'oldroot' ]; then
cat >> /boot/grub/custom.cfg << __EOF
# Make sure that the typical default 0 is booted next time...
set saved_entry=0
${OLDGRUBNOWRITE:+#} save_env saved_entry
unset prev_saved_entry
${OLDGRUBNOWRITE:+#} save_env prev_saved_entry
# ... or directly on problems
set fallback=0
# define Mini-Debian boot entry
__EOF
fi
save_default_entry | sed -e "s/^/\t/" >>/boot/grub/custom.cfg
prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
printf -- '%s\n' "${prepare_boot_cache}" >>/boot/grub/custom.cfg
cat >> /boot/grub/custom.cfg << __EOF
echo 'Loading ${LLABEL} (${1}) ...'
linux ${LKERNEL} ${LPARAMS}
__EOF
if [ -n "${LINITRD}" ]; then
cat >> /boot/grub/custom.cfg << __EOF
echo 'Loading initial ramdisk ...'
initrd ${LINITRD}.mini-debian
__EOF
fi
cat >> /boot/grub/custom.cfg << __EOF
}
### END grub2_mini-debian.sh (for ${1}) ###
__EOF