1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: init 2484 2009-11-14 23:44:19Z bruno $
|
---|
4 | #
|
---|
5 | # init script launched during the restore process
|
---|
6 | #------------------------------------------------------------
|
---|
7 |
|
---|
8 |
|
---|
9 | CaughtSoftReset() {
|
---|
10 | trap SIGTERM
|
---|
11 | reboot
|
---|
12 | }
|
---|
13 |
|
---|
14 |
|
---|
15 | ConfigureLoggingDaemons() {
|
---|
16 | echo -en "Running klogd..."
|
---|
17 | klogd -c 2 > /dev/null 2> /dev/null
|
---|
18 | echo -en "Done.\nRunning syslogd..."
|
---|
19 | syslogd > /dev/null 2> /dev/null
|
---|
20 | echo "Done."
|
---|
21 | LogIt "klogd and syslogd have been started."
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 | CopyBootDevEntry() {
|
---|
27 | local outfile devfile
|
---|
28 | devfile=/dev/boot_device
|
---|
29 | outfile=`cat /BOOTLOADER.DEVICE 2> /dev/null`
|
---|
30 | [ ! "$outfile" ] && return 0
|
---|
31 | echo -en "Copying boot device to $outfile..."
|
---|
32 | if [ -e "$outfile" ] ; then
|
---|
33 | echo "not needed."
|
---|
34 | return 0
|
---|
35 | fi
|
---|
36 | mkdir -p $outfile
|
---|
37 | rmdir $outfile
|
---|
38 | cp -pRdf $devfile $outfile
|
---|
39 | if [ "$?" -ne "0" ] ; then
|
---|
40 | echo "Failed."
|
---|
41 | return 1
|
---|
42 | else
|
---|
43 | echo "OK."
|
---|
44 | return 0
|
---|
45 | fi
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | Die() {
|
---|
51 | LogIt "Fatal error! $1" 1
|
---|
52 | exit 1
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | ExtractDevTarballs() {
|
---|
58 | cd /
|
---|
59 | for fname in ataraid.tgz ida.tgz i2o.tgz rd.tgz raw.tgz cciss.tgz nst.tgz dm.tgz vc.tgz ; do
|
---|
60 | if [ ! -e "/$fname" ] ; then
|
---|
61 | LogIt "/$fname not found; cannot extract to /." 1
|
---|
62 | else
|
---|
63 | echo -en "\rExtracting /$fname... "
|
---|
64 | tar -zxf /$fname || LogIt "Error occurred while extracting /$fname"
|
---|
65 | fi
|
---|
66 | done
|
---|
67 | echo -en "\r"
|
---|
68 | LogIt "Extracted additional /dev entries OK. " 1
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 | LaunchTerminals() {
|
---|
74 | openvt 2 /bin/sh
|
---|
75 | openvt 3 /bin/sh
|
---|
76 | openvt 4 /bin/sh
|
---|
77 | openvt 5 /bin/sh
|
---|
78 | openvt 6 /bin/sh
|
---|
79 | openvt 7 /bin/sh /sbin/wait-for-petris
|
---|
80 | openvt 8 /usr/bin/tail -f $LOGFILE
|
---|
81 | # May avoid shell error messages
|
---|
82 | chmod 666 /dev/tty* /dev/console
|
---|
83 | # By default first serial line is configured as tty
|
---|
84 | # Required to have a correct serial console support (MP on ia64 or VSP with iLO2 e.g.)
|
---|
85 | serial=/dev/ttyS0
|
---|
86 | for i in `cat /proc/cmdline` ; do
|
---|
87 | echo $i | grep -qi serial= && serial=`echo $i | cut -d= -f2`
|
---|
88 | done
|
---|
89 | ln -s -f $serial /dev/tty
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | LoadKeymap() {
|
---|
94 | local fname
|
---|
95 | fname=`cat /tmp/KEYMAP-LIVES-HERE 2> /dev/null`
|
---|
96 | [ "$fname" = "" ] && return
|
---|
97 | if which loadkeys > /dev/null 2> /dev/null ; then
|
---|
98 | loadkeys $fname
|
---|
99 | # loadkmap != loadkeys
|
---|
100 | # elif which loadkmap > /dev/null 2> /dev/null ; then
|
---|
101 | # loadkmap < $fname
|
---|
102 | else
|
---|
103 | LogIt "Using default keyboard map." 1
|
---|
104 | fi
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | UntarTapeStuff() {
|
---|
109 | local old_pwd res
|
---|
110 | old_pwd=`pwd`
|
---|
111 | cd $GROOVY
|
---|
112 | [ "$1" != "" ] && tapedev=$1
|
---|
113 | [ ! "$tapedev" ] && tapedev=`grep media-dev /tmp/mondo-restore.cfg 2>/dev/null | tr -s ' ' ' ' | cut -d' ' -f2`
|
---|
114 | mt -f $tapedev rewind
|
---|
115 | mt -f $tapedev fsf 2
|
---|
116 | dd if=$tapedev bs=32k count=1024 | tar -zx
|
---|
117 | res=$?
|
---|
118 | if [ "$res" -eq "0" ] ; then
|
---|
119 | # Store the dev name in case we changed it interactively
|
---|
120 | if [ -f "/tmp/mondo-restore.cfg" ]; then
|
---|
121 | sed -i "s/^media-dev .*$/media-dev $tapedev/" /tmp/mondo-restore.cfg
|
---|
122 | fi
|
---|
123 | fi
|
---|
124 | cd $old_pwd
|
---|
125 | return $res
|
---|
126 | }
|
---|
127 |
|
---|
128 | HandleTape() {
|
---|
129 | local res tapedev
|
---|
130 | tapedev="" ; # will be set by UntarTapeStuff()
|
---|
131 |
|
---|
132 | # Here we can add the USB storage module, it's working even with OBDR !
|
---|
133 | modprobe -q usb-storage
|
---|
134 | # Tape takes some time to appear
|
---|
135 | sleep 10
|
---|
136 | cd $GROOVY
|
---|
137 | UntarTapeStuff $tapedev
|
---|
138 | res=$?
|
---|
139 | while [ "$res" -ne "0" ] ; do
|
---|
140 | LogIt "$tapedev failed to act as extended data disk for booting." 1
|
---|
141 | LogIt "Please specify an alternate tape device," 1
|
---|
142 | LogIt "or hit <Enter> to boot from another media." 1
|
---|
143 | echo -en "---> "
|
---|
144 | read tapedev
|
---|
145 | if [ "$tapedev" ] ; then
|
---|
146 | LogIt "User specified $tapedev instead"
|
---|
147 | UntarTapeStuff $tapedev
|
---|
148 | res=$?
|
---|
149 | else
|
---|
150 | LogIt "User opted not to specify an alternate tapedev"
|
---|
151 | res=1
|
---|
152 | break
|
---|
153 | fi
|
---|
154 | done
|
---|
155 | # For post-init
|
---|
156 | export TAPEDEV=$tapedev
|
---|
157 |
|
---|
158 | if [ "$res" -ne "0" ] ; then
|
---|
159 | cd /
|
---|
160 | LogIt "Failed to use tape as extended datadisk. Reverting to another media." 1
|
---|
161 | HandleCDROM
|
---|
162 | res=$?
|
---|
163 | else
|
---|
164 | LogIt "Using tape as extended datadisk. Good." 3
|
---|
165 | echo "Using tape as extd ddisk." > /tmp/TAPEDEV-HAS-DATA-DISKS
|
---|
166 | res=0
|
---|
167 | CD_MOUNTED_OK=yes
|
---|
168 | fi
|
---|
169 | return $res
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 | HandleCDROM() {
|
---|
175 | # Just in case we have an iLO ensure we will map it correctly
|
---|
176 | echo "$DENY_MODS" | grep -q "usb-storage "
|
---|
177 | if [ $? -eq 0 ]; then
|
---|
178 | return
|
---|
179 | fi
|
---|
180 | echo "Activating a potential USB Storage device"
|
---|
181 | modprobe -q usb-storage
|
---|
182 | for i in 1 2 3 4 5 6 7 8 9 10 ; do
|
---|
183 | sleep 1
|
---|
184 | echo -en "."
|
---|
185 | done
|
---|
186 |
|
---|
187 | find-and-mount-cdrom
|
---|
188 | res=$?
|
---|
189 | if [ "$res" -ne "0" ] ; then
|
---|
190 | LogIt "First call to find-and-mount-cdrom failed." 1
|
---|
191 | LogIt "Sleeping for 3 seconds and trying again." 1
|
---|
192 | sleep 3
|
---|
193 | find-and-mount-cdrom
|
---|
194 | res=$?
|
---|
195 | fi
|
---|
196 | if [ "$res" -eq "0" ] ; then
|
---|
197 | LogIt "OK, I am running on a CD-ROM. Good." 3
|
---|
198 | CD_MOUNTED_OK=yes
|
---|
199 | else
|
---|
200 | LogIt "You probably not have the right drivers" 3
|
---|
201 | LogIt "to support the hardware on which we are running" 3
|
---|
202 | LogIt "Your archives are probably fine but" 3
|
---|
203 | LogIt "your tape streamer and/or CD-ROM drive are unsupported at that point." 3
|
---|
204 | CD_MOUNTED_OK=""
|
---|
205 | fi
|
---|
206 | return 0
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | PauseForRaids() {
|
---|
211 | if [ "`dmesg | grep -i "RAID Controller"`" != "" ] || [ "`dmesg | grep -i "Vendor: 3ware"`" != "" ] ; then
|
---|
212 | LogIt "RAID controller(s) detected. Pausing 10 seconds to let them warm up." 1
|
---|
213 | echo -en "Pausing..."
|
---|
214 | for i in 1 2 3 4 5 6 7 8 9 10 ; do
|
---|
215 | sleep 1
|
---|
216 | echo -en "$(($i*10))%..."
|
---|
217 | done
|
---|
218 | echo "Done."
|
---|
219 | fi
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | # 06/13/2002 --- DuckX's & Hugo's new routine
|
---|
224 | # 10/11/2003 --- added a simple devfsd.conf file
|
---|
225 | # 01/24/2005 --- cater for arbitrary locations of devfsd.conf by using the
|
---|
226 | # config file path compiled into devfsd
|
---|
227 | RunDevfsd() {
|
---|
228 | loc=`which devfsd 2> /dev/null`
|
---|
229 | if [ "$loc" != "" ] ; then
|
---|
230 | LogIt "Devfs found. Testing kernel support..."
|
---|
231 | if [ ! -e "/dev/.devfsd" ] ; then
|
---|
232 | mount -t devfs devfs /dev 2>> $LOGFILE
|
---|
233 | if [ "$?" -ne "0" ] ; then
|
---|
234 | LogIt "Error while trying to mount devfs"
|
---|
235 | else
|
---|
236 | LogIt "Devfs mounted OK"
|
---|
237 | fi
|
---|
238 | fi
|
---|
239 | #check if the kernel supports devfs
|
---|
240 | if [ -e "/dev/.devfsd" ] ; then
|
---|
241 | [ -d "/proc/1" ] || mount -n /proc
|
---|
242 | LogIt "Kernel support found. Creating config file and starting devfsd"
|
---|
243 | conffile=`strings $loc | grep -E "devfsd.conf$"`
|
---|
244 | [ "$conffile" ] || conffile="/etc/devfsd.conf"
|
---|
245 | confpath=`echo $conffile | sed "s/\/devfsd\.conf$//"`
|
---|
246 | [ -d "$confpath" ] || mkdir -p $confpath
|
---|
247 | echo -en "REGISTER .* MKOLDCOMPAT\nUNREGISTER .* RMOLDCOMPAT\n" > $conffile
|
---|
248 | devfsd /dev &
|
---|
249 | sleep 5
|
---|
250 | else
|
---|
251 | LogIt "No devfs kernel support."
|
---|
252 | fi
|
---|
253 | fi
|
---|
254 | }
|
---|
255 |
|
---|
256 | # Taken from udev management in Mandriva 2008.0. Kudos guys
|
---|
257 | make_extra_nodes () {
|
---|
258 | # there are a few things that sysfs does not export for us.
|
---|
259 | # these things are listed in /etc/udev/links.conf
|
---|
260 | grep '^[^#]' /etc/udev-links.conf | \
|
---|
261 | while read type name arg1; do
|
---|
262 | [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue
|
---|
263 | case "$type" in
|
---|
264 | L) ln -s $arg1 /dev/$name ;;
|
---|
265 | D) mkdir -p /dev/$name ;;
|
---|
266 | M) mknod /dev/$name $arg1 && chmod 600 /dev/$name;;
|
---|
267 | *) echo "udev-links.conf: unparseable line (%s %s %s)\n" "$type" "$name" "$arg1" ;;
|
---|
268 | esac
|
---|
269 | done
|
---|
270 | }
|
---|
271 |
|
---|
272 | create_dev_makedev() {
|
---|
273 | if [ -e /sbin/MAKEDEV ]; then
|
---|
274 | ln -sf /sbin/MAKEDEV /dev/MAKEDEV
|
---|
275 | else
|
---|
276 | ln -sf /bin/true /dev/MAKEDEV
|
---|
277 | fi
|
---|
278 | }
|
---|
279 |
|
---|
280 | RunUdevd() {
|
---|
281 | # Inspiration from Mandriva 2008.0 startup script
|
---|
282 | echo "Preparing udev environment..."
|
---|
283 | mv /dev /dev.static
|
---|
284 | mkdir /dev
|
---|
285 | mount -n -o size=5M,mode=0755 -t tmpfs none /dev
|
---|
286 | make_extra_nodes
|
---|
287 | mount -n -t devpts -o mode=620 none /dev/pts
|
---|
288 | mount -n -t tmpfs none /dev/shm
|
---|
289 | if [ -e /proc/sys/kernel/hotplug ]; then
|
---|
290 | echo > /proc/sys/kernel/hotplug
|
---|
291 | fi
|
---|
292 | PKLVL=`cut -f1 /proc/sys/kernel/printk`
|
---|
293 | echo 0 > /proc/sys/kernel/printk
|
---|
294 | # Many possibilities depending on udev versions
|
---|
295 | if [ -x /sbin/startudev ]; then
|
---|
296 | /sbin/startudev
|
---|
297 | fi
|
---|
298 | if [ -x /sbin/start_udev ]; then
|
---|
299 | /sbin/start_udev
|
---|
300 | fi
|
---|
301 | # Depending on udevd version it gives back the hand or not :-(
|
---|
302 | ps | grep udevd 2> /dev/null 1> /dev/null
|
---|
303 | if [ $? -ne 0 ]; then
|
---|
304 | /sbin/udevd --daemon &
|
---|
305 | echo "Waiting for udev to start..."
|
---|
306 | sleep 5
|
---|
307 | fi
|
---|
308 | mkdir -p /dev/.udev/queue/
|
---|
309 | if [ -x /sbin/udevtrigger ]; then
|
---|
310 | /sbin/udevtrigger
|
---|
311 | fi
|
---|
312 | echo "Waiting for udev to discover..."
|
---|
313 | create_dev_makedev
|
---|
314 | # Newer version use udevadm for that
|
---|
315 | if [ -x /sbin/udevsettle ]; then
|
---|
316 | /sbin/udevsettle --timeout=10
|
---|
317 | elif [ -x /sbin/udevadm ]; then
|
---|
318 | /sbin/udevadm trigger
|
---|
319 | /sbin/udevadm settle --timeout=10
|
---|
320 | fi
|
---|
321 | # It seems we need to have more static devs on some distro were
|
---|
322 | # udev as some other requirements to be covered later on.
|
---|
323 | # So in the mean time:
|
---|
324 | for d in `ls /dev.static`; do
|
---|
325 | if [ ! -e /dev/$d ]; then
|
---|
326 | mv /dev.static/$d /dev
|
---|
327 | fi
|
---|
328 | done
|
---|
329 | echo $PKLVL > /proc/sys/kernel/printk
|
---|
330 | }
|
---|
331 |
|
---|
332 | RstHW() {
|
---|
333 |
|
---|
334 | # Restore the HW configuration if available (NOT by default)
|
---|
335 | answer="NO"
|
---|
336 |
|
---|
337 | grep -q nohw /proc/cmdline
|
---|
338 | if [ "$?" -eq 0 ]; then
|
---|
339 | return
|
---|
340 | fi
|
---|
341 | if [ -x ./mindi-rsthw ]; then
|
---|
342 | grep -q RESTORE /proc/cmdline
|
---|
343 | if [ "$?" -ne 0 ]; then
|
---|
344 | #clear
|
---|
345 | echo "*********************************************************************"
|
---|
346 | echo "Do you want to restore the HW configuration of the original machine ?"
|
---|
347 | echo "(This may dammage your hardware so be sure to check twice before saying yes)"
|
---|
348 | echo "*********************************************************************"
|
---|
349 | echo "Please confirm by typing YES exactly as written here (NO by default)"
|
---|
350 | echo -n "--> "
|
---|
351 | read answer
|
---|
352 | else
|
---|
353 | answer="YES"
|
---|
354 | fi
|
---|
355 | if [ "$answer" = "YES" ] ; then
|
---|
356 | ./mindi-rsthw
|
---|
357 | fi
|
---|
358 | fi
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | #RunDevfsd() {
|
---|
363 | # loc=`which devfsd 2> /dev/null`
|
---|
364 | # if [ "$loc" != "" ] ; then
|
---|
365 | # LogIt "Starting devfsd"
|
---|
366 | # devfsd /dev &
|
---|
367 | # sleep 5
|
---|
368 | # fi
|
---|
369 | #}
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 | StartUSBKbd() {
|
---|
374 | # Prepare minimal USB env in case we have USB kbd such as with iLO
|
---|
375 | [ -d /proc/bus/usb ] && ! grep -q /proc/bus/usb /proc/mounts && mount -t usbfs none /proc/bus/usb
|
---|
376 | echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
|
---|
377 | if [ $? -eq 0 ]; then
|
---|
378 | return
|
---|
379 | fi
|
---|
380 | modprobe -q uhcd_hci
|
---|
381 | modprobe -q usbhid
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 | StartLvms() {
|
---|
387 | if [ "`grep -i nolvm /proc/cmdline`" ]; then
|
---|
388 | return;
|
---|
389 | fi
|
---|
390 | if [ -e "/tmp/i-want-my-lvm" ] ; then
|
---|
391 | LogIt "Scanning LVM's..." 1
|
---|
392 | if which lvm ; then
|
---|
393 | modprobe -q dm-mod
|
---|
394 | modprobe -q dm_mod
|
---|
395 | lvm vgscan --mknodes
|
---|
396 | else
|
---|
397 | vgscan
|
---|
398 | fi
|
---|
399 | grep -E "^#.*vgchange" /tmp/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
|
---|
400 | chmod +x /tmp/start-lvm
|
---|
401 | echo -en "Starting LVM's..."
|
---|
402 | /tmp/start-lvm &
|
---|
403 | for i in 1 2 3 4 5 ; do
|
---|
404 | echo -en "."
|
---|
405 | sleep 1
|
---|
406 | done
|
---|
407 | echo "Done."
|
---|
408 | fi
|
---|
409 | # If necessary, cannibalize 'analyze-my-lvm'; copy some of its code here,
|
---|
410 | # pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
|
---|
411 | LogIt "LVM's have been started."
|
---|
412 | }
|
---|
413 |
|
---|
414 | StartPowerPath() {
|
---|
415 |
|
---|
416 | # Taken from the init script of EMC PowerPath on RHEL
|
---|
417 | if [ -f /etc/emcp_devicesDB.dat ]; then
|
---|
418 | if [ -f /etc/emcp_devicesDB.idx ]; then
|
---|
419 | /etc/opt/emcpower/emcpmgr map -p > /dev/null 2>&1
|
---|
420 | fi
|
---|
421 | fi
|
---|
422 |
|
---|
423 | /sbin/powermt config > /dev/null 2>&1
|
---|
424 | # Wait for udev to finish creating emcpower devices
|
---|
425 | #
|
---|
426 | pdfound=1
|
---|
427 | for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
|
---|
428 | pdfound=1
|
---|
429 | for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
|
---|
430 | bpd=`basename $pd`
|
---|
431 | if [ ! -e /dev/$bpd ]; then
|
---|
432 | pdfound=0
|
---|
433 | sleep 2
|
---|
434 | break;
|
---|
435 | fi
|
---|
436 | done
|
---|
437 | if [ "$pdfound" -eq 1 ]; then
|
---|
438 | break
|
---|
439 | fi
|
---|
440 | done
|
---|
441 | if [ "$pdfound" -eq 0 ]; then
|
---|
442 | echo "Unable to start PowerPath"
|
---|
443 | fi
|
---|
444 |
|
---|
445 | /sbin/powermt load > /dev/null 2>&1
|
---|
446 | /etc/opt/emcpower/emcpmgr map > /dev/null 2>&1
|
---|
447 | /etc/opt/emcpower/powercf -C > /dev/null 2>&1
|
---|
448 | if [ ! -e /etc/powermt.custom ]; then
|
---|
449 | /sbin/powermt save > /dev/null 2>&1
|
---|
450 | fi
|
---|
451 | /sbin/powermt register > /dev/null 2>&1
|
---|
452 | /sbin/powermig transition -startup -noprompt > /dev/null 2>&1
|
---|
453 | }
|
---|
454 |
|
---|
455 | StartMpath() {
|
---|
456 | if [ "`grep -i nompath /proc/cmdline`" ]; then
|
---|
457 | return;
|
---|
458 | fi
|
---|
459 | if [ "`grep mpath /tmp/mountlist.txt`" ]; then
|
---|
460 | if [ -x /sbin/multipath ]; then
|
---|
461 | echo "Starting Mpath..."
|
---|
462 | mkdir -p /var/lib/multipath
|
---|
463 | cat > /etc/multipath.conf << EOF
|
---|
464 | defaults {
|
---|
465 | user_friendly_names yes
|
---|
466 | }
|
---|
467 | EOF
|
---|
468 | /sbin/multipath -v 0
|
---|
469 | if [ -x /sbin/kpartx ]; then
|
---|
470 | /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
|
---|
471 | fi
|
---|
472 | fi
|
---|
473 | fi
|
---|
474 | }
|
---|
475 |
|
---|
476 | StartRaids() {
|
---|
477 | local raid_devices i
|
---|
478 |
|
---|
479 | if [ "`grep -i noraid /proc/cmdline`" ]; then
|
---|
480 | return;
|
---|
481 | fi
|
---|
482 |
|
---|
483 | raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
|
---|
484 | if which raidstart > /dev/null 2> /dev/null ; then
|
---|
485 | for i in $raid_devices ; do
|
---|
486 | if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
|
---|
487 | LogIt "$i is started already; no need to run 'raidstart $i'" 1
|
---|
488 | else
|
---|
489 | LogIt "Running 'raidstart $i'" 1
|
---|
490 | raidstart $i
|
---|
491 | fi
|
---|
492 | done
|
---|
493 | elif which mdrun > /dev/null 2> /dev/null ; then
|
---|
494 | if [ "`grep -i nomd /proc/cmdline`" ]; then
|
---|
495 | return;
|
---|
496 | fi
|
---|
497 | LogIt "Running 'mdrun'" 1
|
---|
498 | mdrun
|
---|
499 | elif which mdadm > /dev/null 2> /dev/null ; then
|
---|
500 | if [ "`grep -i nomd /proc/cmdline`" ]; then
|
---|
501 | return;
|
---|
502 | fi
|
---|
503 | LogIt "Running 'mdadm'" 1
|
---|
504 | for i in $raid_devices ; do
|
---|
505 | if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
|
---|
506 | LogIt "$i is started already; no need to run 'mdadm $i'" 1
|
---|
507 | else
|
---|
508 | if [ -f /etc/mdadm.conf ] ; then
|
---|
509 | LogIt "Running 'mdadm $i' with user supplied /etc/mdadm.conf" 1
|
---|
510 | mdadm -A $i -c /etc/mdadm.conf
|
---|
511 | elif [ -f /etc/mdadm/mdadm.conf ] ; then
|
---|
512 | LogIt "Running 'mdadm $i' with user supplied /etc/mdadm/mdadm.conf" 1
|
---|
513 | mdadm -A $i -c /etc/mdadm/mdadm.conf
|
---|
514 | else
|
---|
515 | LogIt "Running 'mdadm $i'" 1
|
---|
516 | mdadm -Ac partitions -m dev $i
|
---|
517 | fi
|
---|
518 | fi
|
---|
519 | done
|
---|
520 | elif which dmraid > /dev/null 2> /dev/null ; then
|
---|
521 | if [ "`grep -i nodmraid /proc/cmdline`" ]; then
|
---|
522 | return;
|
---|
523 | fi
|
---|
524 | for x in $(/sbin/dmraid -ay -i -p -t 2>/dev/null | grep -E -iv "^no " |awk -F ':' '{ print $1 }') ; do
|
---|
525 | echo "Please send the result of /sbin/dmraid -ay -i -p -t to the devteam !!!"
|
---|
526 | return
|
---|
527 | #dmname=$(resolve_dm_name $x)
|
---|
528 | #[ -z "$dmname" ] && continue
|
---|
529 | #/sbin/dmraid -ay -i -p "$dmname" >/dev/null 2>&1
|
---|
530 | #/sbin/kpartx -a -p p "/dev/mapper/$dmname"
|
---|
531 | done
|
---|
532 | else
|
---|
533 | LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
|
---|
534 | fi
|
---|
535 |
|
---|
536 | }
|
---|
537 |
|
---|
538 |
|
---|
539 | TryAgainToFindCD() {
|
---|
540 | local res
|
---|
541 | mount | grep /mnt/cdrom && return 0
|
---|
542 | [ "`grep "backup_media_type" /tmp/mondo-restore.cfg 2> /dev/null | grep "cdstream"`" ] && return
|
---|
543 | LogIt "Trying to mount CD-ROM a 2nd time..."
|
---|
544 | find-and-mount-cdrom --second-try
|
---|
545 | res=$?
|
---|
546 | if [ "$res" -eq "0" ] ; then
|
---|
547 | CD_MOUNTED_OK=yes
|
---|
548 | LogIt "CD-ROM drive mounted successfully." 1
|
---|
549 | else
|
---|
550 | LogIt "I still cannot find or mount the CD-ROM drive, by the way."
|
---|
551 | fi
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 |
|
---|
556 | UseTmpfs()
|
---|
557 | {
|
---|
558 | local mount_cmd
|
---|
559 | echo -en "Mounting /tmp/tmpfs..."
|
---|
560 | mkdir -p /tmp/tmpfs
|
---|
561 | # For technical reasons, some sets are as large as 16MB.
|
---|
562 | # I am allowing 32MB because selective restore occupies a lot of space.
|
---|
563 | for size in 128m 64m 48m 40m 32m ; do
|
---|
564 | mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
|
---|
565 | LogIt "Trying '$mount_cmd'"
|
---|
566 | $mount_cmd /tmp/tmpfs 2>> $LOGFILE
|
---|
567 | res=$?
|
---|
568 | [ "$res" -eq "0" ] && break
|
---|
569 | done
|
---|
570 | if [ "$res" -ne "0" ] ; then
|
---|
571 | LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
|
---|
572 | umount /tmp/tmpfs > /dev/null 2> /dev/null
|
---|
573 | rmdir /tmp/tmpfs
|
---|
574 | ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondo-restore
|
---|
575 | LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
|
---|
576 | else
|
---|
577 | LogIt "Great. Pivot succeeded w/ size=$size" 1
|
---|
578 | echo -en "Pivoting /tmp..."
|
---|
579 | umount /tmp/tmpfs
|
---|
580 | mkdir -p /tmp.old
|
---|
581 | mv /tmp/* /tmp.old/
|
---|
582 | # Try to Deal with a busybox bug on inexistant links
|
---|
583 | cp /tmp/* /tmp.old/
|
---|
584 | rm -f /tmp/*
|
---|
585 | $mount_cmd /tmp
|
---|
586 | mv /tmp.old/* /tmp/
|
---|
587 | # Try to Deal with a busybox bug on inexistant links
|
---|
588 | cp /tmp.old/* /tmp/
|
---|
589 | rm -rf /tmp.old
|
---|
590 | mkdir -p /tmp/tmpfs
|
---|
591 | mkdir -p $GROOVY
|
---|
592 | echo "Done."
|
---|
593 | LogIt "Successfully mounted dynamic /tmp ramdisk"
|
---|
594 | # mkdir -p /tmp/tmpfs/var
|
---|
595 | # mv -f /var/log /tmp/tmpfs/var/log
|
---|
596 | # ln -sf /tmp/tmpfs/var/log /var/log
|
---|
597 | fi
|
---|
598 | }
|
---|
599 |
|
---|
600 |
|
---|
601 | WelcomeMessage()
|
---|
602 | {
|
---|
603 | echo "********************************************************************"
|
---|
604 | echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
|
---|
605 | echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
|
---|
606 | which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
|
---|
607 | echo "Executables and source code are covered by the GNU GPL. No warranty."
|
---|
608 | echo "running on $ARCH"
|
---|
609 | echo "********************************************************************"
|
---|
610 | }
|
---|
611 |
|
---|
612 |
|
---|
613 | EnableCcissIfAppropriate() {
|
---|
614 | local i fname
|
---|
615 | for i in 0 1 2 3 ; do
|
---|
616 | fname="/proc/driver/cciss/cciss$i"
|
---|
617 | if [ -e "$fname" ] ; then
|
---|
618 | LogIt "Engaging $fname"
|
---|
619 | echo "engage scsi" > $fname
|
---|
620 | LogIt "...result=$?"
|
---|
621 | fi
|
---|
622 | done
|
---|
623 | }
|
---|
624 |
|
---|
625 | ModprobeAllModules() {
|
---|
626 |
|
---|
627 | for m in `find /lib/modules -name '*\.ko*' -o -name '*\.o*'`; do
|
---|
628 | k=`basename $m | sed 's/\.ko.*$//'`
|
---|
629 | j=`basename $k | sed 's/\.o.*$//'`
|
---|
630 | echo "$DENY_MODS" | grep -q "$j "
|
---|
631 | if [ $? -eq 0 ]; then
|
---|
632 | echo "Denying $j..."
|
---|
633 | continue
|
---|
634 | fi
|
---|
635 | echo "Probing $j..."
|
---|
636 | modprobe -q $j
|
---|
637 | done
|
---|
638 | }
|
---|
639 |
|
---|
640 | ExtractDataDisksAndLoadModules() {
|
---|
641 | echo "Installing additional tools ..."
|
---|
642 | install-additional-tools
|
---|
643 | # Keep the kernel silent again
|
---|
644 | PKLVL=`cut -f1 /proc/sys/kernel/printk`
|
---|
645 | echo 0 > /proc/sys/kernel/printk
|
---|
646 | ModprobeAllModules
|
---|
647 | echo $PKLVL > /proc/sys/kernel/printk
|
---|
648 |
|
---|
649 | # Retry failed udev events now that local filesystems are mounted read-write
|
---|
650 | # (useful for rules creating network ifcfg files)
|
---|
651 | if [ -e "/tmp/USE-UDEV" ] ; then
|
---|
652 | if [ -x /sbin/udevadm ]; then
|
---|
653 | /sbin/udevadm trigger --retry-failed
|
---|
654 | fi
|
---|
655 | fi
|
---|
656 | }
|
---|
657 |
|
---|
658 | # ------------------------ main -----------------------
|
---|
659 |
|
---|
660 | MINDI_VER=PBVER
|
---|
661 | MINDI_REV=PBREV
|
---|
662 | trap CaughtSoftReset SIGTERM
|
---|
663 | LOGFILE=/var/log/mondorestore.log
|
---|
664 | PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
|
---|
665 | GROOVY=/tmp/groovy-stuff
|
---|
666 | USER=root
|
---|
667 | ARCH=`uname -m`
|
---|
668 |
|
---|
669 | export PATH GROOVY USER LOGFILE ARCH
|
---|
670 |
|
---|
671 | echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
|
---|
672 |
|
---|
673 | mount -o remount rw /
|
---|
674 | [ ! "$GROOVY" ] && Die "I'm not groovy!"
|
---|
675 | for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
|
---|
676 | mkdir -p $i
|
---|
677 | done
|
---|
678 | #/bin/update
|
---|
679 | mount /proc/ /proc -v -t proc
|
---|
680 | mkdir /sys 2> /dev/null
|
---|
681 | mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
|
---|
682 | # For ESX 3
|
---|
683 | [ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
|
---|
684 | rm -f /foozero
|
---|
685 |
|
---|
686 | if [ "`grep -i denymods /proc/cmdline`" ]; then
|
---|
687 | export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
|
---|
688 | else
|
---|
689 | export DENY_MODS=" "
|
---|
690 | fi
|
---|
691 | if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
|
---|
692 | # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
|
---|
693 | export DENY_MODS="usb-storage $DENY_MODS"
|
---|
694 | fi
|
---|
695 | if [ "`grep -i forcemods /proc/cmdline`" ]; then
|
---|
696 | export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
|
---|
697 | else
|
---|
698 | export FORCE_MODS=" "
|
---|
699 | fi
|
---|
700 |
|
---|
701 | echo "Activating a potential USB keyboard/mouse"
|
---|
702 | StartUSBKbd
|
---|
703 |
|
---|
704 | if [ -f /proc/sys/kernel/exec-shield ]; then
|
---|
705 | echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
|
---|
706 | fi
|
---|
707 |
|
---|
708 | if [ -f /proc/modules ]; then
|
---|
709 | echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
|
---|
710 | fi
|
---|
711 |
|
---|
712 | if [ -e "/tmp/USE-UDEV" ] ; then
|
---|
713 | RunUdevd
|
---|
714 | fi
|
---|
715 | ExtractDevTarballs
|
---|
716 | LaunchTerminals
|
---|
717 |
|
---|
718 | # Keeping kernel silent for module insertion
|
---|
719 | PKLVL=`cut -f1 /proc/sys/kernel/printk`
|
---|
720 | echo 0 > /proc/sys/kernel/printk
|
---|
721 | ModprobeAllModules
|
---|
722 | echo $PKLVL > /proc/sys/kernel/printk
|
---|
723 |
|
---|
724 | EnableCcissIfAppropriate
|
---|
725 | #-------------------------------
|
---|
726 | #WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
|
---|
727 | #-------------------------------
|
---|
728 | UseTmpfs
|
---|
729 | if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
|
---|
730 | LogIt "Warning - /tmp/mondo-restore.cfg not found"
|
---|
731 | fi
|
---|
732 | if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
|
---|
733 | # We need to get here exported variables from start-netfs
|
---|
734 | . /sbin/start-netfs
|
---|
735 | fi
|
---|
736 |
|
---|
737 | if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
|
---|
738 | HandleTape
|
---|
739 | ExtractDataDisksAndLoadModules
|
---|
740 | elif [ "`grep -i pxe /proc/cmdline`" ]; then
|
---|
741 | # Simulate a local CD
|
---|
742 | echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
|
---|
743 | CD_MOUNTED_OK=yes
|
---|
744 | ExtractDataDisksAndLoadModules
|
---|
745 | # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
|
---|
746 | sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondo-restore.cfg
|
---|
747 | elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
|
---|
748 | . /sbin/start-usb
|
---|
749 |
|
---|
750 | # Simulate a local CD
|
---|
751 | echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
|
---|
752 | CD_MOUNTED_OK=yes
|
---|
753 | ExtractDataDisksAndLoadModules
|
---|
754 | else
|
---|
755 | HandleCDROM
|
---|
756 | ExtractDataDisksAndLoadModules
|
---|
757 | # We need to get here exported variables from start-netfs
|
---|
758 | . /sbin/start-netfs
|
---|
759 | fi
|
---|
760 | res=$?
|
---|
761 | ConfigureLoggingDaemons
|
---|
762 | if [ -e "/tmp/USE-DEVFS" ] ; then
|
---|
763 | umount /mnt/cdrom 2> /dev/null
|
---|
764 | mv /dev/cdrom /cdrom.lnk 2> /dev/null
|
---|
765 | CD_MOUNTED_OK=""
|
---|
766 | RunDevfsd
|
---|
767 | fi
|
---|
768 | LoadKeymap
|
---|
769 | WelcomeMessage
|
---|
770 | RstHW
|
---|
771 | echo "Starting potential Raid/LVMs ..."
|
---|
772 | PauseForRaids
|
---|
773 | StartRaids
|
---|
774 | StartMpath
|
---|
775 | StartLvms
|
---|
776 | CopyBootDevEntry
|
---|
777 | mkdir -p /tmp/tmpfs
|
---|
778 | sleep 2
|
---|
779 | #clear
|
---|
780 | if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
|
---|
781 | LogIt "Creating /dev/md/* softlinks just in case." 1
|
---|
782 | mkdir -p /dev/md
|
---|
783 | cp -af /dev/md0 /dev/md/0 2> /dev/null
|
---|
784 | cp -af /dev/md1 /dev/md/1 2> /dev/null
|
---|
785 | cp -af /dev/md2 /dev/md/2 2> /dev/null
|
---|
786 | fi
|
---|
787 | [ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
|
---|
788 |
|
---|
789 | if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
|
---|
790 | res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
|
---|
791 | [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
|
---|
792 | [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
|
---|
793 | [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
|
---|
794 | #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
|
---|
795 | fi
|
---|
796 | hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
|
---|
797 |
|
---|
798 | # Log some useful info
|
---|
799 | LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
|
---|
800 | LogIt "/proc/cmdline is:"
|
---|
801 | LogIt "----------"
|
---|
802 | cat /proc/cmdline >> $LOGFILE
|
---|
803 | LogIt "----------"
|
---|
804 | LogIt "df result:"
|
---|
805 | LogIt "----------"
|
---|
806 | df >> $LOGFILE
|
---|
807 | LogIt "-------------"
|
---|
808 | LogIt "mount result:"
|
---|
809 | LogIt "-------------"
|
---|
810 | mount >> $LOGFILE
|
---|
811 | LogIt "-------------"
|
---|
812 | LogIt "lsmod result:"
|
---|
813 | LogIt "-------------"
|
---|
814 | lsmod >> $LOGFILE
|
---|
815 | LogIt "-------------"
|
---|
816 | LogIt "dmesg result:"
|
---|
817 | LogIt "-------------"
|
---|
818 | dmesg >> $LOGFILE
|
---|
819 | LogIt "-------------"
|
---|
820 | LogIt "/proc/swaps:" >> $LOGFILE
|
---|
821 | LogIt "-------------"
|
---|
822 | cat /proc/swaps >> $LOGFILE
|
---|
823 | LogIt "-------------"
|
---|
824 | LogIt "/proc/filesystems:" >> $LOGFILE
|
---|
825 | LogIt "-------------"
|
---|
826 | cat /proc/filesystems >> $LOGFILE
|
---|
827 | LogIt "-------------"
|
---|
828 | LogIt "/proc/partitions:" >> $LOGFILE
|
---|
829 | LogIt "-------------"
|
---|
830 | cat /proc/partitions >> $LOGFILE
|
---|
831 | LogIt "-------------"
|
---|
832 | LogIt "fdisk result:" >> $LOGFILE
|
---|
833 | LogIt "-------------"
|
---|
834 | fdisk -l >> $LOGFILE
|
---|
835 |
|
---|
836 | ide-opt
|
---|
837 |
|
---|
838 | #ctrlaltdel soft
|
---|
839 | for path in /usr.bin /usr/bin ; do
|
---|
840 | fname=$path/nano
|
---|
841 | [ -e "$fname" ] && ln -sf $fname /usr/bin/pico
|
---|
842 | done
|
---|
843 | res=`which nano 2> /dev/null`
|
---|
844 | [ "$res" ] && ln -sf /usr/bin/
|
---|
845 | for i in null stdout stdin stderr ; do
|
---|
846 | cp -af /dev/$i /tmp
|
---|
847 | done
|
---|
848 | # Not sure it's still needed, but shouldn't hurt
|
---|
849 | if [ -e "/tmp/USE-UDEV" ] ; then
|
---|
850 | if [ -x /sbin/udevadm ]; then
|
---|
851 | /sbin/udevadm trigger --retry-failed
|
---|
852 | fi
|
---|
853 | fi
|
---|
854 | if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
|
---|
855 | LogIt "backup-media-type is specified in config file - great."
|
---|
856 | LogIt "Calling post-init"
|
---|
857 | # start-netfs moved it under /tmp as the NFS share is already unmounted
|
---|
858 | if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
|
---|
859 | post=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
|
---|
860 | fi
|
---|
861 | if [ -x $pre ]; then
|
---|
862 | echo "Executing preliminary script $pre"
|
---|
863 | LogIt "Executing preliminary script $pre"
|
---|
864 | $pre
|
---|
865 | fi
|
---|
866 | post-init
|
---|
867 | else
|
---|
868 | LogIt "backup-media-type is not specified in config file."
|
---|
869 | LogIt "I think this media has no archives on it."
|
---|
870 | fi
|
---|
871 | if [ "`grep -i "post=" /proc/cmdline`" ] ; then
|
---|
872 | for i in `cat /proc/cmdline` ; do
|
---|
873 | echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
|
---|
874 | done
|
---|
875 | # start-netfs moved it under /tmp as the NFS share is already unmounted
|
---|
876 | if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
|
---|
877 | post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
|
---|
878 | fi
|
---|
879 | if [ -x $post ]; then
|
---|
880 | echo "Executing final script $post"
|
---|
881 | LogIt "Executing final script $post"
|
---|
882 | if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
|
---|
883 | mount-me
|
---|
884 | fi
|
---|
885 | $post
|
---|
886 | if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
|
---|
887 | unmount-me
|
---|
888 | fi
|
---|
889 | fi
|
---|
890 | fi
|
---|
891 | if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
|
---|
892 | echo "Rebooting in 10 seconds automatically as per reboot order"
|
---|
893 | echo -en "Press ^C to interrupt if you have to ..."
|
---|
894 | for i in 1 2 3 4 5 6 7 8 9 10 ; do
|
---|
895 | sleep 1
|
---|
896 | echo -en "."
|
---|
897 | done
|
---|
898 | echo "Boom."
|
---|
899 | sleep 1
|
---|
900 | else
|
---|
901 | echo -en "Type 'exit' to reboot the PC\n"
|
---|
902 | umount /mnt/cdrom 2> /dev/null
|
---|
903 | mount / -o rw,remount > /dev/null 2> /dev/null
|
---|
904 | LogIt "Launching Shell"
|
---|
905 | sh
|
---|
906 | fi
|
---|
907 | CaughtSoftReset
|
---|
908 | # reboot
|
---|