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

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