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

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

r4154@vgiles: bruno | 2011-06-11 22:02:34 +0200

  • Avoids error msgs if no mondo-restore.cfg file exists (when mindi used stdalone)
  • Property svn:keywords set to Id
File size: 25.9 KB
Line 
1#!/bin/sh
2#
3# $Id: init 2832 2011-06-16 19:27:38Z 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 -c 2 /bin/sh
78    openvt -c 3 /bin/sh
79    openvt -c 4 /bin/sh
80    openvt -c 5 /bin/sh
81    openvt -c 6 /bin/sh
82    openvt -c 7 /bin/sh /sbin/wait-for-petris
83    openvt -c 8 /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 US 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 -v grep |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 "$MINDI_CACHE/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" $MINDI_CACHE/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" $MINDI_CACHE/i-want-my-lvm > $MINDI_CACHE/i-want-my-lvm.new
396            mv $MINDI_CACHE/i-want-my-lvm.new $MINDI_CACHE/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" $MINDI_CACHE/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" $MINDI_CACHE/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
668UdevadmTrigger() {
669if [ -x /sbin/udevadm ]; then
670    if [ `/sbin/udevadm --version` -ge 146 ]; then
671        # After version 146 option --retry-failed doesn't exist anymore
672        /sbin/udevadm triger --type=failed
673    else
674        /sbin/udevadm trigger --retry-failed
675    fi
676fi
677}
678
679ExtractDataDisksAndLoadModules() {
680    echo "Installing additional tools ..."
681    install-additional-tools
682    # Keep the kernel silent again
683    PKLVL=`cut -f1 /proc/sys/kernel/printk`
684    echo 0 > /proc/sys/kernel/printk
685    ModprobeAllModules
686    echo $PKLVL > /proc/sys/kernel/printk
687
688    # Retry failed udev events now that local filesystems are mounted read-write
689    # (useful for rules creating network ifcfg files)
690    if [ "$USE_UDEV" = "yes" ]; then
691        UdevadmTrigger
692    fi
693}
694
695# ------------------------ main -----------------------
696
697MINDI_VER=PBVER
698MINDI_REV=PBREV
699trap CaughtSoftReset SIGTERM
700LOGFILE=/var/log/mondorestore.log
701PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
702GROOVY=$MINDI_CACHE/groovy-stuff
703USER=root
704ARCH=`uname -m`
705
706export PATH GROOVY USER LOGFILE ARCH
707
708echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
709
710mount -o remount rw /
711[ ! "$GROOVY" ] && Die "I'm not groovy!"
712for i in /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
713    mkdir -p $i
714done
715#/bin/update
716mount /proc/ /proc -v -t proc
717
718# Now we can look at command line
719if [ -e "/proc/cmdline" ]; then
720    # Linux
721    export CMDLINE="/proc/cmdline"
722elif [ -e "/tmp/cmdline" ]; then
723    # BSD ?
724    export CMDLINE="/tmp/cmdline"
725else
726    export CMDLINE="/dev/null"
727fi
728
729mkdir /sys 2> /dev/null
730mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
731# For ESX 3
732[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
733rm -f /foozero
734
735if [ "`grep -i denymods $CMDLINE`" ]; then
736    export DENY_MODS="`cat $CMDLINE | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
737else
738    export DENY_MODS=" "
739fi
740if [ -f $MINDI_CACHE/mondorestore.cfg ] && [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2> /dev/null`" ]; then
741    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
742    export DENY_MODS="usb-storage $DENY_MODS"
743fi
744if [ "`grep -i forcemods $CMDLINE`" ]; then
745    export FORCE_MODS="`cat $CMDLINE | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
746else
747    export FORCE_MODS=" "
748fi
749if [ "`grep -i excludedevs $CMDLINE`" ]; then
750    export MINDI_EXCLUDE_DEVS="`cat $CMDLINE | sed 's~.*excludedevs=\"\(.*\)\".*~\1~'` mondonone"
751    for d in $MINDI_EXCLUDE_DEVS ; do
752        echo "Mountlist exclusion == $d"
753        perl -i -ne 'print $_ unless m~$d~' $MINDI_CACHE/mountlist.txt
754    done
755else
756    export MINDI_EXCLUDE_DEVS=" "
757fi
758
759echo "Activating a potential USB keyboard/mouse"
760StartUSBKbd
761
762if [ -f /proc/sys/kernel/exec-shield ]; then
763    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
764fi
765
766if [ -f /proc/modules ]; then
767    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
768fi
769
770USE_UDEV=""
771if [ -f $MINDI_CACHE/mondorestore.cfg ]; then
772    USE_UDEV=`grep "use_udev" $MINDI_CACHE/mondorestore.cfg | cut -d' ' -f2`
773fi
774if [ "$USE_UDEV" = "yes" ]; then
775    RunUdevd
776fi
777ExtractDevTarballs
778LaunchTerminals
779
780# Keeping kernel silent  for module insertion
781PKLVL=`cut -f1 /proc/sys/kernel/printk`
782echo 0 > /proc/sys/kernel/printk
783ModprobeAllModules
784echo $PKLVL > /proc/sys/kernel/printk
785
786EnableCcissIfAppropriate
787#-------------------------------
788#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
789#-------------------------------
790UseTmpfs
791if [ ! -e "$MINDI_CACHE/mondorestore.cfg" ] ; then
792    LogIt "Warning - $MINDI_CACHE/mondorestore.cfg not found"
793fi
794if [ "`grep -i pxe $CMDLINE`" ] || [ "`grep -i net $CMDLINE`" ]; then
795    # We need to get here exported variables from start-netfs
796    . /sbin/start-netfs
797fi
798
799if [ -f $MINDI_CACHE/mondorestore.cfg ] && [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2>/dev/null`" ]; then
800    HandleTape
801    ExtractDataDisksAndLoadModules
802elif [ "`grep -i pxe $CMDLINE`" ]; then
803    # Simulate a local CD
804    echo "/mnt/cdrom" > $MINDI_CACHE/CDROM-LIVES-HERE
805    CD_MOUNTED_OK=yes
806    ExtractDataDisksAndLoadModules
807    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
808    [ -f $MINDI_CACHE/mondorestore.cfg ] && sed -i "s/backup-media-type.*/backup-media-type netfs/" $MINDI_CACHE/mondorestore.cfg
809elif [ "`grep -i usb= $CMDLINE`" ] || [ "`grep -i usb $MINDI_CACHE/mondorestore.cfg 2>/dev/null | grep media-type`" ]; then
810    . /sbin/start-usb
811
812    # Simulate a local CD
813    echo "/mnt/cdrom" > $MINDI_CACHE/CDROM-LIVES-HERE
814    CD_MOUNTED_OK=yes
815    ExtractDataDisksAndLoadModules
816else
817    if [ -f "$MINDI_CACHE/mondorestore.cfg" ] ; then
818        HandleCDROM
819    fi
820    ExtractDataDisksAndLoadModules
821    # We need to get here exported variables from start-netfs
822    . /sbin/start-netfs
823fi
824res=$?
825ConfigureLoggingDaemons
826LoadKeymap
827WelcomeMessage
828RstHW
829[ -e "$MINDI_CACHE/mountlist.txt" ] && cp -f $MINDI_CACHE/mountlist.txt $MINDI_CACHE/mountlist.original
830StartRaids
831StartMpath
832StartLvms
833CopyBootDevEntry
834mkdir -p /tmp/tmpfs
835sleep 2
836if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ $MINDI_CACHE/mountlist.txt`" != "" ] ; then
837    LogIt "Creating /dev/md/* softlinks just in case." 1
838    mkdir -p /dev/md
839    cp -af /dev/md0 /dev/md/0 2> /dev/null
840    cp -af /dev/md1 /dev/md/1 2> /dev/null
841    cp -af /dev/md2 /dev/md/2 2> /dev/null
842fi
843
844if ! [ "`grep -i "pxe" $CMDLINE`" ] ; then
845    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
846    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
847    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
848    [ "$CD_MOUNTED_OK" != "yes" ] && [ -f $MINDI_CACHE/mondorestore.cfg ] && TryAgainToFindCD
849fi
850hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
851
852# Log some useful info
853LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
854LogIt "$CMDLINE is:"
855LogIt "----------"
856cat $CMDLINE  >> $LOGFILE
857LogIt "----------"
858LogIt "df result:"
859LogIt "----------"
860df >> $LOGFILE
861LogIt "-------------"
862LogIt "mount result:"
863LogIt "-------------"
864mount >> $LOGFILE
865LogIt "-------------"
866LogIt "lsmod result:"
867LogIt "-------------"
868lsmod >> $LOGFILE
869LogIt "-------------"
870LogIt "dmesg result:"
871LogIt "-------------"
872dmesg >> $LOGFILE
873LogIt "-------------"
874LogIt "/proc/swaps:" >> $LOGFILE
875LogIt "-------------"
876cat /proc/swaps  >> $LOGFILE
877LogIt "-------------"
878LogIt "/proc/filesystems:" >> $LOGFILE
879LogIt "-------------"
880cat /proc/filesystems  >> $LOGFILE
881LogIt "-------------"
882LogIt "/proc/partitions:" >> $LOGFILE
883LogIt "-------------"
884cat /proc/partitions  >> $LOGFILE
885LogIt "-------------"
886LogIt "fdisk result:" >> $LOGFILE
887LogIt "-------------"
888fdisk -l  >> $LOGFILE
889LogIt "-------------"
890if [ -f /tmp/mondo-restore.cfg ]; then
891    LogIt "/tmp/mondo-restore.cfg result:" >> $LOGFILE
892    LogIt "-------------"
893    cat /tmp/mondo-restore.cfg  >> $LOGFILE
894fi
895
896ide-opt
897
898# Not sure it's still needed, but shouldn't hurt
899if [ "$USE_UDEV" = "yes" ]; then
900    if [ -x /sbin/udevadm ]; then
901        UdevadmTrigger
902    fi
903
904fi
905if [ -f $MINDI_CACHE/mondorestore.cfg ]; then 
906    grep -q "backup-media-type" $MINDI_CACHE/mondorestore.cfg
907    if [ $? -eq 0 ]; then
908        LogIt "backup-media-type is specified in config file - great."
909        LogIt "Calling post-init"
910        # start-netfs moved it under /tmp as the NFS share is already unmounted
911        if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
912            pre=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
913        fi
914        if [ -x $pre ]; then
915            echo "Executing preliminary script $pre"
916            LogIt "Executing preliminary script $pre"
917            $pre
918        fi
919        post-init
920    else
921        LogIt "backup-media-type is not specified in config file."
922        LogIt "I think this media has no archives on it."
923    fi
924else
925    LogIt "$MINDI_CACHE/mondorestore.cfg not found."
926    LogIt "I think this media has no archives on it."
927fi
928if [ "`grep -i "post=" $CMDLINE`" ] ; then
929    for i in `cat $CMDLINE` ; do
930        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
931    done
932    # start-netfs moved it under /tmp as the NFS share is already unmounted
933    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
934        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
935    fi
936    if [ -r $post ]; then
937        echo "Executing final script $post"
938        LogIt "Executing final script $post"
939        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
940            mount-me
941        fi
942        chmod 755 $post
943        $post
944        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
945            unmount-me
946        fi
947    fi
948fi
949if grep "RESTORE" $CMDLINE > /dev/null 2> /dev/null ; then
950    echo "Rebooting in 10 seconds automatically as per reboot order"
951    echo -en "Press ^C to interrupt if you have to ..."
952    for i in 1 2 3 4 5 6 7 8 9 10 ; do
953        sleep 1
954        echo -en "."
955    done
956    echo "Boom."
957    sleep 1
958else
959    echo -en "Type 'exit' to reboot the PC\n"
960    umount /mnt/cdrom 2> /dev/null
961    mount / -o rw,remount > /dev/null 2> /dev/null
962    LogIt "Launching Shell"
963    sh
964fi
965CaughtSoftReset
966# reboot
Note: See TracBrowser for help on using the repository browser.