source: MondoRescue/branches/2.2.10/mindi/rootfs/sbin/init@ 2850

Last change on this file since 2850 was 2850, checked in by Bruno Cornec, 13 years ago

svn merge -r 2773:2849 2.2.9 in 2.2.10

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • Really support both mkisofs and genisoimage everywhere
  • Try to handle netfs_user better in all cases (NFS and SSHFS)
    • Improve logging in init script
    • Format improvement
    • Removes a warning when trying to launch udevadm and it doesn't exist (RHEL 5 e.g.)
    • Fix syntax description in mondoarchive man page for -E & -I with |
  • Adds download entries for new distro supported (Mageia, Fedora 15, Ubuntu 11.04)

-Fix mindi-get-perl-modules when perl dirs in @INC are symlinks (case on Ubuntu 11.04)

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