source: branches/2.2.10/mindi/rootfs/sbin/init @ 2594

Last change on this file since 2594 was 2594, checked in by bruno, 9 years ago

r3735@localhost: bruno | 2010-03-14 19:50:12 +0100

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