source: branches/2.2.9/mindi/rootfs/sbin/init @ 2768

Last change on this file since 2768 was 2768, checked in by Bruno Cornec, 9 years ago

Log content of mondo-restore.cfg

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