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

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