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

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