source: branches/2.2.9/mindi/rootfs/etc/init.d/rcS @ 2893

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