source: branches/3.0/mindi/rootfs/etc/init.d/rcS @ 3119

Last change on this file since 3119 was 3119, checked in by bruno, 6 years ago

r5281@localhost: bruno | 2013-05-08 11:56:49 +0200

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