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

Last change on this file since 2477 was 2477, checked in by Bruno Cornec, 11 years ago
  • Adds a nolvm boot option at restore time
  • Property svn:keywords set to Id
File size: 24.0 KB
Line 
1#!/bin/sh
2#
3# $Id: init 2477 2009-11-11 12:29:27Z 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    ps | grep udevd 2> /dev/null 1> /dev/null
300    if [ $? -ne 0 ]; then
301        /sbin/udevd --daemon &
302        echo "Waiting for udev to start..."
303        sleep 5
304    fi
305    mkdir -p /dev/.udev/queue/
306    if [ -x /sbin/udevtrigger ]; then
307        /sbin/udevtrigger
308    fi
309    echo "Waiting for udev to discover..."
310    create_dev_makedev
311    # Newer version use udevadm for that
312    if [ -x /sbin/udevsettle ]; then
313        /sbin/udevsettle --timeout=10
314    elif [ -x /sbin/udevadm ]; then
315        /sbin/udevadm trigger
316        /sbin/udevadm settle --timeout=10
317    fi
318    # It seems we need to have more static devs on some distro were
319    # udev as some other requirements to be covered later on.
320    # So in the mean time:
321    for d in `ls /dev.static`; do
322        if [ ! -e /dev/$d ]; then
323            mv /dev.static/$d /dev
324        fi
325    done
326    echo $PKLVL > /proc/sys/kernel/printk
327}
328
329RstHW() {
330
331    # Restore the HW configuration if available (NOT by default)
332    answer="NO"
333
334    grep -q nohw /proc/cmdline
335    if [ "$?" -eq 0 ]; then
336        return
337    fi
338    if [ -x ./mindi-rsthw ]; then
339        grep -q RESTORE /proc/cmdline
340        if [ "$?" -ne 0 ]; then
341            #clear
342            echo "*********************************************************************"
343            echo "Do you want to restore the HW configuration of the original machine ?"
344            echo "(This may dammage your hardware so be sure to check twice before saying yes)"
345            echo "*********************************************************************"
346            echo "Please confirm by typing YES exactly as written here (NO by default)"
347            echo -n "--> "
348            read answer
349        else
350            answer="YES"
351        fi
352        if [ "$answer" = "YES" ] ; then
353            ./mindi-rsthw
354        fi
355    fi
356}
357
358
359#RunDevfsd() {
360#    loc=`which devfsd 2> /dev/null`
361#    if [ "$loc" != "" ] ; then
362#        LogIt "Starting devfsd"
363#        devfsd /dev &
364#        sleep 5
365#    fi
366#}
367
368
369
370StartUSBKbd() {
371# Prepare minimal USB env in case we have USB kbd such as with iLO
372[ -d /proc/bus/usb ] && ! grep -q /proc/bus/usb /proc/mounts && mount -t usbfs none /proc/bus/usb
373echo "$DENY_MODS" | grep -Eq 'uhcd_hci |usbhid |usbcore '
374if [ $? -eq 0 ]; then
375    return
376fi
377modprobe -q uhcd_hci
378modprobe -q usbhid
379}
380
381
382
383StartLvms() {
384    if [ "`grep -i nolvm /proc/cmdline`" ]; then
385        return;
386    fi
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 /proc/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 /proc/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        # Try to Deal with a busybox bug on inexistant links
580        cp /tmp/* /tmp.old/
581        rm -f /tmp/*
582        $mount_cmd /tmp
583        mv /tmp.old/* /tmp/
584        # Try to Deal with a busybox bug on inexistant links
585        cp /tmp.old/* /tmp/
586        rm -rf /tmp.old
587        mkdir -p /tmp/tmpfs
588        mkdir -p $GROOVY
589    echo "Done."
590    LogIt "Successfully mounted dynamic /tmp ramdisk"
591#   mkdir -p /tmp/tmpfs/var
592#        mv -f /var/log /tmp/tmpfs/var/log
593#        ln -sf /tmp/tmpfs/var/log /var/log
594    fi
595}
596
597
598WelcomeMessage()
599{
600    echo "********************************************************************"
601    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
602    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
603which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
604    echo "Executables and source code are covered by the GNU GPL. No warranty."
605    echo "running on $ARCH"
606    echo "********************************************************************"
607}
608
609
610EnableCcissIfAppropriate() {
611    local i fname
612    for i in 0 1 2 3 ; do
613        fname="/proc/driver/cciss/cciss$i"
614        if [ -e "$fname" ] ; then
615            LogIt "Engaging $fname"
616            echo "engage scsi" > $fname
617            LogIt "...result=$?"
618        fi
619    done
620}
621
622ModprobeAllModules() {
623
624    for m in `find /lib/modules -name '*\.ko*' -o -name '*\.o*'`; do
625        k=`basename $m | sed 's/\.ko.*$//'`
626        j=`basename $k | sed 's/\.o.*$//'`
627        echo "$DENY_MODS" | grep -q "$j "
628        if [ $? -eq 0 ]; then
629            echo "Denying $j..."
630            continue
631        fi
632        echo "Probing $j..."
633        modprobe -q $j
634    done
635}
636
637ExtractDataDisksAndLoadModules() {
638    echo "Installing additional tools ..."
639    install-additional-tools
640    # Keep the kernel silent again
641    PKLVL=`cut -f1 /proc/sys/kernel/printk`
642    echo 0 > /proc/sys/kernel/printk
643    ModprobeAllModules
644    echo $PKLVL > /proc/sys/kernel/printk
645
646    # Retry failed udev events now that local filesystems are mounted read-write
647    # (useful for rules creating network ifcfg files)
648    if [ -e "/tmp/USE-UDEV" ] ; then
649        if [ -x /sbin/udevadm ]; then
650            /sbin/udevadm trigger --retry-failed
651        fi
652    fi
653}
654
655# ------------------------ main -----------------------
656
657MINDI_VER=PBVER
658MINDI_REV=PBREV
659trap CaughtSoftReset SIGTERM
660LOGFILE=/var/log/mondorestore.log
661PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
662GROOVY=/tmp/groovy-stuff
663USER=root
664ARCH=`uname -m`
665
666export PATH GROOVY USER LOGFILE ARCH
667
668echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
669
670mount -o remount rw /
671[ ! "$GROOVY" ] && Die "I'm not groovy!"
672for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
673    mkdir -p $i
674done
675#/bin/update
676mount /proc/ /proc -v -t proc
677mkdir /sys 2> /dev/null
678mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
679# For ESX 3
680[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
681rm -f /foozero
682
683if [ "`grep -i denymods /proc/cmdline`" ]; then
684    export DENY_MODS="`cat /proc/cmdline | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
685else
686    export DENY_MODS=" "
687fi
688if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2> /dev/null`" ]; then
689    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
690    export DENY_MODS="usb-storage $DENY_MODS"
691fi
692if [ "`grep -i forcemods /proc/cmdline`" ]; then
693    export FORCE_MODS="`cat /proc/cmdline | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
694else
695    export FORCE_MODS=" "
696fi
697
698echo "Activating a potential USB keyboard/mouse"
699StartUSBKbd
700
701if [ -f /proc/sys/kernel/exec-shield ]; then
702    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
703fi
704
705if [ -f /proc/modules ]; then
706    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
707fi
708
709if [ -e "/tmp/USE-UDEV" ] ; then
710    RunUdevd
711fi
712ExtractDevTarballs
713LaunchTerminals
714
715# Keeping kernel silent  for module insertion
716PKLVL=`cut -f1 /proc/sys/kernel/printk`
717echo 0 > /proc/sys/kernel/printk
718ModprobeAllModules
719echo $PKLVL > /proc/sys/kernel/printk
720
721EnableCcissIfAppropriate
722#-------------------------------
723#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
724#-------------------------------
725UseTmpfs
726if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
727    LogIt "Warning - /tmp/mondo-restore.cfg not found"
728fi
729if [ "`grep -i pxe /proc/cmdline`" ] || [ "`grep -i net /proc/cmdline`" ]; then
730    # We need to get here exported variables from start-netfs
731    . /sbin/start-netfs
732fi
733
734if [ "`grep -i 'obdr ' /tmp/mondo-restore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' /tmp/mondo-restore.cfg 2>/dev/null`" ]; then
735    HandleTape
736    ExtractDataDisksAndLoadModules
737elif [ "`grep -i pxe /proc/cmdline`" ]; then
738    # Simulate a local CD
739    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
740    CD_MOUNTED_OK=yes
741    ExtractDataDisksAndLoadModules
742    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
743    sed -i "s/backup-media-type.*/backup-media-type netfs/" /tmp/mondo-restore.cfg
744elif [ "`grep -i usb= /proc/cmdline`" ] || [ "`grep -i usb /tmp/mondo-restore.cfg 2>/dev/null | grep media-type`" ]; then
745    . /sbin/start-usb
746
747    # Simulate a local CD
748    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
749    CD_MOUNTED_OK=yes
750    ExtractDataDisksAndLoadModules
751else
752    HandleCDROM
753    ExtractDataDisksAndLoadModules
754    # We need to get here exported variables from start-netfs
755    . /sbin/start-netfs
756fi
757res=$?
758ConfigureLoggingDaemons
759if [ -e "/tmp/USE-DEVFS" ] ; then
760    umount /mnt/cdrom 2> /dev/null
761    mv /dev/cdrom /cdrom.lnk 2> /dev/null
762    CD_MOUNTED_OK=""
763    RunDevfsd
764fi
765LoadKeymap
766WelcomeMessage
767RstHW
768echo "Starting potential Raid/LVMs ..."
769PauseForRaids
770StartRaids
771StartMpath
772StartLvms
773CopyBootDevEntry
774mkdir -p /tmp/tmpfs
775sleep 2
776#clear
777if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
778    LogIt "Creating /dev/md/* softlinks just in case." 1
779    mkdir -p /dev/md
780    cp -af /dev/md0 /dev/md/0 2> /dev/null
781    cp -af /dev/md1 /dev/md/1 2> /dev/null
782    cp -af /dev/md2 /dev/md/2 2> /dev/null
783fi
784[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
785
786if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
787    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
788    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
789    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
790    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
791    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
792fi
793hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
794
795# Log some useful info
796LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
797LogIt "/proc/cmdline is:"
798LogIt "----------"
799cat /proc/cmdline  >> $LOGFILE
800LogIt "----------"
801LogIt "df result:"
802LogIt "----------"
803df >> $LOGFILE
804LogIt "-------------"
805LogIt "mount result:"
806LogIt "-------------"
807mount >> $LOGFILE
808LogIt "-------------"
809LogIt "lsmod result:"
810LogIt "-------------"
811lsmod >> $LOGFILE
812LogIt "-------------"
813LogIt "dmesg result:"
814LogIt "-------------"
815dmesg >> $LOGFILE
816LogIt "-------------"
817LogIt "/proc/swaps:" >> $LOGFILE
818LogIt "-------------"
819cat /proc/swaps  >> $LOGFILE
820LogIt "-------------"
821LogIt "/proc/filesystems:" >> $LOGFILE
822LogIt "-------------"
823cat /proc/filesystems  >> $LOGFILE
824LogIt "-------------"
825LogIt "/proc/partitions:" >> $LOGFILE
826LogIt "-------------"
827cat /proc/partitions  >> $LOGFILE
828LogIt "-------------"
829LogIt "fdisk result:" >> $LOGFILE
830LogIt "-------------"
831fdisk -l  >> $LOGFILE
832
833ide-opt
834
835#ctrlaltdel soft
836for path in /usr.bin /usr/bin ; do
837    fname=$path/nano
838    [ -e "$fname" ] && ln -sf $fname /usr/bin/pico
839done
840res=`which nano 2> /dev/null`
841[ "$res" ] && ln -sf /usr/bin/
842for i in null stdout stdin stderr ; do
843    cp -af /dev/$i /tmp
844done
845# Not sure it's still needed, but shouldn't hurt
846if [ -e "/tmp/USE-UDEV" ] ; then
847    if [ -x /sbin/udevadm ]; then
848        /sbin/udevadm trigger --retry-failed
849    fi
850fi
851if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
852    LogIt "backup-media-type is specified in config file - great."
853    LogIt "Calling post-init"
854    # start-netfs moved it under /tmp as the NFS share is already unmounted
855    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
856        post=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
857    fi
858    if [ -x $pre ]; then
859        echo "Executing preliminary script $pre"
860        LogIt "Executing preliminary script $pre"
861        $pre
862    fi
863    post-init
864else
865    LogIt "backup-media-type is not specified in config file."
866    LogIt "I think this media has no archives on it."
867fi
868if [ "`grep -i "post=" /proc/cmdline`" ] ; then
869    for i in `cat /proc/cmdline` ; do
870        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
871    done
872    # start-netfs moved it under /tmp as the NFS share is already unmounted
873    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
874        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
875    fi
876    if [ -x $post ]; then
877        echo "Executing final script $post"
878        LogIt "Executing final script $post"
879        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
880            mount-me
881        fi
882        $post
883        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
884            unmount-me
885        fi
886    fi
887fi
888if grep "RESTORE" /proc/cmdline > /dev/null 2> /dev/null ; then
889    echo "Rebooting in 10 seconds automatically as per reboot order"
890    echo -en "Press ^C to interrupt if you have to ..."
891    for i in 1 2 3 4 5 6 7 8 9 10 ; do
892        sleep 1
893        echo -en "."
894    done
895    echo "Boom."
896    sleep 1
897else
898    echo -en "Type 'exit' to reboot the PC\n"
899    umount /mnt/cdrom 2> /dev/null
900    mount / -o rw,remount > /dev/null 2> /dev/null
901    LogIt "Launching Shell"
902    sh
903fi
904CaughtSoftReset
905# reboot
Note: See TracBrowser for help on using the repository browser.