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

Last change on this file since 2965 was 2965, checked in by bruno, 7 years ago

r4564@localhost: bruno | 2012-03-13 00:55:09 +0100

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