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

Last change on this file since 3154 was 3154, checked in by bruno, 6 years ago
  • Remove the introduction of LogProgress? in ListKernelModulePaths? which should stay quiet
  • Remove a remaining support of max-noof-media in confidure.in now gone.
  • Fix #640 by cleaning up fully the managemnt of tmpdir and scratchdir (one function for the creation, one point of removal at end, intermediate removal if needed, clean naming conventions, unify mkdtemp usage, remove sensibly_set_tmpdir_and_scratchdir function). Consequence is that default dir for scratchdir if nothing else specified is /tmp using CLI and the largest partition using the GUI.
  • Fix a bug introduced in process_the_s_switch with intermediate variables which weren't initialized correctly.
  • Property svn:keywords set to Id
File size: 30.2 KB
Line 
1#!/bin/sh
2#
3# $Id: rcS 3154 2013-06-22 22:34:33Z 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 $console ]]; then
62        setsid sh -c "exec sh <$console >$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 [ -f $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        fi
403        echo "Waiting for udev to start..."
404        sleep 5
405        LogIt "udev started manually"
406    fi
407    mkdir -p /dev/.udev/queue/
408    if [ -x /sbin/udevtrigger ]; then
409        /sbin/udevtrigger
410    fi
411    echo "Waiting for udev to discover..."
412    CreateDevMakedev
413    # Newer version use udevadm for that
414    if [ -x /sbin/udevsettle ]; then
415        /sbin/udevsettle --timeout=10
416        LogIt "Discovering with udevsettle"
417    elif [ -x /sbin/udevadm ] || [ -x /usr/bin/udevadm ]; then
418        ua=`UdevadmTrigger`
419        $ua settle --timeout=10
420        LogIt "Discovering with udevadm"
421    fi
422    # It seems we need to have more static devs on some distro were
423    # udev as some other requirements to be covered later on.
424    # So in the mean time:
425    for d in `ls /dev.static`; do
426        if [ ! -e /dev/$d ]; then
427            mv /dev.static/$d /dev
428        fi
429    done
430    echo $PKLVL > /proc/sys/kernel/printk
431}
432
433RstHW() {
434
435    # Restore the HW configuration if available (NOT by default)
436    answer="NO"
437
438    grep -q nohw /proc/cmdline
439    if [ "$?" -eq 0 ]; then
440        return
441    fi
442    if [ -x ./mindi-rsthw ]; then
443        grep -q RESTORE /proc/cmdline
444        if [ "$?" -ne 0 ]; then
445            #clear
446            echo "*********************************************************************"
447            echo "Do you want to restore the HW configuration of the original machine ?"
448            echo "(This may dammage your hardware so be sure to check twice before saying yes)"
449            echo "*********************************************************************"
450            echo "Please confirm by typing YES exactly as written here (NO by default)"
451            echo -n "--> "
452            read answer
453        else
454            answer="YES"
455        fi
456        if [ "$answer" = "YES" ] ; then
457            ./mindi-rsthw
458        fi
459    fi
460}
461
462
463StartUSBKbd() {
464# Prepare minimal USB env in case we have USB kbd such as with iLO
465[ -d /proc/bus/usb ] && ! grep -q /proc/bus/usb /proc/mounts && mount -t usbfs none /proc/bus/usb
466echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
467if [ $? -eq 0 ]; then
468    return
469fi
470modprobe -q uhcd_hci 2> /dev/null
471modprobe -q usbhid 2> /dev/null
472}
473
474
475
476StartLvms() {
477    if [ "`grep -i nolvm /proc/cmdline`" ]; then
478        return;
479    fi
480    if [ -e "/tmp/i-want-my-lvm" ] ; then
481        LogIt "Scanning LVM's..." 1
482        if which lvm ; then
483            modprobe -q dm-mod 2> /dev/null
484            modprobe -q dm_mod 2> /dev/null
485            lvm vgscan --mknodes
486        else
487            vgscan
488        fi
489
490        # Exclude devices we may not want
491        rm -f /tmp/restorevgs
492        for d in $MINDI_EXCLUDE_DEVS ; do
493            echo "LVM exclusion == $d"
494            EXCLUDE_VGS=`grep " $d" /tmp/i-want-my-lvm | grep vgcreate | awk '{print $4}'`
495            vg=`echo $EXCLUDE_VGS | sed "s/ /|/g"`
496            if [ "$vg" != "" ]; then
497                re=" $d|$vg"
498            else 
499                re=" $d"
500            fi
501            # Remove VGs from i-want-my-lvm
502            grep -Ev "$re" /tmp/i-want-my-lvm > /tmp/i-want-my-lvm.new
503            mv /tmp/i-want-my-lvm.new /tmp/i-want-my-lvm
504            # Prepare  script to restore the VG exluded here if needed
505            for v in $EXCLUDE_VGS; do
506                echo "vgcfgrestore $v" >> /tmp/restorevgs
507                # Remove LVs from mountlist
508                EXCLUDE_LVS=`grep " $v" /tmp/i-want-my-lvm | grep lvcreate | sed "s/^.*-n \([^ ][^ ]*\) .*$/$1/"`
509                for l in $EXCLUDE_LVS; do
510                    # FIXME: Should search for all possible device names here
511                    grep -Ev "/dev/$v/$l" /tmp/mountlist.txt > /tmp/mountlist.txt.new
512                    grep -Ev "/dev/mapper/${v}-$l" /tmp/mountlist.txt.new > /tmp/mountlist.txt
513                done
514            done
515        done
516
517        grep -E "^#.*vgchange" /tmp/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
518        chmod +x /tmp/start-lvm
519        echo -en "Starting LVM's..."
520        /tmp/start-lvm &
521        for i in 1 2 3 4 5 ; do
522            echo -en "."
523            sleep 1
524        done
525        echo "Done."
526    fi
527# If necessary, cannibalize 'analyze-my-lvm'; copy some of its code here,
528# pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
529    LogIt "LVM's have been started."
530}
531
532StartPowerPath() {
533
534    # Taken from the init script of EMC PowerPath on RHEL
535    if [ -f /etc/emcp_devicesDB.dat ]; then 
536        if [ -f /etc/emcp_devicesDB.idx ]; then
537            /etc/opt/emcpower/emcpmgr map -p > /dev/null 2>&1
538        fi
539    fi
540
541    /sbin/powermt config > /dev/null 2>&1
542    #   Wait for udev to finish creating emcpower devices
543    #
544    pdfound=1
545    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
546        pdfound=1
547        for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
548            bpd=`basename $pd`
549            if [ ! -e /dev/$bpd ]; then
550                pdfound=0
551                sleep 2
552                break;
553            fi
554        done
555        if [ "$pdfound" -eq 1 ]; then
556            break
557        fi
558    done
559    if [ "$pdfound" -eq 0 ]; then
560        echo "Unable to start PowerPath"
561    fi
562
563    /sbin/powermt load      > /dev/null 2>&1
564    /etc/opt/emcpower/emcpmgr map   > /dev/null 2>&1
565    /etc/opt/emcpower/powercf -C    > /dev/null 2>&1
566    if [ ! -e /etc/powermt.custom ]; then 
567        /sbin/powermt save      > /dev/null 2>&1
568    fi 
569    /sbin/powermt register  > /dev/null 2>&1
570    /sbin/powermig transition -startup -noprompt    > /dev/null 2>&1
571}
572
573StartMpath() {
574    if [ "`grep -i nompath /proc/cmdline`" ]; then
575        return;
576    fi
577    if [ "`grep mpath /tmp/mountlist.txt`" ]; then
578        if [ -x /sbin/multipath ]; then
579            echo "Starting Mpath..."
580            mkdir -p /var/lib/multipath
581            cat > /etc/multipath.conf << EOF
582defaults {
583        user_friendly_names yes
584}
585EOF
586            /sbin/multipath -v 0
587            if [ -x /sbin/kpartx ]; then
588                /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
589            fi
590            LogIt "Multipath started"
591        fi
592    fi
593}
594
595StartRaids() {
596    local raid_devices i
597
598    if [ "`grep -i noraid /proc/cmdline`" ]; then
599        return;
600    fi
601
602    raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
603    if which raidstart > /dev/null 2> /dev/null ; then
604        for i in $raid_devices ; do
605            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
606                LogIt "$i is started already; no need to run 'raidstart $i'" 1
607            else
608                LogIt "Running 'raidstart $i'" 1
609                raidstart $i
610            fi
611        done
612    elif which mdrun > /dev/null 2> /dev/null ; then
613        if [ "`grep -i nomd /proc/cmdline`" ]; then
614            return;
615        fi
616        LogIt "Running 'mdrun'" 1
617        mdrun
618    elif which mdadm > /dev/null 2> /dev/null ; then
619        if [ "`grep -i nomd /proc/cmdline`" ]; then
620            return;
621        fi
622        LogIt "Running 'mdadm'" 1
623        for i in $raid_devices ; do
624            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
625                LogIt "$i is started already; no need to run 'mdadm $i'" 1
626            else
627                if [ -f /etc/mdadm.conf ] ; then
628                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm.conf" 1
629                    mdadm -A $i -c /etc/mdadm.conf
630                elif [ -f /etc/mdadm/mdadm.conf ] ; then
631                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm/mdadm.conf" 1
632                    mdadm -A $i -c /etc/mdadm/mdadm.conf
633                else
634                    LogIt "Running 'mdadm $i'" 1
635                    mdadm -Ac partitions -m dev $i
636                fi
637            fi
638        done
639    elif which dmraid > /dev/null 2> /dev/null ; then
640        if [ "`grep -i nodmraid /proc/cmdline`" ]; then
641            return;
642        fi
643        for x in $(/sbin/dmraid -ay -i -p -t 2>/dev/null | grep -E  -iv "^no " |awk -F ':' '{ print $1 }') ; do
644            echo "Please send the result of /sbin/dmraid -ay -i -p -t to the devteam !!!"
645            return
646            #dmname=$(resolve_dm_name $x)
647            #[ -z "$dmname" ] && continue
648            #/sbin/dmraid  -ay -i -p "$dmname" >/dev/null 2>&1
649            #/sbin/kpartx -a -p p "/dev/mapper/$dmname"
650        done
651    else
652        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
653    fi
654
655}
656
657
658TryAgainToFindCD() {
659    local res
660    mount | grep /mnt/cdrom && return 0
661    [ "`grep "backup_media_type" /tmp/mondo-restore.cfg 2> /dev/null | grep "cdstream"`" ] && return
662    LogIt "Trying to mount CD-ROM a 2nd time..."
663    find-and-mount-cdrom --second-try
664    res=$?
665    if [ "$res" -eq "0" ] ; then
666        CD_MOUNTED_OK=yes
667        LogIt "CD-ROM drive mounted successfully." 1
668    else
669        LogIt "I still cannot find or mount the CD-ROM drive, by the way."
670    fi
671}
672
673
674
675UseTmpfs()
676{
677    local mount_cmd
678    echo -en "Mounting /tmp/tmpfs..."
679    mkdir -p /tmp/tmpfs
680# For technical reasons, some sets are as large as 16MB.
681# I am allowing 32MB because selective restore occupies a lot of space.
682    for size in 256m 128m 64m 48m 40m 32m ; do
683        mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
684        LogIt "Trying '$mount_cmd'"
685        $mount_cmd /tmp/tmpfs 2>> $LOGFILE
686        res=$?
687        [ "$res" -eq "0" ] && break
688    done
689    if [ "$res" -ne "0" ] ; then
690        LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
691        umount /tmp/tmpfs > /dev/null 2> /dev/null
692        rmdir /tmp/tmpfs
693        ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondo-restore
694        LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
695    else
696        LogIt "Great. Pivot succeeded w/ size=$size" 1
697        echo -en "Pivoting /tmp..."
698        umount /tmp/tmpfs
699        mkdir -p /tmp.old
700        mv /tmp/* /tmp.old/
701        # Try to Deal with a busybox bug on inexistant links
702        cp /tmp/* /tmp.old/
703        rm -f /tmp/*
704        $mount_cmd /tmp
705        mv /tmp.old/* /tmp/
706        # Try to Deal with a busybox bug on inexistant links
707        cp /tmp.old/* /tmp/
708        rm -rf /tmp.old
709        mkdir -p /tmp/tmpfs
710        mkdir -p $GROOVY
711    echo "Done."
712    LogIt "Successfully mounted dynamic /tmp ramdisk"
713#   mkdir -p /tmp/tmpfs/var
714#        mv -f /var/log /tmp/tmpfs/var/log
715#        ln -sf /tmp/tmpfs/var/log /var/log
716    fi
717}
718
719
720WelcomeMessage()
721{
722    echo "********************************************************************"
723    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
724    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
725which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
726    echo "Executables and source code are covered by the GNU GPL. No warranty."
727    echo "running on $ARCH"
728    echo "********************************************************************"
729}
730
731EnableCcissIfAppropriate() {
732    local f
733
734    # In some cases, the OBDR tape remains in CD-ROM mode. This branch solves that issue (#498)
735    if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] && [ -x /usr/bin/hpsa_obdr_mode ]; then
736        for lun in `/usr/bin/hpsa_obdr_mode -m query /dev/cciss/* 2>&1 | grep "is an OBDR device" | cut -d' ' -f4`; do
737            /usr/bin/hpsa_obdr_mode -m query -l $lun /dev/cciss/* 2>&1 | grep -q "is in CD-ROM mode"
738            if [ $? -eq 0 ]; then
739                # This tape/lun should be brought back in Sequential mode
740                LogIt "Putting back tape $lun in Sequential mode..."
741                /usr/bin/hpsa_obdr_mode -m tape -l $lun /dev/cciss/* 2>&1 > /dev/null
742            fi
743        done
744    fi
745
746    # Now engage all Smart Array controllers to detect attached devices
747    if [ -d  "/proc/driver/cciss" ]; then
748        for f in /proc/driver/cciss/cciss* ; do
749            LogIt "Engaging $f"
750            echo "engage scsi" > $f
751            LogIt "...result=$?"
752        done
753    fi
754}
755
756ModprobeAllModules() {
757
758    lismod=`find /lib/modules -name '*\.ko*' -o -name '*\.o*'`
759    # loading forced modules first
760    for m in $lismod; do
761        k=`basename $m | sed 's/\.ko.*$//'`
762        j=`basename $k | sed 's/\.o.*$//'`
763        echo "$FORCE_MODS" | grep -q "$j "
764        if [ $? -eq 0 ]; then
765            echo "Forcing first $j..."
766            modprobe -q $j 2> /dev/null
767        fi
768    done
769    for m in $lismod; do
770        k=`basename $m | sed 's/\.ko.*$//'`
771        j=`basename $k | sed 's/\.o.*$//'`
772        echo "$DENY_MODS" | grep -q "$j "
773        if [ $? -eq 0 ]; then
774            echo "Denying $j..."
775            continue
776        fi
777        echo "$FORCE_MODS" | grep -q "$j "
778        if [ $? -eq 0 ]; then
779            continue
780        fi
781        echo "Probing $j..."
782        modprobe -q $j 2> /dev/null
783    done
784}
785
786UdevadmTrigger() {
787
788# This function should just echo the return value $ua
789
790if [ -x /sbin/udevadm ]; then
791    ua="/sbin/udevadm"
792elif [ -x /usr/bin/udevadm ]; then
793    ua="/usr/bin/udevadm"
794else
795    LogIt "WARNING: Unable to find udevadm. Not triggering udev"
796    ua="/bin/true"
797fi
798
799v="`$ua --version`"
800
801if [ -x "$v" ]; then
802    LogIt "Triggering udev again..."
803    if [ "$v" -ge "146" -a "$v" -lt "174" ]; then
804        $ua trigger --type=failed
805    elif [ "$v" -lt "146" ]; then
806        $ua trigger --retry-failed
807    else
808        LogIt "... not needed"
809    fi
810fi
811echo $ua
812}
813
814ExtractDataDisksAndLoadModules() {
815    LogIt "Installing additional tools ..." 1
816    # BCO: test return value
817    install-additional-tools
818    # Keep the kernel silent again
819    PKLVL=`cut -f1 /proc/sys/kernel/printk`
820    echo 0 > /proc/sys/kernel/printk
821    ModprobeAllModules
822    echo $PKLVL > /proc/sys/kernel/printk
823
824    # Retry failed udev events now that local filesystems are mounted read-write
825    # (useful for rules creating network ifcfg files)
826    if [ -e "/tmp/USE-UDEV" ] ; then
827        ua=`UdevadmTrigger`
828    fi
829}
830
831# ------------------------ main -----------------------
832
833MINDI_VER=PBVER
834MINDI_REV=PBREV
835trap CaughtSoftReset SIGTERM
836trap GetShell SIGINT
837LOGFILE=/var/log/mondorestore.log
838PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
839GROOVY=/tmp/groovy-stuff
840USER=root
841ARCH=`uname -m`
842
843export PATH GROOVY USER LOGFILE ARCH
844
845echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
846
847mount -o remount rw /
848[ ! "$GROOVY" ] && Die "I'm not groovy!"
849for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
850    mkdir -p $i
851done
852#/bin/update
853mkdir /proc 2> /dev/null
854mount /proc/ /proc -v -t proc
855mkdir /sys 2> /dev/null
856mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
857# For ESX 3
858[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
859rm -f /foozero
860
861if [ "`grep -i denymods /proc/cmdline`" ]; then
862    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
863else
864    export DENY_MODS=" "
865fi
866if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
867    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
868    export DENY_MODS="usb-storage $DENY_MODS"
869fi
870if [ "`grep -i forcemods /proc/cmdline`" ]; then
871    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
872else
873    export FORCE_MODS=" "
874fi
875if [ "`grep -i excludedevs /proc/cmdline`" ]; then
876    export MINDI_EXCLUDE_DEVS="`cat /proc/cmdline | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
877    for d in $MINDI_EXCLUDE_DEVS ; do
878        echo "Mountlist exclusion == $d"
879        perl -i -ne 'print $_ unless m~$d~' /tmp/mountlist.txt
880    done
881else
882    export MINDI_EXCLUDE_DEVS=" "
883fi
884
885echo "Activating a potential USB keyboard/mouse"
886StartUSBKbd
887
888if [ -f /proc/sys/kernel/exec-shield ]; then
889    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
890fi
891
892if [ -f /proc/modules ]; then
893    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
894fi
895
896if [ -e "/tmp/USE-UDEV" ] ; then
897    RunUdevd
898fi
899ExtractDevTarballs
900LaunchTerminals
901
902# Keeping kernel silent  for module insertion
903PKLVL=`cut -f1 /proc/sys/kernel/printk`
904echo 0 > /proc/sys/kernel/printk
905ModprobeAllModules
906echo $PKLVL > /proc/sys/kernel/printk
907
908EnableCcissIfAppropriate
909#-------------------------------
910#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
911#-------------------------------
912UseTmpfs
913if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
914    LogIt "Warning - /tmp/mondo-restore.cfg not found"
915fi
916if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
917    # We need to get here exported variables from start-netfs
918    . /sbin/start-netfs
919fi
920
921if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
922    HandleTape
923    ExtractDataDisksAndLoadModules
924elif [ "`grep -i pxe /proc/cmdline`" ]; then
925    # Simulate a local CD
926    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
927    CD_MOUNTED_OK=yes
928    ExtractDataDisksAndLoadModules
929    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
930    sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondo-restore.cfg
931elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
932    . /sbin/start-usb
933
934    # Simulate a local CD
935    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
936    CD_MOUNTED_OK=yes
937    ExtractDataDisksAndLoadModules
938else
939    HandleCDROM
940    ExtractDataDisksAndLoadModules
941    # We need to get here exported variables from start-netfs
942    . /sbin/start-netfs
943fi
944res=$?
945ConfigureLoggingDaemons
946if [ -e "/tmp/USE-DEVFS" ] ; then
947    umount -d /mnt/cdrom 2> /dev/null
948    mv /dev/cdrom /cdrom.lnk 2> /dev/null
949    CD_MOUNTED_OK=""
950    RunDevfsd
951fi
952LoadKeymap
953WelcomeMessage
954RstHW
955echo "Starting potential Raid/Multipath ..."
956[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
957PauseForRaids
958StartRaids
959StartMpath
960StartLvms
961CopyBootDevEntry
962mkdir -p /tmp/tmpfs
963sleep 2
964#clear
965if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
966    LogIt "Creating /dev/md/* softlinks just in case." 1
967    mkdir -p /dev/md
968    cp -af /dev/md0 /dev/md/0 2> /dev/null
969    cp -af /dev/md1 /dev/md/1 2> /dev/null
970    cp -af /dev/md2 /dev/md/2 2> /dev/null
971fi
972
973if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
974    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
975    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
976    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
977    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
978    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
979fi
980hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
981
982# Log some useful info
983LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
984LogIt "/proc/cmdline is:"
985LogIt "----------"
986cat /proc/cmdline  >> $LOGFILE
987LogIt "----------"
988LogIt "df result:"
989LogIt "----------"
990df >> $LOGFILE
991LogIt "-------------"
992LogIt "mount result:"
993LogIt "-------------"
994mount >> $LOGFILE
995LogIt "-------------"
996LogIt "lsmod result:"
997LogIt "-------------"
998lsmod >> $LOGFILE
999LogIt "-------------"
1000LogIt "dmesg result:"
1001LogIt "-------------"
1002dmesg >> $LOGFILE
1003LogIt "-------------"
1004LogIt "/proc/mdstat:" >> $LOGFILE
1005LogIt "-------------"
1006cat /proc/mdstat  >> $LOGFILE
1007LogIt "-------------"
1008LogIt "/proc/swaps:" >> $LOGFILE
1009LogIt "-------------"
1010cat /proc/swaps  >> $LOGFILE
1011LogIt "-------------"
1012LogIt "/proc/filesystems:" >> $LOGFILE
1013LogIt "-------------"
1014cat /proc/filesystems  >> $LOGFILE
1015LogIt "-------------"
1016LogIt "/proc/partitions:" >> $LOGFILE
1017LogIt "-------------"
1018cat /proc/partitions  >> $LOGFILE
1019LogIt "-------------"
1020LogIt "fdisk result:" >> $LOGFILE
1021LogIt "-------------"
1022fdisk -l  >> $LOGFILE
1023LogIt "-------------"
1024if [ -f /tmp/mondo-restore.cfg ]; then
1025    LogIt "/tmp/mondo-restore.cfg result:" >> $LOGFILE
1026    LogIt "-------------"
1027    cat /tmp/mondo-restore.cfg  >> $LOGFILE
1028fi
1029
1030ide-opt
1031
1032#ctrlaltdel soft
1033for i in null stdout stdin stderr ; do
1034    cp -af /dev/$i /tmp
1035done
1036# Not sure it's still needed, but shouldn't hurt
1037if [ -e "/tmp/USE-UDEV" ] ; then
1038    ua=`UdevadmTrigger`
1039fi
1040if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
1041    LogIt "backup-media-type is specified in config file - great."
1042    LogIt "Calling post-init"
1043    # start-netfs moved it under /tmp as the NFS share is already unmounted
1044    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
1045        pre=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
1046    fi
1047    if [ -x $pre ]; then
1048        echo "Executing preliminary script $pre"
1049        LogIt "Executing preliminary script $pre"
1050        $pre
1051    fi
1052    post-init
1053else
1054    LogIt "backup-media-type is not specified in config file."
1055    LogIt "I think this media has no archives on it."
1056fi
1057if [ "`grep -i "post=" /proc/cmdline`" ] ; then
1058    for i in `cat /proc/cmdline` ; do
1059        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
1060    done
1061    # start-netfs moved it under /tmp as the NFS share is already unmounted
1062    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
1063        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
1064    fi
1065    if [ -r $post ]; then
1066        echo "Executing final script $post"
1067        LogIt "Executing final script $post"
1068        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
1069            mount-me
1070        fi
1071        chmod 755 $post
1072        $post
1073        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
1074            unmount-me
1075        fi
1076    fi
1077fi
1078if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
1079    echo "Rebooting in 10 seconds automatically as per reboot order"
1080    echo -en "Press ^C to interrupt if you have to ..."
1081    for i in 1 2 3 4 5 6 7 8 9 10 ; do
1082        sleep 1
1083        echo -en "."
1084    done
1085    echo "Boom."
1086    sleep 1
1087else
1088    GetShell
1089fi
1090CaughtSoftReset
Note: See TracBrowser for help on using the repository browser.