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

Last change on this file since 2445 was 2445, checked in by Bruno Cornec, 11 years ago

r3513@localhost: bruno | 2009-10-02 00:09:16 +0200

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