source: MondoRescue/branches/2.2.9/mindi/rootfs/sbin/init @ 2255

Last change on this file since 2255 was 2255, checked in by Bruno Cornec, 11 years ago
  • Fix #336 by extending the previous feature to a double call (pre and post) on the boot loader line to be able to call cripts either before mondorestore and/or after its execution
  • Property svn:keywords set to Id
File size: 23.3 KB
Line 
1#!/bin/sh
2#
3# $Id: init 2255 2009-07-05 00:58:53Z 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    echo "Starting Mpath..."
448    if [ -x /sbin/multipath ]; then
449        mkdir -p /var/lib/multipath
450        cat > /etc/multipath.conf << EOF
451defaults {
452        user_friendly_names yes
453}
454EOF
455        /sbin/multipath -v 0
456        if [ -x /sbin/kpartx ]; then
457            /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
458        fi
459    fi
460}
461
462StartRaids() {
463    local raid_devices i
464
465    raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
466    if which raidstart > /dev/null 2> /dev/null ; then
467        for i in $raid_devices ; do
468            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
469                LogIt "$i is started already; no need to run 'raidstart $i'" 1
470            else
471                LogIt "Running 'raidstart $i'" 1
472                raidstart $i
473            fi
474        done
475    elif which mdrun > /dev/null 2> /dev/null ; then
476        LogIt "Running 'mdrun'" 1
477        mdrun
478    elif which mdadm > /dev/null 2> /dev/null ; then
479        LogIt "Running 'mdadm'" 1
480        for i in $raid_devices ; do
481            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
482                LogIt "$i is started already; no need to run 'mdadm $i'" 1
483            else
484                if [ -f /etc/mdadm.conf ] ; then
485                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm.conf" 1
486                    mdadm -A $i -c /etc/mdadm.conf
487                elif [ -f /etc/mdadm/mdadm.conf ] ; then
488                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm/mdadm.conf" 1
489                    mdadm -A $i -c /etc/mdadm/mdadm.conf
490                else
491                    LogIt "Running 'mdadm $i'" 1
492                    mdadm -Ac partitions -m dev $i
493                fi
494            fi
495        done
496    elif which dmraid > /dev/null 2> /dev/null ; then
497        if [ "`grep -i nodmraid /proc/cmdline`" ]; then
498            return;
499        fi
500        for x in $(/sbin/dmraid -ay -i -p -t 2>/dev/null | grep -E  -iv "^no " |awk -F ':' '{ print $1 }') ; do
501            echo "Please send the result of /sbin/dmraid -ay -i -p -t to the devteam !!!"
502            return
503            #dmname=$(resolve_dm_name $x)
504            #[ -z "$dmname" ] && continue
505            #/sbin/dmraid  -ay -i -p "$dmname" >/dev/null 2>&1
506            #/sbin/kpartx -a -p p "/dev/mapper/$dmname"
507        done
508    else
509        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
510    fi
511
512}
513
514
515TryAgainToFindCD() {
516    local res
517    mount | grep /mnt/cdrom && return 0
518    [ "`grep "backup_media_type" /tmp/mondo-restore.cfg 2> /dev/null | grep "cdstream"`" ] && return
519    LogIt "Trying to mount CD-ROM a 2nd time..."
520    find-and-mount-cdrom --second-try
521    res=$?
522    if [ "$res" -eq "0" ] ; then
523        CD_MOUNTED_OK=yes
524        LogIt "CD-ROM drive mounted successfully." 1
525    else
526        LogIt "I still cannot find or mount the CD-ROM drive, by the way."
527    fi
528}
529
530
531
532UseTmpfs()
533{
534    local mount_cmd
535    echo -en "Mounting /tmp/tmpfs..."
536    mkdir -p /tmp/tmpfs
537# For technical reasons, some sets are as large as 16MB.
538# I am allowing 32MB because selective restore occupies a lot of space.
539    for size in 128m 64m 48m 40m 32m ; do
540        mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
541        LogIt "Trying '$mount_cmd'"
542        $mount_cmd /tmp/tmpfs 2>> $LOGFILE
543        res=$?
544        [ "$res" -eq "0" ] && break
545    done
546    if [ "$res" -ne "0" ] ; then
547        LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
548        umount /tmp/tmpfs > /dev/null 2> /dev/null
549        rmdir /tmp/tmpfs
550        ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondo-restore
551        LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
552    else
553        LogIt "Great. Pivot succeeded w/ size=$size" 1
554        echo -en "Pivoting /tmp..."
555        umount /tmp/tmpfs
556        mkdir -p /tmp.old
557        mv /tmp/* /tmp.old/
558        # Try to Deal with a busybox bug on inexistant links
559        cp /tmp/* /tmp.old/
560        rm -f /tmp/*
561        $mount_cmd /tmp
562        mv /tmp.old/* /tmp/
563        # Try to Deal with a busybox bug on inexistant links
564        cp /tmp.old/* /tmp/
565        rm -rf /tmp.old
566        mkdir -p /tmp/tmpfs
567        mkdir -p $GROOVY
568    echo "Done."
569    LogIt "Successfully mounted dynamic /tmp ramdisk"
570#   mkdir -p /tmp/tmpfs/var
571#        mv -f /var/log /tmp/tmpfs/var/log
572#        ln -sf /tmp/tmpfs/var/log /var/log
573    fi
574}
575
576
577WelcomeMessage()
578{
579    echo "********************************************************************"
580    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
581    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
582which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
583    echo "Executables and source code are covered by the GNU GPL. No warranty."
584    echo "running on $ARCH"
585    echo "********************************************************************"
586}
587
588
589EnableCcissIfAppropriate() {
590    local i fname
591    for i in 0 1 2 3 ; do
592        fname="/proc/driver/cciss/cciss$i"
593        if [ -e "$fname" ] ; then
594            LogIt "Engaging $fname"
595            echo "engage scsi" > $fname
596            LogIt "...result=$?"
597        fi
598    done
599}
600
601ModprobeAllModules() {
602
603    for m in `find /lib/modules -name '*\.ko*' -o -name '*\.o*'`; do
604        k=`basename $m | sed 's/\.ko.*$//'`
605        j=`basename $k | sed 's/\.o.*$//'`
606        echo "$DENY_MODS" | grep -q "$j "
607        if [ $? -eq 0 ]; then
608            echo "Denying $j..."
609            continue
610        fi
611        echo "Probing $j..."
612        modprobe -q $j
613    done
614}
615
616ExtractDataDisksAndLoadModules() {
617    echo "Installing additional tools ..."
618    install-additional-tools
619    # Keep the kernel silent again
620    PKLVL=`cut -f1 /proc/sys/kernel/printk`
621    echo 0 > /proc/sys/kernel/printk
622    ModprobeAllModules
623    echo $PKLVL > /proc/sys/kernel/printk
624
625    # Retry failed udev events now that local filesystems are mounted read-write
626    # (useful for rules creating network ifcfg files)
627    if [ -e "/tmp/USE-UDEV" ] ; then
628        if [ -x /sbin/udevadm ]; then
629            /sbin/udevadm trigger --retry-failed
630        fi
631    fi
632}
633
634# ------------------------ main -----------------------
635
636MINDI_VER=PBVER
637MINDI_REV=PBREV
638trap CaughtSoftReset SIGTERM
639LOGFILE=/var/log/mondorestore.log
640PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
641GROOVY=/tmp/groovy-stuff
642USER=root
643ARCH=`uname -m`
644
645export PATH GROOVY USER LOGFILE ARCH
646
647echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
648
649mount -o remount rw /
650[ ! "$GROOVY" ] && Die "I'm not groovy!"
651for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
652    mkdir -p $i
653done
654#/bin/update
655mount /proc/ /proc -v -t proc
656mkdir /sys 2> /dev/null
657mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
658# For ESX 3
659[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
660rm -f /foozero
661
662if [ "`grep -i denymods /proc/cmdline`" ]; then
663    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
664else
665    export DENY_MODS=" "
666fi
667if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
668    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
669    export DENY_MODS="usb-storage $DENY_MODS"
670fi
671if [ "`grep -i forcemods /proc/cmdline`" ]; then
672    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
673else
674    export FORCE_MODS=" "
675fi
676
677echo "Activating a potential USB keyboard/mouse"
678StartUSBKbd
679
680if [ -f /proc/sys/kernel/exec-shield ]; then
681    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
682fi
683
684if [ -f /proc/modules ]; then
685    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
686fi
687
688if [ -e "/tmp/USE-UDEV" ] ; then
689    RunUdevd
690fi
691ExtractDevTarballs
692LaunchTerminals
693
694# Keeping kernel silent  for module insertion
695PKLVL=`cut -f1 /proc/sys/kernel/printk`
696echo 0 > /proc/sys/kernel/printk
697ModprobeAllModules
698echo $PKLVL > /proc/sys/kernel/printk
699
700EnableCcissIfAppropriate
701#-------------------------------
702#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
703#-------------------------------
704UseTmpfs
705if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
706    LogIt "Warning - /tmp/mondo-restore.cfg not found"
707fi
708if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
709    # We need to get here exported variables from start-nfs
710    . /sbin/start-nfs
711fi
712
713if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
714    HandleTape
715    ExtractDataDisksAndLoadModules
716elif [ "`grep -i pxe /proc/cmdline`" ]; then
717    # Simulate a local CD
718    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
719    CD_MOUNTED_OK=yes
720    ExtractDataDisksAndLoadModules
721    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
722    sed -i "s/backup-media-type.*/backup-media-type nfs/" /tmp/mondo-restore.cfg
723elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
724    . /sbin/start-usb
725
726    # Simulate a local CD
727    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
728    CD_MOUNTED_OK=yes
729    ExtractDataDisksAndLoadModules
730else
731    HandleCDROM
732    ExtractDataDisksAndLoadModules
733    # We need to get here exported variables from start-nfs
734    . /sbin/start-nfs
735fi
736res=$?
737ConfigureLoggingDaemons
738if [ -e "/tmp/USE-DEVFS" ] ; then
739    umount /mnt/cdrom 2> /dev/null
740    mv /dev/cdrom /cdrom.lnk 2> /dev/null
741    CD_MOUNTED_OK=""
742    RunDevfsd
743fi
744LoadKeymap
745WelcomeMessage
746RstHW
747echo "Starting potential Raid/LVMs ..."
748PauseForRaids
749StartRaids
750StartMpath
751StartLvms
752CopyBootDevEntry
753mkdir -p /tmp/tmpfs
754sleep 2
755#clear
756if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
757    LogIt "Creating /dev/md/* softlinks just in case." 1
758    mkdir -p /dev/md
759    cp -af /dev/md0 /dev/md/0 2> /dev/null
760    cp -af /dev/md1 /dev/md/1 2> /dev/null
761    cp -af /dev/md2 /dev/md/2 2> /dev/null
762fi
763[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
764
765if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
766    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
767    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
768    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
769    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
770    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
771fi
772hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
773
774# Log some useful info
775LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
776LogIt "/proc/cmdline is:"
777cat /proc/cmdline  >> $LOGFILE
778LogIt "df result:"
779LogIt "----------"
780df >> $LOGFILE
781LogIt "-------------"
782LogIt "mount result:"
783LogIt "-------------"
784mount >> $LOGFILE
785LogIt "-------------"
786LogIt "lsmod result:"
787LogIt "-------------"
788lsmod >> $LOGFILE
789LogIt "-------------"
790LogIt "dmesg result:"
791LogIt "-------------"
792dmesg >> $LOGFILE
793LogIt "-------------"
794LogIt "/proc/swaps:" >> $LOGFILE
795LogIt "-------------"
796cat /proc/swaps  >> $LOGFILE
797LogIt "-------------"
798LogIt "/proc/filesystems:" >> $LOGFILE
799LogIt "-------------"
800cat /proc/filesystems  >> $LOGFILE
801LogIt "-------------"
802LogIt "/proc/partitions:" >> $LOGFILE
803LogIt "-------------"
804cat /proc/partitions  >> $LOGFILE
805
806
807ide-opt
808
809#ctrlaltdel soft
810for path in /usr.bin /usr/bin ; do
811    fname=$path/nano
812    [ -e "$fname" ] && ln -sf $fname /usr/bin/pico
813done
814res=`which nano 2> /dev/null`
815[ "$res" ] && ln -sf /usr/bin/
816for i in null stdout stdin stderr ; do
817    cp -af /dev/$i /tmp
818done
819# Not sure it's still needed, but shouldn't hurt
820if [ -e "/tmp/USE-UDEV" ] ; then
821    if [ -x /sbin/udevadm ]; then
822        /sbin/udevadm trigger --retry-failed
823    fi
824fi
825if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
826    LogIt "backup-media-type is specified in config file - great."
827    LogIt "Calling post-init"
828    # start-nfs moved it under /tmp as the NFS share is already unmounted
829    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
830        post=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
831    fi
832    if [ -x $pre ]; then
833        echo "Executing preliminary script $pre"
834        LogIt "Executing preliminary script $pre"
835        $pre
836    fi
837    post-init
838else
839    LogIt "backup-media-type is not specified in config file."
840    LogIt "I think this media has no archives on it."
841fi
842if [ "`grep -i "post=" /proc/cmdline`" ] ; then
843    for i in `cat /proc/cmdline` ; do
844        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
845    done
846    # start-nfs moved it under /tmp as the NFS share is already unmounted
847    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
848        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
849    fi
850    if [ -x $post ]; then
851        echo "Executing final script $post"
852        LogIt "Executing final script $post"
853        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
854            mount-me
855        fi
856        $post
857        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
858            unmount-me
859        fi
860    fi
861fi
862if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
863    echo "Rebooting in 10 seconds automatically as per reboot order"
864    echo -en "Press ^C to interrupt if you have to ..."
865    for i in 1 2 3 4 5 6 7 8 9 10 ; do
866        sleep 1
867        echo -en "."
868    done
869    echo "Boom."
870    sleep 1
871else
872    echo -en "Type 'exit' to reboot the PC\n"
873    umount /mnt/cdrom 2> /dev/null
874    mount / -o rw,remount > /dev/null 2> /dev/null
875    LogIt "Launching Shell"
876    sh
877fi
878CaughtSoftReset
879# reboot
Note: See TracBrowser for help on using the repository browser.