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

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

r3737@localhost: bruno | 2010-03-14 20:57:44 +0100

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