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

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

r3724@localhost: bruno | 2010-03-10 00:46:58 +0100

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