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

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