-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrub1_mini-debian.sh
84 lines (73 loc) · 2.7 KB
/
grub1_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
#!/bin/sh -eu
## Maddes Mini-Debian GRUB release 1 script
for SRC in /root/bin/luks_OLD*.inc ; do . "${SRC}" ; done
if [ -z "${OLDROOT:-}" ]; then
echo 'ERROR: missing OLDROOT variable'
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
if [ -z "${OLDGRUB1DEFAULT:-}" ]; then
echo 'ERROR: missing OLDGRUB1 default variable'
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
for SRC in /root/bin/luks_MINIDEB*.inc ; do . "${SRC}" ; done
if [ -z "${MINIDEB:-}" ]; then
echo 'ERROR: missing MINIDEB partition variable'
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
if [ -z "${MINIOLDGRUB1DEFAULT:-}" ]; then
echo 'ERROR: missing MINIGRUB1 default variable'
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
case "$(pwd)" in
(/boot|/boot/*) echo 'ERROR: os-prober needs /boot unmounted, leave /boot via cd ${HOME}'
return 1 2>/dev/null || exit 1
printf -- '\a'
;;
esac
if [ -z "$(which linux-boot-prober 2> /dev/null)" ]; then
echo 'ERROR: missing linux-boot-prober'
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
[ -z "${OLDBOOT:-}" ] || umount /boot
LINUX="$(linux-boot-prober ${MINIDEBMOUNT} | head -n 1)"
[ -z "${OLDBOOT}" ] || mount -a
if [ -z "${LINUX}" ]; then
echo "ERROR: linux-boot-prober ${MINIDEBMOUNT} failed"
printf -- '\a'
return 1 2>/dev/null || exit 1
fi
if [ "${OLDGRUB1DEFAULT}" = 'saved' -a "${OLDGRUB1SAVED}" = 'default' ]; then
echo 'ERROR: GRUB 1 default is set to "saved" and saved value is "default"'
printf -- '\a'
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 '^' ' ')"
# fix problems of linux-boot-prober on Debian 4.0 "Etch"
if [ -n "${OLDBOOT:-}" ]; then
LKERNEL="$(echo "${LKERNEL}" | sed -e 's#/boot/#/#')"
LINITRD="$(echo "${LINITRD}" | sed -e 's#/boot/#/#')"
LPARAMS="$(echo "${LPARAMS}" | sed -e "s#UUID=${OLDROOTUUID}#UUID=${MINIDEBUUID}#" -e "s#\(${OLDROOT}\|${OLDROOTMOUNT}\)#${MINIDEBMOUNT}#")"
fi
cat > /boot/grub/custom.mini-debian.oldroot.cfg << __EOF
### BEGIN grub1_mini-debian.sh ###
title ${LLABEL}
# FIXME: set to previous default plus 1 (normally 0 plus 1 = 1)
savedefault ${MINIOLDGRUB1DEFAULT}
# FIXME: set correct value for ${OLDGRUB}, partition is minus 1
root (${OLDGRUB1DEV},${OLDGRUB1PART})
# FIXME: set correct root value for ${MINIDEBMOUNT}, no /boot prefix if separate boot partition
kernel ${LKERNEL} ${LPARAMS}
# FIXME: no /boot prefix if separate boot partition
initrd ${LINITRD}.mini-debian
### END grub1_mini-debian.sh ###
__EOF