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

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