source: branches/2.2.10/mindi/rootfs/sbin/init @ 2607

Last change on this file since 2607 was 2607, checked in by bruno, 9 years ago

r3763@localhost: bruno | 2010-03-18 12:03:49 +0100

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