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

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