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

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