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

Last change on this file since 2918 was 2918, checked in by bruno, 8 years ago
  • Exclude /run similarly to /sys and /proc
  • Property svn:keywords set to Id
File size: 26.8 KB
Line 
1#!/bin/sh
2#
3# $Id: rcS 2918 2011-12-20 00:18:09Z 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    for f in /proc/driver/cciss/cciss* ; do
671        LogIt "Engaging $f"
672        echo "engage scsi" > $f
673        LogIt "...result=$?"
674    done
675}
676
677ModprobeAllModules() {
678
679    lismod=`find /lib/modules -name '*\.ko*' -o -name '*\.o*'`
680    # loading forced modules first
681    for m in $lismod; do
682        k=`basename $m | sed 's/\.ko.*$//'`
683        j=`basename $k | sed 's/\.o.*$//'`
684        echo "$FORCE_MODS" | grep -q "$j "
685        if [ $? -eq 0 ]; then
686            echo "Forcing first $j..."
687            modprobe -q $j
688        fi
689    done
690    for m in $lismod; do
691        k=`basename $m | sed 's/\.ko.*$//'`
692        j=`basename $k | sed 's/\.o.*$//'`
693        echo "$DENY_MODS" | grep -q "$j "
694        if [ $? -eq 0 ]; then
695            echo "Denying $j..."
696            continue
697        fi
698        echo "$FORCE_MODS" | grep -q "$j "
699        if [ $? -eq 0 ]; then
700            continue
701        fi
702        echo "Probing $j..."
703        modprobe -q $j
704    done
705}
706
707UdevadmTrigger() {
708
709if [ -x /sbin/udevadm ]; then
710    v=`/sbin/udevadm --version`
711    if [ "$v" -ge "146" ]; then
712        /sbin/udevadm trigger --type=failed
713    else
714        /sbin/udevadm trigger --retry-failed
715    fi
716fi
717}
718
719ExtractDataDisksAndLoadModules() {
720    LogIt "Installing additional tools ..." 1
721    # BCO: test return value
722    install-additional-tools
723    # Keep the kernel silent again
724    PKLVL=`cut -f1 /proc/sys/kernel/printk`
725    echo 0 > /proc/sys/kernel/printk
726    ModprobeAllModules
727    echo $PKLVL > /proc/sys/kernel/printk
728
729    # Retry failed udev events now that local filesystems are mounted read-write
730    # (useful for rules creating network ifcfg files)
731    if [ -e "/tmp/USE-UDEV" ] ; then
732        UdevadmTrigger
733    fi
734}
735
736# ------------------------ main -----------------------
737
738MINDI_VER=PBVER
739MINDI_REV=PBREV
740trap CaughtSoftReset SIGTERM
741trap GetShell SIGINTR
742LOGFILE=/var/log/mondorestore.log
743PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
744GROOVY=/tmp/groovy-stuff
745USER=root
746ARCH=`uname -m`
747
748export PATH GROOVY USER LOGFILE ARCH
749
750echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
751
752mount -o remount rw /
753[ ! "$GROOVY" ] && Die "I'm not groovy!"
754for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
755    mkdir -p $i
756done
757#/bin/update
758mkdir /proc 2> /dev/null
759mount /proc/ /proc -v -t proc
760mkdir /sys 2> /dev/null
761mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
762# For ESX 3
763[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
764rm -f /foozero
765
766if [ "`grep -i denymods /proc/cmdline`" ]; then
767    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
768else
769    export DENY_MODS=" "
770fi
771if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
772    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
773    export DENY_MODS="usb-storage $DENY_MODS"
774fi
775if [ "`grep -i forcemods /proc/cmdline`" ]; then
776    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
777else
778    export FORCE_MODS=" "
779fi
780if [ "`grep -i excludedevs /proc/cmdline`" ]; then
781    export MINDI_EXCLUDE_DEVS="`cat /proc/cmdline | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
782    for d in $MINDI_EXCLUDE_DEVS ; do
783        echo "Mountlist exclusion == $d"
784        perl -i -ne 'print $_ unless m~$d~' /tmp/mountlist.txt
785    done
786else
787    export MINDI_EXCLUDE_DEVS=" "
788fi
789
790echo "Activating a potential USB keyboard/mouse"
791StartUSBKbd
792
793if [ -f /proc/sys/kernel/exec-shield ]; then
794    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
795fi
796
797if [ -f /proc/modules ]; then
798    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
799fi
800
801if [ -e "/tmp/USE-UDEV" ] ; then
802    RunUdevd
803fi
804ExtractDevTarballs
805LaunchTerminals
806
807# Keeping kernel silent  for module insertion
808PKLVL=`cut -f1 /proc/sys/kernel/printk`
809echo 0 > /proc/sys/kernel/printk
810ModprobeAllModules
811echo $PKLVL > /proc/sys/kernel/printk
812
813EnableCcissIfAppropriate
814#-------------------------------
815#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
816#-------------------------------
817UseTmpfs
818if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
819    LogIt "Warning - /tmp/mondo-restore.cfg not found"
820fi
821if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
822    # We need to get here exported variables from start-netfs
823    . /sbin/start-netfs
824fi
825
826if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
827    HandleTape
828    ExtractDataDisksAndLoadModules
829elif [ "`grep -i pxe /proc/cmdline`" ]; then
830    # Simulate a local CD
831    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
832    CD_MOUNTED_OK=yes
833    ExtractDataDisksAndLoadModules
834    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
835    sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondo-restore.cfg
836elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
837    . /sbin/start-usb
838
839    # Simulate a local CD
840    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
841    CD_MOUNTED_OK=yes
842    ExtractDataDisksAndLoadModules
843else
844    HandleCDROM
845    ExtractDataDisksAndLoadModules
846    # We need to get here exported variables from start-netfs
847    . /sbin/start-netfs
848fi
849res=$?
850ConfigureLoggingDaemons
851if [ -e "/tmp/USE-DEVFS" ] ; then
852    umount -d /mnt/cdrom 2> /dev/null
853    mv /dev/cdrom /cdrom.lnk 2> /dev/null
854    CD_MOUNTED_OK=""
855    RunDevfsd
856fi
857LoadKeymap
858WelcomeMessage
859RstHW
860echo "Starting potential Raid/Multipath ..."
861[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
862PauseForRaids
863StartRaids
864StartMpath
865StartLvms
866CopyBootDevEntry
867mkdir -p /tmp/tmpfs
868sleep 2
869#clear
870if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
871    LogIt "Creating /dev/md/* softlinks just in case." 1
872    mkdir -p /dev/md
873    cp -af /dev/md0 /dev/md/0 2> /dev/null
874    cp -af /dev/md1 /dev/md/1 2> /dev/null
875    cp -af /dev/md2 /dev/md/2 2> /dev/null
876fi
877
878if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
879    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
880    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
881    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
882    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
883    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
884fi
885hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
886
887# Log some useful info
888LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
889LogIt "/proc/cmdline is:"
890LogIt "----------"
891cat /proc/cmdline  >> $LOGFILE
892LogIt "----------"
893LogIt "df result:"
894LogIt "----------"
895df >> $LOGFILE
896LogIt "-------------"
897LogIt "mount result:"
898LogIt "-------------"
899mount >> $LOGFILE
900LogIt "-------------"
901LogIt "lsmod result:"
902LogIt "-------------"
903lsmod >> $LOGFILE
904LogIt "-------------"
905LogIt "dmesg result:"
906LogIt "-------------"
907dmesg >> $LOGFILE
908LogIt "-------------"
909LogIt "/proc/swaps:" >> $LOGFILE
910LogIt "-------------"
911cat /proc/swaps  >> $LOGFILE
912LogIt "-------------"
913LogIt "/proc/filesystems:" >> $LOGFILE
914LogIt "-------------"
915cat /proc/filesystems  >> $LOGFILE
916LogIt "-------------"
917LogIt "/proc/partitions:" >> $LOGFILE
918LogIt "-------------"
919cat /proc/partitions  >> $LOGFILE
920LogIt "-------------"
921LogIt "fdisk result:" >> $LOGFILE
922LogIt "-------------"
923fdisk -l  >> $LOGFILE
924LogIt "-------------"
925if [ -f /tmp/mondo-restore.cfg ]; then
926    LogIt "/tmp/mondo-restore.cfg result:" >> $LOGFILE
927    LogIt "-------------"
928    cat /tmp/mondo-restore.cfg  >> $LOGFILE
929fi
930
931ide-opt
932
933#ctrlaltdel soft
934for i in null stdout stdin stderr ; do
935    cp -af /dev/$i /tmp
936done
937# Not sure it's still needed, but shouldn't hurt
938if [ -e "/tmp/USE-UDEV" ] ; then
939    UdevadmTrigger
940fi
941if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
942    LogIt "backup-media-type is specified in config file - great."
943    LogIt "Calling post-init"
944    # start-netfs moved it under /tmp as the NFS share is already unmounted
945    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
946        pre=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
947    fi
948    if [ -x $pre ]; then
949        echo "Executing preliminary script $pre"
950        LogIt "Executing preliminary script $pre"
951        $pre
952    fi
953    post-init
954else
955    LogIt "backup-media-type is not specified in config file."
956    LogIt "I think this media has no archives on it."
957fi
958if [ "`grep -i "post=" /proc/cmdline`" ] ; then
959    for i in `cat /proc/cmdline` ; do
960        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
961    done
962    # start-netfs moved it under /tmp as the NFS share is already unmounted
963    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
964        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
965    fi
966    if [ -r $post ]; then
967        echo "Executing final script $post"
968        LogIt "Executing final script $post"
969        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
970            mount-me
971        fi
972        chmod 755 $post
973        $post
974        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
975            unmount-me
976        fi
977    fi
978fi
979if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
980    echo "Rebooting in 10 seconds automatically as per reboot order"
981    echo -en "Press ^C to interrupt if you have to ..."
982    for i in 1 2 3 4 5 6 7 8 9 10 ; do
983        sleep 1
984        echo -en "."
985    done
986    echo "Boom."
987    sleep 1
988else
989    GetShell
990fi
991CaughtSoftReset
Note: See TracBrowser for help on using the repository browser.