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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
#!/bin/sh
#
# Copyright © 2006-2007 Martin F. Krafft <madduck@debian.org>
# based on the scripts in the initramfs-tools package.
# released under the terms of the Artistic Licence.
#
# $Id$
#
set -eu
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case ${1:-} in
prereqs)
prereqs
exit 0
;;
esac
is_true()
{
case "${1:-}" in
[Yy]es|[Yy]|1|[Tt]rue|[Tt]) return 0;;
*) return 1;
esac
}
write()
{
local PREFIX; PREFIX=$1; shift
echo "${PREFIX}: mdadm: $@" >&2
}
info()
{
is_true ${VERBOSE:-false} && write I "$@" || :
}
warn()
{
write W "$@"
}
err()
{
write E "$@"
}
if [ -e /usr/share/initramfs-tools/hooks/md ]; then
warn "initramfs md hook still present, stepping out of its way."
warn "Please see /usr/share/doc/mdadm/README.initramfs-transition ."
exit 0
fi
if [ -e /etc/initramfs-tools/hooks/md ]; then
warn "I found /etc/initramfs-tools/hooks/md, which may conflict"
warn "with this version of mdadm. Please see /usr/share/doc/mdadm/README.mdrun"
warn "and /usr/share/initramfs-tools/hooks/mdadm for reference and update"
warn "(or remove) the file."
exit 0
fi
MDADM=/sbin/mdadm
[ -x "$MDADM" ] || exit 0
[ -r /usr/share/initramfs-tools/hook-functions ] || exit 0
. /usr/share/initramfs-tools/hook-functions
# copy the binary as early as possible
copy_exec $MDADM /sbin
# copy all modules into the initramfs, just for safety.
# we copy raid456 / raid5+raid6 because the hook script just won't do
# anything when the module cannot be found.
modules="linear multipath raid0 raid1 raid456 raid5 raid6 raid10"
for mod in $modules; do manual_add_modules $mod; done
# read in the configuration
CONFIG=/etc/mdadm/mdadm.conf
ALTCONFIG=/etc/mdadm.conf
[ ! -f $CONFIG ] && [ -f $ALTCONFIG ] && CONFIG=$ALTCONFIG || :
DEBIANCONFIG=/etc/default/mdadm
INITRDSTART=all
[ -s $DEBIANCONFIG ] && . $DEBIANCONFIG
[ -z "$INITRDSTART" ] && INITRDSTART=none
DESTMDADMCONF=$DESTDIR/etc/mdadm/mdadm.conf
DESTCONFIG=$DESTDIR/conf/md.conf
# save the homehost for now, even if we don't use it yet
if [ -f $CONFIG ]; then
homehost="$(sed -ne 's,^[[:space:]]*HOMEHOST[[:space:]]*,,p' $CONFIG)"
fi
if [ -z "${homehost:-}" ] || [ "${homehost:-}" = '<system>' ]; then
homehost="$(hostname)"
fi
echo "MD_HOMEHOST='$homehost'" > $DESTCONFIG
install_config()
{
# install the configuration file
mkdir -p ${2%/*}
# only copy ARRAY and DEVICE lines, and merge continuation lines into one
sed -e :a -re '$!N;s/\n[[:space:]]+/ /;ta' -ne '/^(ARRAY|DEVICE)/P;D' $1 > $2
}
if [ ! -f $CONFIG ]; then
# there is no configuration file, so let's create one
if /usr/share/mdadm/mkconf generate $CONFIG; then
# all is well
install_config $CONFIG $DESTMDADMCONF
info "auto-generated the mdadm.conf configuration file."
else
# we failed to auto-generate, so let the emergency procedure take over
warn "failed to auto-generate the mdadm.conf file."
warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ."
fi
else
use_temp=0
if [ -e /var/lib/mdadm/CONF-UNCHECKED ]; then
# the file comes from an old installation and hence is not guaranteed to
# work. We thus better create one and start all arrays to be sure.
warn "unchecked configuration file: $CONFIG"
warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ."
use_temp=1
elif ! grep -q '^ARRAY' $CONFIG; then
# the file defines no ARRAYs. We better create a temporary file to be
# sure.
warn "$CONFIG defines no arrays."
use_temp=1
else
# this is the ideal case
install_config $CONFIG $DESTMDADMCONF
info "using configuration file: $CONFIG"
fi
if [ $use_temp -eq 1 ]; then
mkdir --parents ${DESTMDADMCONF%/*}
tmpfile="${DESTMDADMCONF}.tmp"
if /usr/share/mdadm/mkconf > $tmpfile; then
# all is well, we now have a temporary configuration file
info "auto-generated temporary mdadm.conf configuration file."
install_config $tmpfile $DESTMDADMCONF
else
# stuff's really broke, as we failed to generate a temporary file.
# let's hope the unchecked file works, provided it contains at least one
# ARRAY statement...
warn "failed to auto-generate temporary mdadm.conf file."
if grep -q '^ARRAY' $CONFIG; then
warn "using the unchecked file and hoping for the best..."
install_config $CONFIG $DESTMDADMCONF
fi
fi
rm -f $tmpfile
fi
fi
# if at this point, $DESTMDADMCONF does not exist or it does not contain any
# ARRAY statements, we must let the initramfs handle stuff.
if [ ! -f $DESTMDADMCONF ]; then
warn "no configuration file available."
warn "falling back to emergency procedure in initramfs."
exit 0
elif ! grep -q '^ARRAY' $DESTMDADMCONF; then
warn "no arrays defined in configuration file."
warn "falling back to emergency procedure in initramfs."
exit 0
else
# obtain dev:level pairs from config file, honouring multiline entries
devpairs="$(
while read line; do
case "$line" in
(ARRAY*) :;;
(*) continue;;
esac
for atom in $line; do
case "$atom" in
(/dev*) dev=$atom;;
(level=raid*|level=linear|level=multipath) level=${atom#level=};;
(level=*)
err "invalid level specified in ARRAY statement in $CONFIG:"
err " $line"
err "levels should be either raid*, linear, or multipath."
warn "falling back to emergency procedure in initramfs."
exit 1
;;
(*) :;;
esac
done
[ -n "${dev:-}" ] || continue
echo -n "${dev}:"
if [ -n "${level:-}" ]; then
echo -n "$level"
else
echo -n "$($MDADM --detail $dev | sed -rne 's,[[:space:]]+Raid Level : ,,p')"
fi
echo -n ' '
done < $DESTMDADMCONF)" || exit $?
fi
uniquify()
{
for i in $@; do echo "$i"; done | sort -u
}
if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then
echo "MD_DEVPAIRS='${devpairs% }'" >> $DESTCONFIG
devs=''; levels=''
for i in $devpairs; do
dev=${i%:*}
level=${i##*:}
case "$INITRDSTART" in
all|*${dev}*)
devs="${devs:+$devs }$dev"
levels="${levels:+$levels }$level"
;;
*) :;;
esac
done
for i in $INITRDSTART; do
case "$INITRDSTART" in all|none|'') break;; *) :;; esac
case "$devs" in
*${i}*) continue;;
*) :;;
esac
warn "I am supposed to start $i from the initial ramdisk,"
warn "yet I cannot find the array in the configuration file."
warn "I am thus reverting to starting all arrays."
INITRDSTART=all
break
done
echo "MD_LEVELS='$levels'" >> $DESTCONFIG
if [ "$INITRDSTART" = all ]; then
echo "MD_DEVS=all" >> $DESTCONFIG
else
echo "MD_DEVS='$devs'" >> $DESTCONFIG
fi
# raid4 is handled by raid5
modules="$(echo $levels | sed -e 's,raid4,raid5,g')"
# if raid456 module is present, use it for raid[456]
modprobe --set-version="$version" --show-depends raid456 >/dev/null 2>&1 \
&& modules="$(echo $modules | sed -e 's,raid[456],raid456,g')"
modules="$(uniquify $modules | tr '\n' ' ')"
echo "MD_MODULES='${modules% }'" >> $DESTCONFIG
if [ "$INITRDSTART" = all ]; then
info "will start all available MD arrays from the initial ramdisk."
else
for i in $devs; do
info "will start MD array $i from the initial ramdisk."
done
fi
else
echo "MD_DEVS=none" >> $DESTCONFIG
echo "MD_MODULES=''" >> $DESTCONFIG
info "no MD arrays will be started from the initial ramdisk."
fi
# only output this on Debian systems
[ -s /etc/default/mdadm ] && \
info 'use `dpkg-reconfigure --priority=low mdadm` to change this.'
exit 0
|