source: branches/2.2.9/mindi/rootfs/sbin/init @ 2580

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