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

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