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

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