source: branches/3.2/mindi/rootfs/etc/init.d/rcS @ 3484

Last change on this file since 3484 was 3484, checked in by Bruno Cornec, 5 years ago

Fix lvmetad usage on latest Debian (report from Hugo Vanwoerkom)

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