source: MondoRescue/branches/2.2.10/mindi/rootfs/sbin/init @ 2349

Last change on this file since 2349 was 2349, checked in by Bruno Cornec, 11 years ago
  • Solve tmp dir creation which sometimes was trying to create /%xx dirs. Should fix #293 for good
  • Adds fdisk -l result in Log File at restore time

(Backports from 2.2.9)

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