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

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

r3757@localhost: bruno | 2010-03-17 15:05:13 +0100

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