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

Last change on this file since 2844 was 2844, checked in by Bruno Cornec, 9 years ago

r4185@vgiles: bruno | 2011-06-28 18:04:46 +0200

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