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
RevLine 
[1]1#!/bin/sh
2#
[736]3# $Id: rcS 3153 2013-06-22 06:42:08Z bruno $
[1]4#
[736]5# init script launched during the restore process
[1]6#------------------------------------------------------------
7
8
9CaughtSoftReset() {
[1747]10    trap SIGTERM
[2890]11
[2893]12    reboot
[1]13}
14
15
16ConfigureLoggingDaemons() {
[1747]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."
[1]23}
24
25
26
27CopyBootDevEntry() {
[1747]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
[2174]34        echo "not needed."
[1410]35        return 0
[1747]36    fi
37    mkdir -p $outfile
38    rmdir $outfile
39    cp -pRdf $devfile $outfile
40    if [ "$?" -ne "0" ] ; then
[1410]41        echo "Failed."
42        return 1
[1747]43    else
[1410]44        echo "OK."
45        return 0
[1747]46    fi
[1]47}
48
49
[2888]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"
[3051]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
[2888]67}
[1]68
[2888]69
[1]70Die() {
[1747]71    LogIt "Fatal error! $1" 1
[2888]72    GetShell
[1]73}
74
75
76ExtractDevTarballs() {
[1747]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
[1]88}
89
90
91
92LaunchTerminals() {
[2727]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
[3090]108    openvt $opt 9 /usr/bin/tail -f /var/log/messages
[1922]109    # May avoid shell error messages
110    chmod 666 /dev/tty* /dev/console
[2484]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
[2487]116    # Doing that is only valid when using a real serial line
117    if [ -f $serial ]; then
[2498]118        LogIt "Redirecting serial $serial to /dev/tty" 1
[2487]119        ln -s -f $serial /dev/tty
120    fi
[1]121}
122
123
124LoadKeymap() {
[1747]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
[2846]130        LogIt "Using $fname keyboard map." 1
[1747]131    else
[2731]132        LogIt "Using default US keyboard map." 1
[1747]133    fi
[1]134}
135
136
137UntarTapeStuff() {
[1747]138    local old_pwd res
139    old_pwd=`pwd`
140    cd $GROOVY
141    [ "$1" != "" ] && tapedev=$1
[1983]142    [ ! "$tapedev" ] && tapedev=`grep media-dev /tmp/mondo-restore.cfg 2>/dev/null | tr -s ' ' ' ' | cut -d' ' -f2`
[1962]143    mt -f $tapedev rewind
[3119]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`
[3153]150            if [ "$devtype" -eq "1" ]; then
[3119]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
[3153]156            elif [ "$devtype" -eq "0" ]; then
[3119]157                # Skipping a HDD
[3135]158                /bin/true
[3153]159            elif [ "$devtype" -eq "5" ]; then
[3119]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
[1958]206    mt -f $tapedev fsf 2
[2915]207    # 32k is DEFAULT_INTERNAL_TAPE_BLOCK_SIZE
208    mt -f $tapedev setblk 32768
[1747]209    dd if=$tapedev bs=32k count=1024 | tar -zx
210    res=$?
211    if [ "$res" -eq "0" ] ; then
[1958]212        # Store the dev name in case we changed it interactively
[1983]213        if [ -f "/tmp/mondo-restore.cfg" ]; then
214            sed -i "s/^media-dev .*$/media-dev  $tapedev/" /tmp/mondo-restore.cfg
215        fi
[1747]216    fi
217    cd $old_pwd
218    return $res
[1]219}
220
221HandleTape() {
[1747]222    local res tapedev
223    tapedev="" ; # will be set by UntarTapeStuff()
[1963]224
[1968]225    # Here we can add the USB storage module, it's working even with OBDR !
[2964]226    modprobe -q usb-storage 2> /dev/null
[1968]227    # Tape takes some time to appear
228    sleep 10
[1747]229    cd $GROOVY
[1958]230    UntarTapeStuff $tapedev
[1747]231    res=$?
[3124]232    tapedev="default tape device"
[1747]233    while [ "$res" -ne "0" ] ; do
234        LogIt "$tapedev failed to act as extended data disk for booting." 1
[3124]235        LogIt "Please specify an alternate non-rewinding tape device, such as /dev/nst0" 1
[1885]236        LogIt "or hit <Enter> to boot from another media." 1
[1747]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
[1]246        break
[1747]247        fi
248    done
[1962]249    # For post-init
250    export TAPEDEV=$tapedev
[1]251
[1747]252    if [ "$res" -ne "0" ] ; then
[1410]253        cd /
[1885]254        LogIt "Failed to use tape as extended datadisk. Reverting to another media." 1
255        HandleCDROM
[1410]256        res=$?
[1747]257    else
[1410]258        LogIt "Using tape as extended datadisk. Good." 3
259        echo "Using tape as extd ddisk." > /tmp/TAPEDEV-HAS-DATA-DISKS
260        res=0
[1747]261        CD_MOUNTED_OK=yes
262    fi
263    return $res
[1]264}
265
266
267
[1885]268HandleCDROM() {
[1825]269    # Just in case we have an iLO ensure we will map it correctly
[1830]270    echo "$DENY_MODS" | grep -q "usb-storage "
[1829]271    if [ $? -eq 0 ]; then
272        return
273    fi
[1826]274    echo "Activating a potential USB Storage device"
[2964]275    modprobe -q usb-storage 2> /dev/null
[1826]276    for i in 1 2 3 4 5 6 7 8 9 10 ; do
277        sleep 1
278        echo -en "."
279    done
[1825]280
[1747]281    find-and-mount-cdrom
282    res=$?
283    if [ "$res" -ne "0" ] ; then
[898]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=$?
[1747]289    fi
290    if [ "$res" -eq "0" ] ; then
[898]291        LogIt "OK, I am running on a CD-ROM. Good." 3
[1747]292        CD_MOUNTED_OK=yes
293    else
[1885]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
[898]298        CD_MOUNTED_OK=""
[1747]299    fi
300    return 0
[1]301}
302
303
304PauseForRaids() {
[1747]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
[1]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() {
[1747]322    loc=`which devfsd 2> /dev/null`
323    if [ "$loc" != "" ] ; then
[1]324    LogIt "Devfs found. Testing kernel support..."
325    if [ ! -e "/dev/.devfsd" ] ; then
[746]326        mount -t devfs devfs /dev 2>> $LOGFILE
[1747]327            if [ "$?" -ne "0" ] ; then
[1]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"
[911]337        conffile=`strings $loc | grep -E "devfsd.conf$"`
[1]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
[1747]347    fi
[1]348}
349
[1718]350# Taken from udev management in Mandriva 2008.0. Kudos guys
[2845]351MakeExtraNodes () {
[1718]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 ;;
[1719]360            M) mknod /dev/$name $arg1 && chmod 600 /dev/$name;;
361            *) echo "udev-links.conf: unparseable line (%s %s %s)\n" "$type" "$name" "$arg1" ;;
[1718]362        esac
363    done
364}
365
[2845]366CreateDevMakedev() {
[1792]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}
[1718]373
[1716]374RunUdevd() {
[1718]375    # Inspiration from Mandriva 2008.0 startup script
376    echo "Preparing udev environment..."
[2846]377    LogIt "Preparing udev environment..."
[1718]378    mv /dev /dev.static
379    mkdir /dev
380    mount -n -o size=5M,mode=0755 -t tmpfs none /dev
[2845]381    MakeExtraNodes
[1718]382    mount -n -t devpts -o mode=620 none /dev/pts
383    mount -n -t tmpfs  none /dev/shm
[1789]384    if [ -e /proc/sys/kernel/hotplug ]; then
385        echo > /proc/sys/kernel/hotplug
386    fi
[1734]387    PKLVL=`cut -f1 /proc/sys/kernel/printk`
388    echo 0 > /proc/sys/kernel/printk
[2081]389    # Many possibilities depending on udev versions
[1759]390    if [ -x /sbin/startudev ]; then
391        /sbin/startudev
392    fi
[2081]393    if [ -x /sbin/start_udev ]; then
394        /sbin/start_udev
395    fi
[1759]396    # Depending on udevd version it gives back the hand or not :-(
[2673]397    ps | grep -v grep |grep udevd 2> /dev/null 1> /dev/null
[2437]398    if [ $? -ne 0 ]; then
[2965]399        if [ -x /sbin/udevd ]; then
400            /sbin/udevd --daemon &
401        elif [ -x /usr/bin/udevd ]; then
402            /usr/bin/udevd --daemon &
403        fi
[2437]404        echo "Waiting for udev to start..."
405        sleep 5
[2846]406        LogIt "udev started manually"
[2437]407    fi
[1792]408    mkdir -p /dev/.udev/queue/
[1789]409    if [ -x /sbin/udevtrigger ]; then
410        /sbin/udevtrigger
411    fi
[2442]412    echo "Waiting for udev to discover..."
[2845]413    CreateDevMakedev
[2182]414    # Newer version use udevadm for that
[2437]415    if [ -x /sbin/udevsettle ]; then
[2442]416        /sbin/udevsettle --timeout=10
[2846]417        LogIt "Discovering with udevsettle"
[2965]418    elif [ -x /sbin/udevadm ] || [ -x /usr/bin/udevadm ]; then
419        ua=`UdevadmTrigger`
420        $ua settle --timeout=10
[2846]421        LogIt "Discovering with udevadm"
[1816]422    fi
[1824]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
[1816]431    echo $PKLVL > /proc/sys/kernel/printk
[1716]432}
[1]433
[1761]434RstHW() {
[1]435
[1761]436    # Restore the HW configuration if available (NOT by default)
437    answer="NO"
[1]438
[1815]439    grep -q nohw /proc/cmdline
440    if [ "$?" -eq 0 ]; then
441        return
442    fi
[1761]443    if [ -x ./mindi-rsthw ]; then
444        grep -q RESTORE /proc/cmdline
445        if [ "$?" -ne 0 ]; then
[1815]446            #clear
[1761]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
[1910]457        if [ "$answer" = "YES" ] ; then
[1761]458            ./mindi-rsthw
459        fi
460    fi
461}
[1]462
[1761]463
[1787]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
[1830]467echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
[1829]468if [ $? -eq 0 ]; then
469    return
470fi
[2964]471modprobe -q uhcd_hci 2> /dev/null
472modprobe -q usbhid 2> /dev/null
[1787]473}
[1]474
475
[1787]476
[1]477StartLvms() {
[2477]478    if [ "`grep -i nolvm /proc/cmdline`" ]; then
479        return;
480    fi
[1747]481    if [ -e "/tmp/i-want-my-lvm" ] ; then
482        LogIt "Scanning LVM's..." 1
[739]483        if which lvm ; then
[2964]484            modprobe -q dm-mod 2> /dev/null
485            modprobe -q dm_mod 2> /dev/null
[2845]486            lvm vgscan --mknodes
[739]487        else
[2845]488            vgscan
[739]489        fi
[2533]490
491        # Exclude devices we may not want
492        rm -f /tmp/restorevgs
[2564]493        for d in $MINDI_EXCLUDE_DEVS ; do
[2580]494            echo "LVM exclusion == $d"
[2533]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
[2535]511                    # FIXME: Should search for all possible device names here
[2533]512                    grep -Ev "/dev/$v/$l" /tmp/mountlist.txt > /tmp/mountlist.txt.new
[2550]513                    grep -Ev "/dev/mapper/${v}-$l" /tmp/mountlist.txt.new > /tmp/mountlist.txt
[2533]514                done
515            done
516        done
517
[1747]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
[2845]523            echo -en "."
524            sleep 1
[1747]525        done
526        echo "Done."
527    fi
[1]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.
[1747]530    LogIt "LVM's have been started."
[1]531}
532
[2177]533StartPowerPath() {
[1]534
[2177]535    # Taken from the init script of EMC PowerPath on RHEL
[2845]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
[2177]541
[2845]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
[2177]557            break
[2845]558        fi
559    done
560    if [ "$pdfound" -eq 0 ]; then
561        echo "Unable to start PowerPath"
562    fi
[2177]563
[2845]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
[2177]572}
573
[2072]574StartMpath() {
575    if [ "`grep -i nompath /proc/cmdline`" ]; then
576        return;
577    fi
[2353]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
[2072]583defaults {
584        user_friendly_names yes
585}
586EOF
[2353]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
[2846]591            LogIt "Multipath started"
[2072]592        fi
593    fi
594}
595
[1]596StartRaids() {
[1747]597    local raid_devices i
[1273]598
[2353]599    if [ "`grep -i noraid /proc/cmdline`" ]; then
600        return;
601    fi
602
[1747]603    raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
[623]604    if which raidstart > /dev/null 2> /dev/null ; then
[1747]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
[623]609                LogIt "Running 'raidstart $i'" 1
610                raidstart $i
[1747]611            fi
612        done
[623]613    elif which mdrun > /dev/null 2> /dev/null ; then
[2353]614        if [ "`grep -i nomd /proc/cmdline`" ]; then
615            return;
616        fi
[623]617        LogIt "Running 'mdrun'" 1
618        mdrun
[1273]619    elif which mdadm > /dev/null 2> /dev/null ; then
[2353]620        if [ "`grep -i nomd /proc/cmdline`" ]; then
621            return;
622        fi
[1273]623        LogIt "Running 'mdadm'" 1
624        for i in $raid_devices ; do
[1747]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
[1610]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
[1747]638            fi
639        done
[2075]640    elif which dmraid > /dev/null 2> /dev/null ; then
[2072]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
[623]652    else
653        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
654    fi
655
[1]656}
657
658
659TryAgainToFindCD() {
[1747]660    local res
661    mount | grep /mnt/cdrom && return 0
[1983]662    [ "`grep "backup_media_type" /tmp/mondo-restore.cfg 2> /dev/null | grep "cdstream"`" ] && return
[1747]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
[1]672}
673
674
675
676UseTmpfs()
677{
[1747]678    local mount_cmd
679    echo -en "Mounting /tmp/tmpfs..."
680    mkdir -p /tmp/tmpfs
[1]681# For technical reasons, some sets are as large as 16MB.
682# I am allowing 32MB because selective restore occupies a lot of space.
[3035]683    for size in 256m 128m 64m 48m 40m 32m ; do
[1747]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
[1752]701        mv /tmp/* /tmp.old/
702        # Try to Deal with a busybox bug on inexistant links
[1747]703        cp /tmp/* /tmp.old/
704        rm -f /tmp/*
705        $mount_cmd /tmp
[1752]706        mv /tmp.old/* /tmp/
707        # Try to Deal with a busybox bug on inexistant links
[1747]708        cp /tmp.old/* /tmp/
709        rm -rf /tmp.old
710        mkdir -p /tmp/tmpfs
711        mkdir -p $GROOVY
[1]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
[1747]717    fi
[1]718}
719
720
721WelcomeMessage()
722{
[1747]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."
[1]726which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
[1747]727    echo "Executables and source code are covered by the GNU GPL. No warranty."
728    echo "running on $ARCH"
729    echo "********************************************************************"
[1]730}
731
732EnableCcissIfAppropriate() {
[2908]733    local f
[2913]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
[2925]737        for lun in `/usr/bin/hpsa_obdr_mode -m query /dev/cciss/* 2>&1 | grep "is an OBDR device" | cut -d' ' -f4`; do
[2913]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
[2955]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
[1]755}
756
[1802]757ModprobeAllModules() {
[1]758
[2562]759    lismod=`find /lib/modules -name '*\.ko*' -o -name '*\.o*'`
760    # loading forced modules first
761    for m in $lismod; do
[1927]762        k=`basename $m | sed 's/\.ko.*$//'`
763        j=`basename $k | sed 's/\.o.*$//'`
[2562]764        echo "$FORCE_MODS" | grep -q "$j "
765        if [ $? -eq 0 ]; then
766            echo "Forcing first $j..."
[2964]767            modprobe -q $j 2> /dev/null
[2562]768        fi
769    done
770    for m in $lismod; do
771        k=`basename $m | sed 's/\.ko.*$//'`
772        j=`basename $k | sed 's/\.o.*$//'`
[1830]773        echo "$DENY_MODS" | grep -q "$j "
[1829]774        if [ $? -eq 0 ]; then
[1830]775            echo "Denying $j..."
[1829]776            continue
777        fi
[2562]778        echo "$FORCE_MODS" | grep -q "$j "
779        if [ $? -eq 0 ]; then
780            continue
781        fi
[1829]782        echo "Probing $j..."
[2964]783        modprobe -q $j 2> /dev/null
[1802]784    done
785}
786
[2755]787UdevadmTrigger() {
[2844]788
[2965]789# This function should just echo the return value $ua
790
[2844]791if [ -x /sbin/udevadm ]; then
[2965]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
[2755]808    else
[2965]809        LogIt "... not needed"
[2755]810    fi
[2844]811fi
[2965]812echo $ua
[2755]813}
814
[287]815ExtractDataDisksAndLoadModules() {
[2846]816    LogIt "Installing additional tools ..." 1
[2888]817    # BCO: test return value
[287]818    install-additional-tools
[1800]819    # Keep the kernel silent again
820    PKLVL=`cut -f1 /proc/sys/kernel/printk`
[1802]821    echo 0 > /proc/sys/kernel/printk
[1922]822    ModprobeAllModules
[1800]823    echo $PKLVL > /proc/sys/kernel/printk
[2081]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
[2965]828        ua=`UdevadmTrigger`
[2081]829    fi
[287]830}
[1]831
832# ------------------------ main -----------------------
833
[1698]834MINDI_VER=PBVER
835MINDI_REV=PBREV
[1]836trap CaughtSoftReset SIGTERM
[2964]837trap GetShell SIGINT
[1643]838LOGFILE=/var/log/mondorestore.log
[1236]839PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
[1]840GROOVY=/tmp/groovy-stuff
841USER=root
[2163]842ARCH=`uname -m`
[1]843
[2163]844export PATH GROOVY USER LOGFILE ARCH
845
[1716]846echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
[898]847
[1]848mount -o remount rw /
849[ ! "$GROOVY" ] && Die "I'm not groovy!"
[1885]850for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
[1747]851    mkdir -p $i
[1]852done
853#/bin/update
[2918]854mkdir /proc 2> /dev/null
[1]855mount /proc/ /proc -v -t proc
856mkdir /sys 2> /dev/null
857mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
[1824]858# For ESX 3
859[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
[1]860rm -f /foozero
861
[1829]862if [ "`grep -i denymods /proc/cmdline`" ]; then
863    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
[1830]864else
865    export DENY_MODS=" "
[1829]866fi
[1983]867if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
[1958]868    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
[1960]869    export DENY_MODS="usb-storage $DENY_MODS"
[1958]870fi
[1829]871if [ "`grep -i forcemods /proc/cmdline`" ]; then
872    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
[1830]873else
874    export FORCE_MODS=" "
[1829]875fi
[2533]876if [ "`grep -i excludedevs /proc/cmdline`" ]; then
[2564]877    export MINDI_EXCLUDE_DEVS="`cat /proc/cmdline | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
[2580]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
[2533]882else
[2564]883    export MINDI_EXCLUDE_DEVS=" "
[2533]884fi
[1829]885
[1826]886echo "Activating a potential USB keyboard/mouse"
[1787]887StartUSBKbd
888
[1720]889if [ -f /proc/sys/kernel/exec-shield ]; then
890    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
891fi
[1]892
[1729]893if [ -f /proc/modules ]; then
894    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
895fi
896
[1716]897if [ -e "/tmp/USE-UDEV" ] ; then
[1747]898    RunUdevd
[1716]899fi
[1798]900ExtractDevTarballs
[1]901LaunchTerminals
[1718]902
[1789]903# Keeping kernel silent  for module insertion
904PKLVL=`cut -f1 /proc/sys/kernel/printk`
905echo 0 > /proc/sys/kernel/printk
[1922]906ModprobeAllModules
[1789]907echo $PKLVL > /proc/sys/kernel/printk
[1718]908
[1]909EnableCcissIfAppropriate
910#-------------------------------
911#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
912#-------------------------------
913UseTmpfs
914if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
[1747]915    LogIt "Warning - /tmp/mondo-restore.cfg not found"
[1]916fi
[2182]917if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
[2380]918    # We need to get here exported variables from start-netfs
919    . /sbin/start-netfs
[2182]920fi
[1]921
[1983]922if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
[1747]923    HandleTape
[287]924    ExtractDataDisksAndLoadModules
[737]925elif [ "`grep -i pxe /proc/cmdline`" ]; then
[287]926    # Simulate a local CD
927    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
[1747]928    CD_MOUNTED_OK=yes
[287]929    ExtractDataDisksAndLoadModules
[2182]930    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
[2380]931    sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondo-restore.cfg
[1983]932elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
[1747]933    . /sbin/start-usb
[1698]934
935    # Simulate a local CD
936    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
[1747]937    CD_MOUNTED_OK=yes
[1698]938    ExtractDataDisksAndLoadModules
[1]939else
[1885]940    HandleCDROM
[287]941    ExtractDataDisksAndLoadModules
[2380]942    # We need to get here exported variables from start-netfs
943    . /sbin/start-netfs
[1]944fi
945res=$?
946ConfigureLoggingDaemons
947if [ -e "/tmp/USE-DEVFS" ] ; then
[2878]948    umount -d /mnt/cdrom 2> /dev/null
[1747]949    mv /dev/cdrom /cdrom.lnk 2> /dev/null
950    CD_MOUNTED_OK=""
951    RunDevfsd
[1]952fi
[1813]953LoadKeymap
954WelcomeMessage
955RstHW
[2559]956echo "Starting potential Raid/Multipath ..."
[2580]957[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
[1]958PauseForRaids
959StartRaids
[2072]960StartMpath
[1]961StartLvms
962CopyBootDevEntry
963mkdir -p /tmp/tmpfs
964sleep 2
965#clear
[241]966if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
[1747]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
[1]972fi
973
[241]974if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
[1]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
[1403]983# Log some useful info
[1837]984LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
[1413]985LogIt "/proc/cmdline is:"
[2346]986LogIt "----------"
[1403]987cat /proc/cmdline  >> $LOGFILE
[2346]988LogIt "----------"
[1413]989LogIt "df result:"
990LogIt "----------"
[1403]991df >> $LOGFILE
[1413]992LogIt "-------------"
993LogIt "mount result:"
994LogIt "-------------"
[1403]995mount >> $LOGFILE
[1413]996LogIt "-------------"
997LogIt "lsmod result:"
998LogIt "-------------"
[1403]999lsmod >> $LOGFILE
[1413]1000LogIt "-------------"
[1476]1001LogIt "dmesg result:"
1002LogIt "-------------"
1003dmesg >> $LOGFILE
[2015]1004LogIt "-------------"
[2979]1005LogIt "/proc/mdstat:" >> $LOGFILE
1006LogIt "-------------"
1007cat /proc/mdstat  >> $LOGFILE
1008LogIt "-------------"
[2015]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
[2346]1020LogIt "-------------"
1021LogIt "fdisk result:" >> $LOGFILE
1022LogIt "-------------"
1023fdisk -l  >> $LOGFILE
[2768]1024LogIt "-------------"
[2832]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
[1403]1030
[1983]1031ide-opt
[1]1032
1033#ctrlaltdel soft
1034for i in null stdout stdin stderr ; do
[1747]1035    cp -af /dev/$i /tmp
[1]1036done
[2081]1037# Not sure it's still needed, but shouldn't hurt
1038if [ -e "/tmp/USE-UDEV" ] ; then
[2965]1039    ua=`UdevadmTrigger`
[2081]1040fi
[1]1041if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
[1747]1042    LogIt "backup-media-type is specified in config file - great."
[2197]1043    LogIt "Calling post-init"
[2380]1044    # start-netfs moved it under /tmp as the NFS share is already unmounted
[2255]1045    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
[2533]1046        pre=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
[2255]1047    fi
1048    if [ -x $pre ]; then
1049        echo "Executing preliminary script $pre"
1050        LogIt "Executing preliminary script $pre"
1051        $pre
1052    fi
[1747]1053    post-init
[1]1054else
[1747]1055    LogIt "backup-media-type is not specified in config file."
[1885]1056    LogIt "I think this media has no archives on it."
[1]1057fi
[2255]1058if [ "`grep -i "post=" /proc/cmdline`" ] ; then
[2249]1059    for i in `cat /proc/cmdline` ; do
[2255]1060        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
[2249]1061    done
[2380]1062    # start-netfs moved it under /tmp as the NFS share is already unmounted
[2255]1063    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
1064        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
[2253]1065    fi
[2581]1066    if [ -r $post ]; then
[2255]1067        echo "Executing final script $post"
1068        LogIt "Executing final script $post"
1069        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
[2253]1070            mount-me
1071        fi
[2581]1072        chmod 755 $post
[2255]1073        $post
1074        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
[2253]1075            unmount-me
1076        fi
[2249]1077    fi
1078fi
[1612]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
[2888]1089    GetShell
[1612]1090fi
[1]1091CaughtSoftReset
Note: See TracBrowser for help on using the repository browser.