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
RevLine 
[1]1#!/bin/sh
2#
[736]3# $Id: init 2850 2011-07-24 02:12:44Z bruno $
[1]4#
[736]5# init script launched during the restore process
[1]6#------------------------------------------------------------
7
[2462]8export MINDI_CACHE=CCC
9
[1]10
11CaughtSoftReset() {
[1747]12 trap SIGTERM
13 reboot
[1]14}
15
16
17ConfigureLoggingDaemons() {
[1747]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."
[1]24}
25
26
27
28CopyBootDevEntry() {
[1747]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
[2174]35 echo "not needed."
[1410]36 return 0
[1747]37 fi
38 mkdir -p $outfile
39 rmdir $outfile
40 cp -pRdf $devfile $outfile
41 if [ "$?" -ne "0" ] ; then
[1410]42 echo "Failed."
43 return 1
[1747]44 else
[1410]45 echo "OK."
46 return 0
[1747]47 fi
[1]48}
49
50
51
52Die() {
[1747]53 LogIt "Fatal error! $1" 1
54 exit 1
[1]55}
56
57
58
59ExtractDevTarballs() {
[1747]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"
[2487]67 rm -f /$fname
[1747]68 fi
69 done
70 echo -en "\r"
71 LogIt "Extracted additional /dev entries OK. " 1
[1]72}
73
74
75
76LaunchTerminals() {
[2816]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
[2603]84 serial="/foo"
[2484]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.)
[2603]87 for i in `cat $CMDLINE` ; do
[2484]88 echo $i | grep -qi serial= && serial=`echo $i | cut -d= -f2`
89 done
[2487]90 # Doing that is only valid when using a real serial line
91 if [ -f $serial ]; then
[2499]92 LogIt "Redirecting serial $serial to /dev/tty" 1
[2487]93 ln -s -f $serial /dev/tty
94 fi
[1]95}
96
97
98LoadKeymap() {
[1747]99 local fname
[2487]100 fname=`cat $MINDI_CACHE/KEYMAP-LIVES-HERE 2> /dev/null`
[1747]101 [ "$fname" = "" ] && return
102 if which loadkeys > /dev/null 2> /dev/null ; then
103 loadkeys $fname
[2850]104 LogIt "Using $fname keyboard map." 1
[1747]105 else
[2816]106 LogIt "Using default US keyboard map." 1
[1747]107 fi
[1]108}
109
110
111UntarTapeStuff() {
[1747]112 local old_pwd res
113 old_pwd=`pwd`
114 cd $GROOVY
115 [ "$1" != "" ] && tapedev=$1
[2591]116 [ ! "$tapedev" ] && [ -f $MINDI_CACHE/mondorestore.cfg ] && tapedev=`grep media-dev $MINDI_CACHE/mondorestore.cfg 2>/dev/null | tr -s ' ' ' ' | cut -d' ' -f2`
[1962]117 mt -f $tapedev rewind
[1958]118 mt -f $tapedev fsf 2
[1747]119 dd if=$tapedev bs=32k count=1024 | tar -zx
120 res=$?
121 if [ "$res" -eq "0" ] ; then
[1958]122 # Store the dev name in case we changed it interactively
[2462]123 if [ -f "$MINDI_CACHE/mondorestore.cfg" ]; then
124 sed -i "s/^media-dev .*$/media-dev $tapedev/" $MINDI_CACHE/mondorestore.cfg
[1983]125 fi
[1747]126 fi
127 cd $old_pwd
128 return $res
[1]129}
130
131HandleTape() {
[1747]132 local res tapedev
133 tapedev="" ; # will be set by UntarTapeStuff()
[1963]134
[1968]135 # Here we can add the USB storage module, it's working even with OBDR !
[1963]136 modprobe -q usb-storage
[1968]137 # Tape takes some time to appear
138 sleep 10
[1958]139 UntarTapeStuff $tapedev
[1747]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
[1885]144 LogIt "or hit <Enter> to boot from another media." 1
[1747]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
[1]154 break
[1747]155 fi
156 done
[1962]157 # For post-init
158 export TAPEDEV=$tapedev
[1]159
[1747]160 if [ "$res" -ne "0" ] ; then
[1885]161 LogIt "Failed to use tape as extended datadisk. Reverting to another media." 1
162 HandleCDROM
[1410]163 res=$?
[1747]164 else
[1410]165 LogIt "Using tape as extended datadisk. Good." 3
166 echo "Using tape as extd ddisk." > /tmp/TAPEDEV-HAS-DATA-DISKS
167 res=0
[1747]168 CD_MOUNTED_OK=yes
169 fi
170 return $res
[1]171}
172
173
174
[1885]175HandleCDROM() {
[1825]176 # Just in case we have an iLO ensure we will map it correctly
[1830]177 echo "$DENY_MODS" | grep -q "usb-storage "
[1829]178 if [ $? -eq 0 ]; then
179 return
180 fi
[1826]181 echo "Activating a potential USB Storage device"
[1922]182 modprobe -q usb-storage
[1826]183 for i in 1 2 3 4 5 6 7 8 9 10 ; do
184 sleep 1
185 echo -en "."
186 done
[1825]187
[1747]188 find-and-mount-cdrom
189 res=$?
190 if [ "$res" -ne "0" ] ; then
[898]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=$?
[1747]196 fi
197 if [ "$res" -eq "0" ] ; then
[898]198 LogIt "OK, I am running on a CD-ROM. Good." 3
[1747]199 CD_MOUNTED_OK=yes
200 else
[1885]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
[898]205 CD_MOUNTED_OK=""
[1747]206 fi
207 return 0
[1]208}
209
210
[2362]211# --- cater for arbitrary locations of devfsd.conf by using the
212# config file path compiled into devfsd
[1]213RunDevfsd() {
[1747]214 loc=`which devfsd 2> /dev/null`
215 if [ "$loc" != "" ] ; then
[1]216 LogIt "Devfs found. Testing kernel support..."
217 if [ ! -e "/dev/.devfsd" ] ; then
[746]218 mount -t devfs devfs /dev 2>> $LOGFILE
[1747]219 if [ "$?" -ne "0" ] ; then
[1]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"
[911]229 conffile=`strings $loc | grep -E "devfsd.conf$"`
[1]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
[1747]239 fi
[1]240}
241
[1718]242# Taken from udev management in Mandriva 2008.0. Kudos guys
[2850]243MakeExtraNodes () {
[1718]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 ;;
[1719]252 M) mknod /dev/$name $arg1 && chmod 600 /dev/$name;;
253 *) echo "udev-links.conf: unparseable line (%s %s %s)\n" "$type" "$name" "$arg1" ;;
[1718]254 esac
255 done
256}
257
[2850]258CreateDevMakedev() {
[1792]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}
[1718]265
[1716]266RunUdevd() {
[1718]267 # Inspiration from Mandriva 2008.0 startup script
268 echo "Preparing udev environment..."
[2850]269 LogIt "Preparing udev environment..."
[1718]270 mv /dev /dev.static
271 mkdir /dev
272 mount -n -o size=5M,mode=0755 -t tmpfs none /dev
[2850]273 MakeExtraNodes
[1718]274 mount -n -t devpts -o mode=620 none /dev/pts
275 mount -n -t tmpfs none /dev/shm
[1789]276 if [ -e /proc/sys/kernel/hotplug ]; then
277 echo > /proc/sys/kernel/hotplug
278 fi
[1734]279 PKLVL=`cut -f1 /proc/sys/kernel/printk`
280 echo 0 > /proc/sys/kernel/printk
[2081]281 # Many possibilities depending on udev versions
[1759]282 if [ -x /sbin/startudev ]; then
283 /sbin/startudev
[2286]284 elif [ -x /sbin/start_udev ]; then
[2081]285 /sbin/start_udev
286 fi
[1759]287 # Depending on udevd version it gives back the hand or not :-(
[2696]288 ps | grep -v grep |grep udevd 2> /dev/null 1> /dev/null
[2444]289 if [ $? -ne 0 ]; then
[2286]290 /sbin/udevd --daemon &
[2444]291 echo "Waiting for udev to start..."
[2286]292 sleep 5
[2850]293 LogIt "udev started manually"
[2286]294 fi
[1792]295 mkdir -p /dev/.udev/queue/
[1789]296 if [ -x /sbin/udevtrigger ]; then
297 /sbin/udevtrigger
298 fi
[2444]299 echo "Waiting for udev to discover..."
[2850]300 CreateDevMakedev
[2182]301 # Newer version use udevadm for that
[2444]302 if [ -x /sbin/udevsettle ]; then
303 /sbin/udevsettle --timeout=10
[2850]304 LogIt "Discovering with udevsettle"
[2444]305 elif [ -x /sbin/udevadm ]; then
[2850]306 UdevadmTrigger
[2444]307 /sbin/udevadm settle --timeout=10
[2850]308 LogIt "Discovering with udevadm"
[1816]309 fi
[2594]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.
[1824]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
[1816]318 echo $PKLVL > /proc/sys/kernel/printk
[1716]319}
[1]320
[1761]321RstHW() {
[1]322
[1761]323 # Restore the HW configuration if available (NOT by default)
324 answer="NO"
[1]325
[2329]326 grep -q nohw $CMDLINE
[1815]327 if [ "$?" -eq 0 ]; then
328 return
329 fi
[2462]330 if [ -x $MINDI_CACHE/mindi-rsthw ]; then
[2329]331 grep -q RESTORE $CMDLINE
[1761]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
[1910]343 if [ "$answer" = "YES" ] ; then
[2462]344 $MINDI_CACHE/mindi-rsthw
[1761]345 fi
346 fi
347}
[1]348
[1761]349
[1787]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
[1830]353echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
[1829]354if [ $? -eq 0 ]; then
355 return
356fi
[1922]357modprobe -q uhcd_hci
358modprobe -q usbhid
[1787]359}
[1]360
361
[1787]362
[1]363StartLvms() {
[2603]364 if [ "`grep -i nolvm $CMDLINE`" ]; then
[2481]365 return;
366 fi
[2623]367 if [ -e "$MINDI_CACHE/i-want-my-lvm" ] ; then
[1747]368 LogIt "Scanning LVM's..." 1
[739]369 if which lvm ; then
[2850]370 modprobe -q dm-mod
371 modprobe -q dm_mod
372 lvm vgscan --mknodes
[739]373 else
[2850]374 vgscan
[739]375 fi
[2546]376
377 # Exclude devices we may not want
378 rm -f /tmp/restorevgs
[2569]379 for d in $MINDI_EXCLUDE_DEVS ; do
[2587]380 echo "LVM exclusion == $d"
[2623]381 EXCLUDE_VGS=`grep " $d" $MINDI_CACHE/i-want-my-lvm | grep vgcreate | awk '{print $4}'`
[2546]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
[2623]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
[2546]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
[2623]395 EXCLUDE_LVS=`grep " $v" $MINDI_CACHE/i-want-my-lvm | grep lvcreate | sed "s/^.*-n \([^ ][^ ]*\) .*$/$1/"`
[2546]396 for l in $EXCLUDE_LVS; do
397 # FIXME: Should search for all possible device names here
[2587]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
[2546]400 done
401 done
402 done
403
[2623]404 grep -E "^#.*vgchange" $MINDI_CACHE/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
[1747]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
[2850]409 echo -en "."
410 sleep 1
[1747]411 done
[2487]412 rm -f /tmp/start-lvm
[1747]413 echo "Done."
414 fi
[1]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.
[1747]417 LogIt "LVM's have been started."
[1]418}
419
[2177]420StartPowerPath() {
[1]421
[2177]422 # Taken from the init script of EMC PowerPath on RHEL
[2850]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
[2177]428
[2850]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
[2177]444 break
[2850]445 fi
446 done
447 if [ "$pdfound" -eq 0 ]; then
448 echo "Unable to start PowerPath"
449 fi
[2177]450
[2850]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
[2177]459}
460
[2072]461StartMpath() {
[2329]462 if [ "`grep -i nompath $CMDLINE`" ]; then
[2072]463 return;
464 fi
[2462]465 if [ "`grep mpath $MINDI_CACHE/mountlist.txt`" ]; then
[2354]466 if [ -x /sbin/multipath ]; then
467 echo "Starting Mpath..."
468 mkdir -p /var/lib/multipath
469 cat > /etc/multipath.conf << EOF
[2072]470defaults {
471 user_friendly_names yes
472}
473EOF
[2354]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
[2850]478 LogIt "Multipath started"
[2072]479 fi
480 fi
481}
482
[1]483StartRaids() {
[1747]484 local raid_devices i
[1273]485
[2603]486 if [ "`grep -i noraid $CMDLINE`" ]; then
[2354]487 return;
488 fi
489
[2462]490 raid_devices=`grep /dev/md $MINDI_CACHE/mountlist.txt | cut -d' ' -f1`
[623]491 if which raidstart > /dev/null 2> /dev/null ; then
[1747]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
[623]496 LogIt "Running 'raidstart $i'" 1
497 raidstart $i
[1747]498 fi
499 done
[623]500 elif which mdrun > /dev/null 2> /dev/null ; then
[2603]501 if [ "`grep -i nomd $CMDLINE`" ]; then
[2354]502 return;
503 fi
[623]504 LogIt "Running 'mdrun'" 1
505 mdrun
[1273]506 elif which mdadm > /dev/null 2> /dev/null ; then
[2603]507 if [ "`grep -i nomd $CMDLINE`" ]; then
[2354]508 return;
509 fi
[1273]510 LogIt "Running 'mdadm'" 1
511 for i in $raid_devices ; do
[1747]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
[1610]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
[1747]525 fi
526 done
[2075]527 elif which dmraid > /dev/null 2> /dev/null ; then
[2329]528 if [ "`grep -i nodmraid $CMDLINE`" ]; then
[2072]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
[623]539 else
540 LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
541 fi
542
[1]543}
544
545
546TryAgainToFindCD() {
[1747]547 local res
548 mount | grep /mnt/cdrom && return 0
[2591]549 [ -f $MINDI_CACHE/mondorestore.cfg ] && [ "`grep "backup_media_type" $MINDI_CACHE/mondorestore.cfg 2> /dev/null | grep "cdstream"`" ] && return
[1747]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
[1]559}
560
561
562
563UseTmpfs()
564{
[1747]565 local mount_cmd
566 echo -en "Mounting /tmp/tmpfs..."
567 mkdir -p /tmp/tmpfs
[1]568# For technical reasons, some sets are as large as 16MB.
569# I am allowing 32MB because selective restore occupies a lot of space.
[2212]570 for size in 128m 64m 48m 40m 32m ; do
[1747]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
[1752]588 mv /tmp/* /tmp.old/
[1747]589 rm -f /tmp/*
590 $mount_cmd /tmp
[1752]591 mv /tmp.old/* /tmp/
[1747]592 rm -rf /tmp.old
593 mkdir -p /tmp/tmpfs
[2487]594 echo "Done."
595 LogIt "Successfully mounted dynamic /tmp ramdisk"
[1747]596 fi
[1]597}
598
599
600WelcomeMessage()
601{
[1747]602 echo "********************************************************************"
603 echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
[1]604which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
[1747]605 echo "Executables and source code are covered by the GNU GPL. No warranty."
606 echo "running on $ARCH"
607 echo "********************************************************************"
[1]608}
609
610
611EnableCcissIfAppropriate() {
[1747]612 local i fname
613 for i in 0 1 2 3 ; do
[1410]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
[1747]620 done
[1]621}
622
[1802]623ModprobeAllModules() {
[1]624
[2603]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`
[2569]631 # loading forced modules first
632 for m in $lismod; do
[1927]633 k=`basename $m | sed 's/\.ko.*$//'`
634 j=`basename $k | sed 's/\.o.*$//'`
[2569]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.*$//'`
[2603]644 lsmod | grep -qE '^$j$'
645 if [ $? -eq 0 ];then
646 # Already loaded
647 continue
648 fi
[1830]649 echo "$DENY_MODS" | grep -q "$j "
[1829]650 if [ $? -eq 0 ]; then
[1830]651 echo "Denying $j..."
[1829]652 continue
653 fi
[2569]654 echo "$FORCE_MODS" | grep -q "$j "
655 if [ $? -eq 0 ]; then
656 continue
657 fi
[1829]658 echo "Probing $j..."
[1815]659 modprobe -q $j
[1802]660 done
661}
662
[2816]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
[287]674ExtractDataDisksAndLoadModules() {
[2850]675 LogIt "Installing additional tools ..." 1
[287]676 install-additional-tools
[1800]677 # Keep the kernel silent again
678 PKLVL=`cut -f1 /proc/sys/kernel/printk`
[1802]679 echo 0 > /proc/sys/kernel/printk
[1922]680 ModprobeAllModules
[1800]681 echo $PKLVL > /proc/sys/kernel/printk
[2081]682
683 # Retry failed udev events now that local filesystems are mounted read-write
684 # (useful for rules creating network ifcfg files)
[2596]685 if [ "$USE_UDEV" = "yes" ]; then
[2816]686 UdevadmTrigger
[2081]687 fi
[287]688}
[1]689
690# ------------------------ main -----------------------
691
[1698]692MINDI_VER=PBVER
693MINDI_REV=PBREV
[1]694trap CaughtSoftReset SIGTERM
[1643]695LOGFILE=/var/log/mondorestore.log
[1236]696PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
[2487]697GROOVY=$MINDI_CACHE/groovy-stuff
[1]698USER=root
[2163]699ARCH=`uname -m`
[1]700
[2163]701export PATH GROOVY USER LOGFILE ARCH
702
[1716]703echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
[898]704
[1]705mount -o remount rw /
706[ ! "$GROOVY" ] && Die "I'm not groovy!"
[2487]707for i in /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
[1747]708 mkdir -p $i
[1]709done
710#/bin/update
711mount /proc/ /proc -v -t proc
[2607]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
[1]724mkdir /sys 2> /dev/null
725mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
[1824]726# For ESX 3
727[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
[1]728rm -f /foozero
729
[2329]730if [ "`grep -i denymods $CMDLINE`" ]; then
731 export DENY_MODS="`cat $CMDLINE | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
[1830]732else
733 export DENY_MODS=" "
[1829]734fi
[2591]735if [ -f $MINDI_CACHE/mondorestore.cfg ] && [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2> /dev/null`" ]; then
[1958]736 # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
[1960]737 export DENY_MODS="usb-storage $DENY_MODS"
[1958]738fi
[2329]739if [ "`grep -i forcemods $CMDLINE`" ]; then
740 export FORCE_MODS="`cat $CMDLINE | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
[1830]741else
742 export FORCE_MODS=" "
[1829]743fi
[2603]744if [ "`grep -i excludedevs $CMDLINE`" ]; then
745 export MINDI_EXCLUDE_DEVS="`cat $CMDLINE | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
[2587]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
[2546]750else
[2569]751 export MINDI_EXCLUDE_DEVS=" "
[2546]752fi
[1829]753
[1826]754echo "Activating a potential USB keyboard/mouse"
[1787]755StartUSBKbd
756
[1720]757if [ -f /proc/sys/kernel/exec-shield ]; then
758 echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
759fi
[1]760
[1729]761if [ -f /proc/modules ]; then
762 echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
763fi
764
[2596]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
[1747]770 RunUdevd
[1716]771fi
[1798]772ExtractDevTarballs
[1]773LaunchTerminals
[1718]774
[1789]775# Keeping kernel silent for module insertion
776PKLVL=`cut -f1 /proc/sys/kernel/printk`
777echo 0 > /proc/sys/kernel/printk
[1922]778ModprobeAllModules
[1789]779echo $PKLVL > /proc/sys/kernel/printk
[1718]780
[1]781EnableCcissIfAppropriate
782#-------------------------------
783#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
784#-------------------------------
785UseTmpfs
[2462]786if [ ! -e "$MINDI_CACHE/mondorestore.cfg" ] ; then
787 LogIt "Warning - $MINDI_CACHE/mondorestore.cfg not found"
[1]788fi
[2329]789if [ "`grep -i pxe $CMDLINE`" ] || [ "`grep -i net $CMDLINE`" ]; then
[2382]790 # We need to get here exported variables from start-netfs
791 . /sbin/start-netfs
[2182]792fi
[1]793
[2596]794if [ -f $MINDI_CACHE/mondorestore.cfg ] && [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2>/dev/null`" ]; then
[1747]795 HandleTape
[287]796 ExtractDataDisksAndLoadModules
[2329]797elif [ "`grep -i pxe $CMDLINE`" ]; then
[287]798 # Simulate a local CD
[2487]799 echo "/mnt/cdrom" > $MINDI_CACHE/CDROM-LIVES-HERE
[1747]800 CD_MOUNTED_OK=yes
[287]801 ExtractDataDisksAndLoadModules
[2182]802 # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
[2591]803 [ -f $MINDI_CACHE/mondorestore.cfg ] && sed -i "s/backup-media-type.*/backup-media-type netfs/" $MINDI_CACHE/mondorestore.cfg
[2462]804elif [ "`grep -i usb= $CMDLINE`" ] || [ "`grep -i usb $MINDI_CACHE/mondorestore.cfg 2>/dev/null | grep media-type`" ]; then
[1747]805 . /sbin/start-usb
[1698]806
807 # Simulate a local CD
[2487]808 echo "/mnt/cdrom" > $MINDI_CACHE/CDROM-LIVES-HERE
[1747]809 CD_MOUNTED_OK=yes
[1698]810 ExtractDataDisksAndLoadModules
[1]811else
[2592]812 if [ -f "$MINDI_CACHE/mondorestore.cfg" ] ; then
813 HandleCDROM
814 fi
[287]815 ExtractDataDisksAndLoadModules
[2382]816 # We need to get here exported variables from start-netfs
817 . /sbin/start-netfs
[1]818fi
819res=$?
820ConfigureLoggingDaemons
[1813]821LoadKeymap
822WelcomeMessage
823RstHW
[2587]824[ -e "$MINDI_CACHE/mountlist.txt" ] && cp -f $MINDI_CACHE/mountlist.txt $MINDI_CACHE/mountlist.original
[1]825StartRaids
[2072]826StartMpath
[1]827StartLvms
828CopyBootDevEntry
829mkdir -p /tmp/tmpfs
830sleep 2
[2462]831if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ $MINDI_CACHE/mountlist.txt`" != "" ] ; then
[1747]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
[1]837fi
838
[2329]839if ! [ "`grep -i "pxe" $CMDLINE`" ] ; then
[1]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
[2592]843 [ "$CD_MOUNTED_OK" != "yes" ] && [ -f $MINDI_CACHE/mondorestore.cfg ] && TryAgainToFindCD
[1]844fi
845hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
846
[1403]847# Log some useful info
[1837]848LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
[2329]849LogIt "$CMDLINE is:"
[2349]850LogIt "----------"
[2329]851cat $CMDLINE >> $LOGFILE
[2349]852LogIt "----------"
[1413]853LogIt "df result:"
854LogIt "----------"
[1403]855df >> $LOGFILE
[1413]856LogIt "-------------"
857LogIt "mount result:"
858LogIt "-------------"
[1403]859mount >> $LOGFILE
[1413]860LogIt "-------------"
861LogIt "lsmod result:"
862LogIt "-------------"
[1403]863lsmod >> $LOGFILE
[1413]864LogIt "-------------"
[1476]865LogIt "dmesg result:"
866LogIt "-------------"
867dmesg >> $LOGFILE
[2015]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
[2349]880LogIt "-------------"
881LogIt "fdisk result:" >> $LOGFILE
882LogIt "-------------"
883fdisk -l >> $LOGFILE
[2816]884LogIt "-------------"
[2832]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
[1403]890
[1983]891ide-opt
[1]892
[2081]893# Not sure it's still needed, but shouldn't hurt
[2596]894if [ "$USE_UDEV" = "yes" ]; then
[2850]895 UdevadmTrigger
[2596]896
[2081]897fi
[2607]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."
[2255]916 fi
[1]917else
[2607]918 LogIt "$MINDI_CACHE/mondorestore.cfg not found."
[1885]919 LogIt "I think this media has no archives on it."
[1]920fi
[2329]921if [ "`grep -i "post=" $CMDLINE`" ] ; then
922 for i in `cat $CMDLINE` ; do
[2255]923 echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
[2249]924 done
[2382]925 # start-netfs moved it under /tmp as the NFS share is already unmounted
[2255]926 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
927 post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
[2253]928 fi
[2587]929 if [ -r $post ]; then
[2255]930 echo "Executing final script $post"
931 LogIt "Executing final script $post"
932 if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
[2253]933 mount-me
934 fi
[2587]935 chmod 755 $post
[2255]936 $post
937 if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
[2253]938 unmount-me
939 fi
[2249]940 fi
941fi
[2329]942if grep "RESTORE" $CMDLINE > /dev/null 2> /dev/null ; then
[1612]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
[1]958CaughtSoftReset
959# reboot
Note: See TracBrowser for help on using the repository browser.