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

Last change on this file since 2481 was 2481, checked in by Bruno Cornec, 11 years ago
  • If using nolvm, mondorestore should also not analyze and handle i-want-my-lvm
  • Add support for diskdumplib driver useful for RHEL 3 and IBM xseries 336
  • Fix #367 - the for loop doesn't make any test now, as it was computed before entering the loop, leading to a

n error, and was also made inside the loop anyway.

  • Adds a nolvm boot option at restore time
  • small improvement for loging in USB case

(merge from 2.2.9 2475:2480)

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