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

Last change on this file since 3278 was 3278, checked in by Bruno Cornec, 6 years ago
  • File KEYMAP-LIVES-HERE, USING-* not used anymore
  • Nomalize name usinf iso-dir and ISO-DIR where relevant
  • config entry netfs-server-path not used anymore (iso-dir instead when needed)
  • In network restore mode, also have the extended boot messages
  • Manages grub2 version string as grub 1 was
  • Property svn:keywords set to Id
File size: 31.3 KB
Line 
1#!/bin/bash
2#
3# $Id: rcS 3278 2014-04-30 10:30:11Z 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=`cat /tmp/KEYMAP-LIVES-HERE 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    mount -n -o size=5M,mode=0755 -t tmpfs none /dev
386    MakeExtraNodes
387    mount -n -t devpts -o mode=620 none /dev/pts
388    mount -n -t tmpfs  none /dev/shm
389    if [ -e /proc/sys/kernel/hotplug ]; then
390        echo > /proc/sys/kernel/hotplug
391    fi
392    PKLVL=`cut -f1 /proc/sys/kernel/printk`
393    echo 0 > /proc/sys/kernel/printk
394    # Many possibilities depending on udev versions
395    if [ -x /sbin/startudev ]; then
396        /sbin/startudev
397    fi
398    if [ -x /sbin/start_udev ]; then
399        /sbin/start_udev
400    fi
401    # Depending on udevd version it gives back the hand or not :-(
402    ps | grep -v grep |grep udevd 2> /dev/null 1> /dev/null
403    if [ $? -ne 0 ]; then
404        echo "Waiting for udev to start..."
405        if [ -x /sbin/udevd ]; then
406            /sbin/udevd --daemon &
407        elif [ -x /usr/bin/udevd ]; then
408            /usr/bin/udevd --daemon &
409        elif [ -x /usr/lib/systemd/systemd-udevd ]; then
410            # from https://github.com/hut/minirc/blob/master/rc
411            echo "INFO: This is the systemd version of udev"
412            mkdir -p /run/systemd/journal
413            /usr/lib/systemd/systemd-udevd --daemon
414            udevadm trigger --action=add --type=subsystems
415            udevadm trigger --action=add --type=devices
416        fi
417        sleep 5
418        LogIt "udev started manually" 1
419    fi
420    mkdir -p /dev/.udev/queue/
421    if [ -x /sbin/udevtrigger ]; then
422        /sbin/udevtrigger
423    fi
424    echo "Waiting for udev to discover..."
425    CreateDevMakedev
426    # Newer version use udevadm for that
427    if [ -x /sbin/udevsettle ]; then
428        /sbin/udevsettle --timeout=10
429        LogIt "Discovering with udevsettle"
430    elif [ -x /sbin/udevadm ] || [ -x /usr/bin/udevadm ]; then
431        ua=`UdevadmTrigger`
432        $ua settle --timeout=10
433        LogIt "Discovering with udevadm"
434    fi
435    # It seems we need to have more static devs on some distro were
436    # udev as some other requirements to be covered later on.
437    # So in the mean time:
438    for d in `ls /dev.static`; do
439        if [ ! -e /dev/$d ]; then
440            mv /dev.static/$d /dev
441        fi
442    done
443    echo $PKLVL > /proc/sys/kernel/printk
444}
445
446RstHW() {
447
448    # Restore the HW configuration if available (NOT by default)
449    answer="NO"
450
451    grep -q nohw /proc/cmdline
452    if [ "$?" -eq 0 ]; then
453        return
454    fi
455    if [ -x ./mindi-rsthw ]; then
456        grep -q RESTORE /proc/cmdline
457        if [ "$?" -ne 0 ]; then
458            #clear
459            echo "*********************************************************************"
460            echo "Do you want to restore the HW configuration of the original machine ?"
461            echo "(This may dammage your hardware so be sure to check twice before saying yes)"
462            echo "*********************************************************************"
463            echo "Please confirm by typing YES exactly as written here (NO by default)"
464            echo -n "--> "
465            read answer
466        else
467            answer="YES"
468        fi
469        if [ "$answer" = "YES" ] ; then
470            ./mindi-rsthw
471        fi
472    fi
473}
474
475
476StartUSBKbd() {
477# Prepare minimal USB env in case we have USB kbd such as with iLO
478[ -d /proc/bus/usb ] && ! grep -q /proc/bus/usb /proc/mounts && mount -t usbfs none /proc/bus/usb
479echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
480if [ $? -eq 0 ]; then
481    return
482fi
483modprobe -q uhcd_hci 2> /dev/null
484modprobe -q usbhid 2> /dev/null
485}
486
487
488
489StartLvms() {
490    if [ "`grep -i nolvm /proc/cmdline`" ]; then
491        return;
492    fi
493    if [ -e "/tmp/i-want-my-lvm" ] ; then
494        # Recent LVM need this caching daemon to work
495        if [ -x /usr/sbin/lvmetad ]; then
496            mkdir -p /run/lvm
497            /usr/sbin/lvmetad
498        fi
499        LogIt "Scanning LVM's..." 1
500        if which lvm ; then
501            modprobe -q dm-mod 2> /dev/null
502            modprobe -q dm_mod 2> /dev/null
503            lvm vgscan --mknodes
504        else
505            vgscan
506        fi
507
508        # Exclude devices we may not want
509        rm -f /tmp/restorevgs
510        for d in $MINDI_EXCLUDE_DEVS ; do
511            echo "LVM exclusion == $d"
512            EXCLUDE_VGS=`grep " $d" /tmp/i-want-my-lvm | grep vgcreate | awk '{print $4}'`
513            vg=`echo $EXCLUDE_VGS | sed "s/ /|/g"`
514            if [ "$vg" != "" ]; then
515                re=" $d|$vg"
516            else 
517                re=" $d"
518            fi
519            # Remove VGs from i-want-my-lvm
520            grep -Ev "$re" /tmp/i-want-my-lvm > /tmp/i-want-my-lvm.new
521            mv /tmp/i-want-my-lvm.new /tmp/i-want-my-lvm
522            # Prepare  script to restore the VG exluded here if needed
523            for v in $EXCLUDE_VGS; do
524                echo "vgcfgrestore $v" >> /tmp/restorevgs
525                # Remove LVs from mountlist
526                EXCLUDE_LVS=`grep " $v" /tmp/i-want-my-lvm | grep lvcreate | sed "s/^.*-n \([^ ][^ ]*\) .*$/$1/"`
527                for l in $EXCLUDE_LVS; do
528                    # FIXME: Should search for all possible device names here
529                    if [ -f "/tmp/mountlist.txt" ]; then
530                        grep -Ev "/dev/$v/$l" /tmp/mountlist.txt > /tmp/mountlist.txt.new
531                        grep -Ev "/dev/mapper/${v}-$l" /tmp/mountlist.txt.new > /tmp/mountlist.txt
532                    fi
533                done
534            done
535        done
536
537        grep -E "^#.*vgchange" /tmp/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
538        chmod +x /tmp/start-lvm
539        echo -en "Starting LVM's..."
540        /tmp/start-lvm &
541        for i in 1 2 3 4 5 ; do
542            echo -en "."
543            sleep 1
544        done
545        echo "Done."
546    fi
547# If necessary, cannibalize 'analyze-my-lvm'; copy some of its code here,
548# pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
549    LogIt "LVM's have been started."
550}
551
552StartPowerPath() {
553
554    # Taken from the init script of EMC PowerPath on RHEL
555    if [ -f /etc/emcp_devicesDB.dat ]; then 
556        if [ -f /etc/emcp_devicesDB.idx ]; then
557            /etc/opt/emcpower/emcpmgr map -p > /dev/null 2>&1
558        fi
559    fi
560
561    /sbin/powermt config > /dev/null 2>&1
562    #   Wait for udev to finish creating emcpower devices
563    #
564    pdfound=1
565    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
566        pdfound=1
567        for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
568            bpd=`basename $pd`
569            if [ ! -e /dev/$bpd ]; then
570                pdfound=0
571                sleep 2
572                break;
573            fi
574        done
575        if [ "$pdfound" -eq 1 ]; then
576            break
577        fi
578    done
579    if [ "$pdfound" -eq 0 ]; then
580        echo "Unable to start PowerPath"
581    fi
582
583    /sbin/powermt load      > /dev/null 2>&1
584    /etc/opt/emcpower/emcpmgr map   > /dev/null 2>&1
585    /etc/opt/emcpower/powercf -C    > /dev/null 2>&1
586    if [ ! -e /etc/powermt.custom ]; then 
587        /sbin/powermt save      > /dev/null 2>&1
588    fi 
589    /sbin/powermt register  > /dev/null 2>&1
590    /sbin/powermig transition -startup -noprompt    > /dev/null 2>&1
591}
592
593StartMpath() {
594    if [ "`grep -i nompath /proc/cmdline`" ]; then
595        return;
596    fi
597    if [ -f "/tmp/mountlist.txt" ] && [ "`grep mpath /tmp/mountlist.txt`" ]; then
598        if [ -x /sbin/multipath ]; then
599            echo "Starting Mpath..."
600            mkdir -p /var/lib/multipath
601            cat > /etc/multipath.conf << EOF
602defaults {
603        user_friendly_names yes
604}
605EOF
606            /sbin/multipath -v 0
607            if [ -x /sbin/kpartx ]; then
608                /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
609            fi
610            LogIt "Multipath started"
611        fi
612    fi
613}
614
615StartRaids() {
616    local raid_devices i
617
618    if [ "`grep -i noraid /proc/cmdline`" ]; then
619        return;
620    fi
621
622    if [ -f "/tmp/mountlist.txt" ]; then
623        raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
624    else
625        raid_devices=""
626    fi
627
628    if which raidstart > /dev/null 2> /dev/null ; then
629        for i in $raid_devices ; do
630            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
631                LogIt "$i is started already; no need to run 'raidstart $i'" 1
632            else
633                LogIt "Running 'raidstart $i'" 1
634                raidstart $i
635            fi
636        done
637    elif which mdrun > /dev/null 2> /dev/null ; then
638        if [ "`grep -i nomd /proc/cmdline`" ]; then
639            return;
640        fi
641        LogIt "Running 'mdrun'" 1
642        mdrun
643    elif which mdadm > /dev/null 2> /dev/null ; then
644        if [ "`grep -i nomd /proc/cmdline`" ]; then
645            return;
646        fi
647        LogIt "Running 'mdadm'" 1
648        for i in $raid_devices ; do
649            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
650                LogIt "$i is started already; no need to run 'mdadm $i'" 1
651            else
652                if [ -f /etc/mdadm.conf ] ; then
653                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm.conf" 1
654                    mdadm -A $i -c /etc/mdadm.conf
655                elif [ -f /etc/mdadm/mdadm.conf ] ; then
656                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm/mdadm.conf" 1
657                    mdadm -A $i -c /etc/mdadm/mdadm.conf
658                else
659                    LogIt "Running 'mdadm $i'" 1
660                    mdadm -Ac partitions -m dev $i
661                fi
662            fi
663        done
664    elif which dmraid > /dev/null 2> /dev/null ; then
665        if [ "`grep -i nodmraid /proc/cmdline`" ]; then
666            return;
667        fi
668        for x in $(/sbin/dmraid -ay -i -p -t 2>/dev/null | grep -E  -iv "^no " |awk -F ':' '{ print $1 }') ; do
669            echo "Please send the result of /sbin/dmraid -ay -i -p -t to the devteam !!!"
670            return
671            #dmname=$(resolve_dm_name $x)
672            #[ -z "$dmname" ] && continue
673            #/sbin/dmraid  -ay -i -p "$dmname" >/dev/null 2>&1
674            #/sbin/kpartx -a -p p "/dev/mapper/$dmname"
675        done
676    else
677        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
678    fi
679
680}
681
682
683TryAgainToFindCD() {
684    local res
685    mount | grep /mnt/cdrom && return 0
686    [ "`grep "backup_media_type" /tmp/mondorestore.cfg 2> /dev/null | grep "cdstream"`" ] && return
687    LogIt "Trying to mount CD-ROM a 2nd time..."
688    find-and-mount-cdrom --second-try
689    res=$?
690    if [ "$res" -eq "0" ] ; then
691        CD_MOUNTED_OK=yes
692        LogIt "CD-ROM drive mounted successfully." 1
693    else
694        LogIt "I still cannot find or mount the CD-ROM drive, by the way."
695    fi
696}
697
698
699
700UseTmpfs()
701{
702    local mount_cmd
703    echo -en "Mounting /tmp/tmpfs..."
704    mkdir -p /tmp/tmpfs
705# For technical reasons, some sets are as large as 16MB.
706# I am allowing 32MB because selective restore occupies a lot of space.
707    for size in 256m 128m 64m 48m 40m 32m ; do
708        mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
709        LogIt "Trying '$mount_cmd'"
710        $mount_cmd /tmp/tmpfs 2>> $LOGFILE
711        res=$?
712        [ "$res" -eq "0" ] && break
713    done
714    if [ "$res" -ne "0" ] ; then
715        LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
716        umount /tmp/tmpfs > /dev/null 2> /dev/null
717        rmdir /tmp/tmpfs
718        ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondorestore
719        LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
720    else
721        LogIt "Great. Pivot succeeded w/ size=$size" 1
722        echo -en "Pivoting /tmp..."
723        umount /tmp/tmpfs
724        mkdir -p /tmp.old
725        mv /tmp/* /tmp.old/
726        # Try to Deal with a busybox bug on inexistant links
727        cp /tmp/* /tmp.old/
728        rm -f /tmp/*
729        $mount_cmd /tmp
730        mv /tmp.old/* /tmp/
731        # Try to Deal with a busybox bug on inexistant links
732        cp /tmp.old/* /tmp/
733        rm -rf /tmp.old
734        mkdir -p /tmp/tmpfs
735        mkdir -p $GROOVY
736    echo "Done."
737    LogIt "Successfully mounted dynamic /tmp ramdisk"
738#   mkdir -p /tmp/tmpfs/var
739#        mv -f /var/log /tmp/tmpfs/var/log
740#        ln -sf /tmp/tmpfs/var/log /var/log
741    fi
742}
743
744
745WelcomeMessage()
746{
747    echo "********************************************************************"
748    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
749    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
750which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
751    echo "Executables and source code are covered by the GNU GPL. No warranty."
752    echo "running on $ARCH"
753    echo "********************************************************************"
754}
755
756EnableCcissIfAppropriate() {
757    local f
758
759    # In some cases, the OBDR tape remains in CD-ROM mode. This branch solves that issue (#498)
760    if [ "`grep -i 'obdr ' /tmp/mondorestore.cfg 2>/dev/null`" ] && [ -x /usr/bin/hpsa_obdr_mode ]; then
761        for lun in `/usr/bin/hpsa_obdr_mode -m query /dev/cciss/* 2>&1 | grep "is an OBDR device" | cut -d' ' -f4`; do
762            /usr/bin/hpsa_obdr_mode -m query -l $lun /dev/cciss/* 2>&1 | grep -q "is in CD-ROM mode"
763            if [ $? -eq 0 ]; then
764                # This tape/lun should be brought back in Sequential mode
765                LogIt "Putting back tape $lun in Sequential mode..."
766                /usr/bin/hpsa_obdr_mode -m tape -l $lun /dev/cciss/* 2>&1 > /dev/null
767            fi
768        done
769    fi
770
771    # Now engage all Smart Array controllers to detect attached devices
772    if [ -d  "/proc/driver/cciss" ]; then
773        for f in /proc/driver/cciss/cciss* ; do
774            LogIt "Engaging $f"
775            echo "engage scsi" > $f
776            LogIt "...result=$?"
777        done
778    fi
779}
780
781ModprobeAllModules() {
782
783    echo "Searching for modules to install..."
784    lismod=`find /lib/modules -name '*\.ko*' -o -name '*\.o*'`
785    # loading forced modules first
786    for m in $lismod; do
787        k=`basename $m | sed 's/\.ko.*$//'`
788        j=`basename $k | sed 's/\.o.*$//'`
789        echo "$FORCE_MODS" | grep -q "$j "
790        if [ $? -eq 0 ]; then
791            echo "Forcing first $j..."
792            modprobe -q $j 2> /dev/null
793        fi
794    done
795    for m in $lismod; do
796        k=`basename $m | sed 's/\.ko.*$//'`
797        j=`basename $k | sed 's/\.o.*$//'`
798        echo "$DENY_MODS" | grep -q "$j "
799        if [ $? -eq 0 ]; then
800            echo "Denying $j..."
801            continue
802        fi
803        echo "$FORCE_MODS" | grep -q "$j "
804        if [ $? -eq 0 ]; then
805            continue
806        fi
807        echo "Probing $j..."
808        modprobe -q $j 2> /dev/null
809    done
810}
811
812UdevadmTrigger() {
813
814# This function should just echo the return value $ua
815
816if [ -x /sbin/udevadm ]; then
817    ua="/sbin/udevadm"
818elif [ -x /usr/bin/udevadm ]; then
819    ua="/usr/bin/udevadm"
820else
821    LogIt "WARNING: Unable to find udevadm. Not triggering udev"
822    ua="/bin/true"
823fi
824
825v="`$ua --version`"
826
827if [ -x "$v" ]; then
828    LogIt "Triggering udev again..."
829    if [ "$v" -ge "146" -a "$v" -lt "174" ]; then
830        $ua trigger --type=failed
831    elif [ "$v" -lt "146" ]; then
832        $ua trigger --retry-failed
833    else
834        LogIt "... not needed"
835    fi
836fi
837echo $ua
838}
839
840ExtractDataDisksAndLoadModules() {
841    LogIt "Installing additional tools ..." 1
842    # BCO: test return value
843    install-additional-tools
844    # Keep the kernel silent again
845    PKLVL=`cut -f1 /proc/sys/kernel/printk`
846    echo 0 > /proc/sys/kernel/printk
847    ModprobeAllModules
848    echo $PKLVL > /proc/sys/kernel/printk
849
850    # Retry failed udev events now that local filesystems are mounted read-write
851    # (useful for rules creating network ifcfg files)
852    if [ -e "/tmp/USE-UDEV" ] ; then
853        ua=`UdevadmTrigger`
854    fi
855}
856
857# ------------------------ main -----------------------
858
859MINDI_VER=PBVER
860MINDI_REV=PBREV
861trap CaughtSoftReset SIGTERM
862trap GetShell SIGINT
863LOGFILE=/var/log/mondorestore.log
864PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
865GROOVY=/tmp/groovy-stuff
866USER=root
867ARCH=`uname -m`
868
869export PATH GROOVY USER LOGFILE ARCH
870
871mount -o remount rw /
872rm -f $LOGFILE
873
874mkdir /proc 2> /dev/null
875mount /proc /proc -t proc
876
877# Creates log file
878LogIt ""
879# Redirect every message to the LOGFILE
880exec > >(tee -a ${LOGFILE})
881exec 2> >(tee -a ${LOGFILE} >&2)
882
883echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
884
885mkdir /sys 2> /dev/null
886mount /sys /sys -t sysfs
887
888[ ! "$GROOVY" ] && Die "I'm not groovy!"
889for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
890    mkdir -p $i
891done
892# For ESX 3
893[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
894
895if [ "`grep -i denymods /proc/cmdline`" ]; then
896    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
897else
898    export DENY_MODS=" "
899fi
900if [ "`grep -i 'obdr ' /tmp/mondorestore.cfg 2> /dev/null`" ]; then
901    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
902    export DENY_MODS="usb-storage $DENY_MODS"
903fi
904if [ "`grep -i forcemods /proc/cmdline`" ]; then
905    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
906else
907    export FORCE_MODS=" "
908fi
909if [ "`grep -i excludedevs /proc/cmdline`" ]; then
910    export MINDI_EXCLUDE_DEVS="`cat /proc/cmdline | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
911    for d in $MINDI_EXCLUDE_DEVS ; do
912        echo "Mountlist exclusion == $d"
913        if [ -e "/tmp/mountlist.txt" ]; then
914            perl -i -ne 'print $_ unless m~$d~' /tmp/mountlist.txt
915        fi
916    done
917else
918    export MINDI_EXCLUDE_DEVS=" "
919fi
920
921echo "Activating a potential USB keyboard/mouse"
922StartUSBKbd
923
924if [ -f /proc/sys/kernel/exec-shield ]; then
925    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
926fi
927
928if [ -f /proc/modules ]; then
929    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
930fi
931
932if [ -e "/tmp/USE-UDEV" ] ; then
933    RunUdevd
934fi
935ExtractDevTarballs
936LaunchTerminals
937
938# Keeping kernel silent for module insertion
939PKLVL=`cut -f1 /proc/sys/kernel/printk`
940echo 0 > /proc/sys/kernel/printk
941ModprobeAllModules
942echo $PKLVL > /proc/sys/kernel/printk
943
944EnableCcissIfAppropriate
945#-------------------------------
946#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
947#-------------------------------
948UseTmpfs
949if [ ! -e "/tmp/mondorestore.cfg" ] ; then
950    LogIt "Warning - /tmp/mondorestore.cfg not found"
951fi
952if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
953    # We need to get here exported variables from start-netfs
954    . /sbin/start-netfs
955fi
956
957if [ "`grep -i 'obdr ' /tmp/mondorestore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondorestore.cfg 2>/dev/null`" ]; then
958    HandleTape
959    ExtractDataDisksAndLoadModules
960elif [ "`grep -i pxe /proc/cmdline`" ]; then
961    # Simulate a local CD
962    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
963    CD_MOUNTED_OK=yes
964    ExtractDataDisksAndLoadModules
965    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
966    sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondorestore.cfg
967elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondorestore.cfg 2>/dev/null | grep media-type`" ]; then
968    . /sbin/start-usb
969
970    # Simulate a local CD
971    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
972    CD_MOUNTED_OK=yes
973    ExtractDataDisksAndLoadModules
974else
975    HandleCDROM
976    ExtractDataDisksAndLoadModules
977    # We need to get here exported variables from start-netfs
978    . /sbin/start-netfs
979fi
980res=$?
981ConfigureLoggingDaemons
982if [ -e "/tmp/USE-DEVFS" ] ; then
983    umount -d /mnt/cdrom 2> /dev/null
984    mv /dev/cdrom /cdrom.lnk 2> /dev/null
985    CD_MOUNTED_OK=""
986    RunDevfsd
987fi
988LoadKeymap
989WelcomeMessage
990RstHW
991echo "Starting potential Raid/Multipath ..."
992[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
993PauseForRaids
994StartRaids
995StartMpath
996StartLvms
997CopyBootDevEntry
998mkdir -p /tmp/tmpfs
999sleep 2
1000#clear
1001if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ -e "/tmp/mountlist.txt" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
1002    LogIt "Creating /dev/md/* softlinks just in case." 1
1003    mkdir -p /dev/md
1004    cp -af /dev/md0 /dev/md/0 2> /dev/null
1005    cp -af /dev/md1 /dev/md/1 2> /dev/null
1006    cp -af /dev/md2 /dev/md/2 2> /dev/null
1007fi
1008
1009if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
1010    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
1011    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
1012    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
1013    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
1014    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
1015fi
1016hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
1017
1018# Log some useful info
1019LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
1020LogIt "/proc/cmdline is:"
1021LogIt "----------"
1022cat /proc/cmdline  >> $LOGFILE
1023LogIt "----------"
1024LogIt "df result:"
1025LogIt "----------"
1026df >> $LOGFILE
1027LogIt "-------------"
1028LogIt "mount result:"
1029LogIt "-------------"
1030mount >> $LOGFILE
1031LogIt "-------------"
1032LogIt "lsmod result:"
1033LogIt "-------------"
1034lsmod >> $LOGFILE
1035LogIt "-------------"
1036LogIt "dmesg result:"
1037LogIt "-------------"
1038dmesg >> $LOGFILE
1039LogIt "-------------"
1040LogIt "/proc/mdstat:" >> $LOGFILE
1041LogIt "-------------"
1042cat /proc/mdstat  >> $LOGFILE
1043LogIt "-------------"
1044LogIt "/proc/swaps:" >> $LOGFILE
1045LogIt "-------------"
1046cat /proc/swaps  >> $LOGFILE
1047LogIt "-------------"
1048LogIt "/proc/filesystems:" >> $LOGFILE
1049LogIt "-------------"
1050cat /proc/filesystems  >> $LOGFILE
1051LogIt "-------------"
1052LogIt "/proc/partitions:" >> $LOGFILE
1053LogIt "-------------"
1054cat /proc/partitions  >> $LOGFILE
1055LogIt "-------------"
1056LogIt "fdisk result:" >> $LOGFILE
1057LogIt "-------------"
1058fdisk -l  >> $LOGFILE
1059LogIt "-------------"
1060if [ -f /tmp/mondorestore.cfg ]; then
1061    LogIt "/tmp/mondorestore.cfg result:" >> $LOGFILE
1062    LogIt "-------------"
1063    cat /tmp/mondorestore.cfg  >> $LOGFILE
1064fi
1065
1066ide-opt
1067
1068#ctrlaltdel soft
1069for i in null stdout stdin stderr ; do
1070    cp -af /dev/$i /tmp
1071done
1072# Not sure it's still needed, but shouldn't hurt
1073if [ -e "/tmp/USE-UDEV" ] ; then
1074    ua=`UdevadmTrigger`
1075fi
1076if grep "backup-media-type" /tmp/mondorestore.cfg > /dev/null 2> /dev/null ; then
1077    LogIt "backup-media-type is specified in config file - great."
1078    LogIt "Calling post-init"
1079    # start-netfs moved it under /tmp as the NFS share is already unmounted
1080    if [ _"$pre" != _"" ] && [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
1081        pre=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
1082    fi
1083    if [ _"$pre" != _"" ] && [ -x $pre ]; then
1084        echo "Executing preliminary script $pre"
1085        LogIt "Executing preliminary script $pre"
1086        $pre
1087    fi
1088    post-init
1089else
1090    LogIt "backup-media-type is not specified in config file."
1091    LogIt "I think this media has no archives on it."
1092fi
1093if [ "`grep -i "post=" /proc/cmdline`" ] ; then
1094    for i in `cat /proc/cmdline` ; do
1095        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
1096    done
1097    # start-netfs moved it under /tmp as the NFS share is already unmounted
1098    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
1099        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
1100    fi
1101    if [ -r $post ]; then
1102        echo "Executing final script $post"
1103        LogIt "Executing final script $post"
1104        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
1105            mount-me
1106        fi
1107        chmod 755 $post
1108        $post
1109        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
1110            unmount-me
1111        fi
1112    fi
1113fi
1114if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
1115    echo "Rebooting in 10 seconds automatically as per reboot order"
1116    echo -en "Press ^C to interrupt if you have to ..."
1117    for i in 1 2 3 4 5 6 7 8 9 10 ; do
1118        sleep 1
1119        echo -en "."
1120    done
1121    echo "Boom."
1122    sleep 1
1123else
1124    GetShell
1125fi
1126CaughtSoftReset
Note: See TracBrowser for help on using the repository browser.