source: branches/3.2/mindi/rootfs/etc/init.d/rcS @ 3247

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