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

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