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

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