-
Notifications
You must be signed in to change notification settings - Fork 14
/
42_grml
executable file
·162 lines (141 loc) · 4.34 KB
/
42_grml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
# Filename: 42_grml
# Purpose: grub-mkconfig helper script for Grml rescue systems
# Authors: Grml team (grml.org), (c) Andreas Gredler <jimmy@grml.org>, Michael Prokop <mika@grml.org>
# License: This file is licensed under the GPL v2+.
################################################################################
set -e
prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
if [ -r ${libdir}/grub/grub-mkconfig_lib ] ; then
. ${libdir}/grub/grub-mkconfig_lib
elif [ -r /usr/share/grub/grub-mkconfig_lib ] ; then # fallback for e.g. Fedora
. /usr/share/grub/grub-mkconfig_lib
else
echo "Could not locate file grub-mkconfig_lib, please report a bug." >&2
fi
# default unless configured otherwise:
ISO_LOCATION="/boot/grml"
if [ -r /etc/default/grml-rescueboot ] ; then
. /etc/default/grml-rescueboot
fi
resolve_dm_name() {
retval="$1"
base=${1##*/}
for block in /sys/block /sys/class/block ; do
[ ! -d ${block}/${base}/dm ] && continue
retval="/dev/mapper/$(cat ${block}/${base}/dm/name)"
break
done
case "$retval" in
/dev/dm-*)
minor=${retval##*-}
retval="/dev/mapper/$(dmsetup info -C --noheadings -o name -j 253 -m $minor)"
;;
esac
echo "$retval"
}
get_dependencies() {
device=${1}
if [ -z ${device} ] ; then
return
fi
device=$(readlink -f ${device})
case "$device" in
/dev/mapper/*)
device="/dev/dm-$(dmsetup info -C --noheadings -o minor "$device")"
;;
esac
base=${device##*/}
dependencies=""
additional_dependencies=""
for block in /sys/block /sys/class/block ; do
[ ! -d ${block}/${base}/slaves ] && continue
for file in ${block}/${base}/slaves/* ; do
dep_name="/dev/${file##*/}"
dep_name=$(resolve_dm_name ${dep_name})
# resolve recursively all dependencies
additional_dependencies=$(get_dependencies ${dep_name})
dependencies="$dependencies $additional_dependencies $dep_name"
done
break
done
echo $dependencies
}
get_iso_identifier() {
local iso="$1"
local id=
if isoinfo --version >/dev/null 2>&1 ; then
id=$(isoinfo -d -i "${iso}" | grep '^Volume id:' | sed -e 's/^[^:]*: *//')
[ -n "${id}" ] || id=$(isoinfo -d -i "${iso}" | grep '^Application id:' | sed -e 's/^[^:]*: *//')
fi
echo "${id}"
}
iso_list=""
for file in "${ISO_LOCATION}"/*.iso ; do
if grub_file_is_not_garbage "$file" ; then
iso_list="$iso_list $file "
fi
done
indent=' '
submenu_indent=
if [ -n "${GRUB_SUBMENU}" ] && [ -n "${iso_list}" ] ; then
echo "submenu \"${GRUB_SUBMENU}\" \$menuentry_id_option \"grml-rescueboot\" {"
submenu_indent="${indent}"
fi
for grmliso in $iso_list ; do
rel_dirname="$(dirname $(make_system_path_relative_to_its_root $grmliso))"
grml="$(basename $grmliso)"
device="$(${grub_probe} -t device ${grmliso})"
additional_param=""
case "$device" in
/dev/mapper*|/dev/md*)
dependencies=$(get_dependencies ${device})
dep_string=""
for dep in $dependencies $device ; do
case "$dep" in
/dev/md*)
md_name="$(mdadm --detail --export "$dep" | sed -ne 's/MD_NAME=//p')"
dep="/dev/md/$md_name"
esac
dep_string="$dep_string,$dep"
done
dep_string=${dep_string#,}
additional_param="live-media=$dep_string"
;;
esac
echo "Found grml-rescueboot ISO image: ${grmliso}" >&2
iso_id=$(get_iso_identifier "${grmliso}")
if [ -n "${iso_id}" ] ; then
title="${iso_id} (${grml})"
else
title="${grml}"
fi
grub_prep=$(prepare_grub_to_access_device "${device}" | sed -e "s/^/${indent}/")
grub_iso_path="${rel_dirname%/}/${grml}"
sed -e "s/^/${submenu_indent}/" << EOF
menuentry "${title}" {
${grub_prep}
iso_path="${grub_iso_path}"
export iso_path
kernelopts=" $CUSTOM_BOOTOPTIONS $additional_param "
export kernelopts
# support booting recent GRUB versions on UEFI systems
# (see bugs.debian.org/959425)
rmmod tpm
loopback loop "\$iso_path"
set root=(loop)
configfile /boot/grub/loopback.cfg
unset root
loopback -d loop
unset iso_path
unset kernelopts
}
EOF
done
if [ -n "${GRUB_SUBMENU}" ] && [ -n "${iso_list}" ] ; then
echo "} # end submenu \"${GRUB_SUBMENU}\""
fi
## END OF FILE #################################################################