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

Last change on this file since 2354 was 2354, checked in by Bruno Cornec, 11 years ago
  • Addition of a nomd option to avoid starting mdadm
  • mpath is now already started if there was a mpath entry in mountlist

(Backport from 2.2.9)

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