source: MondoRescue/branches/2.2.10/mindi/rootfs/sbin/init @ 2462

Last change on this file since 2462 was 2462, checked in by Bruno Cornec, 11 years ago

r3548@localhost: bruno | 2009-10-16 19:18:27 +0200

  • mindi now boots in a QEMU VM without busybox
  • mindi is now noarch as a consequence
  • MINDI_LIB becomes MINDI_DATA for coherency and as a consequence
  • CACHEDIR becomes MINDI_CACHE for coherency and it's a build parameter and not hardcoded anymore in mindi
  • THat variable is also used at restore time for mondorestore.cfg e.g.
  • FAILSAFE kernel is gone. Just use another kernel of your choice. Most std kernels work anyway
  • TurnTgzIntoRdz? rewritten and now really computes data disk size and not suppose its size
  • Interface mondo/mindi changed again => incompatible
  • Non-bootable media not supported anymore.
  • Mondorescue adapted to these changes but not tested yet
  • Doc updated as well
  • Property svn:keywords set to Id
File size: 23.9 KB
Line 
1#!/bin/sh
2#
3# $Id: init 2462 2009-10-20 14:07:00Z 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 [ -e "/tmp/i-want-my-lvm" ] ; then
390        LogIt "Scanning LVM's..." 1
391        if which lvm ; then
392            modprobe -q dm-mod
393            modprobe -q dm_mod
394            lvm vgscan --mknodes
395        else
396            vgscan
397        fi
398        grep -E "^#.*vgchange" /tmp/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
399        chmod +x /tmp/start-lvm
400        echo -en "Starting LVM's..."
401        /tmp/start-lvm &
402        for i in 1 2 3 4 5 ; do
403            echo -en "."
404            sleep 1
405        done
406        echo "Done."
407    fi
408# If necessary, cannibalize 'analyze-my-lvm'; copy some of its code here,
409# pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
410    LogIt "LVM's have been started."
411}
412
413StartPowerPath() {
414
415    # Taken from the init script of EMC PowerPath on RHEL
416    if [ -f /etc/emcp_devicesDB.dat ]; then 
417        if [ -f /etc/emcp_devicesDB.idx ]; then
418            /etc/opt/emcpower/emcpmgr map -p > /dev/null 2>&1
419        fi
420    fi
421
422    /sbin/powermt config > /dev/null 2>&1
423    #  Wait for udev to finish creating emcpower devices
424    #
425    pdfound=1
426    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
427        pdfound=1
428        for pd in `/bin/ls -d /sys/block/emcpower* 2> /dev/null`; do
429           bpd=`basename $pd`
430           if [ ! -e /dev/$bpd ]; then
431              pdfound=0
432              sleep 2
433              break;
434           fi
435        done
436        if [ "$pdfound" -eq 1 ]; then
437            break
438        fi
439    done
440    if [ "$pdfound" -eq 0 ]; then
441       echo "Unable to start PowerPath"
442    fi
443
444    /sbin/powermt load      > /dev/null 2>&1
445    /etc/opt/emcpower/emcpmgr map   > /dev/null 2>&1
446    /etc/opt/emcpower/powercf -C    > /dev/null 2>&1
447    if [ ! -e /etc/powermt.custom ]; then 
448       /sbin/powermt save       > /dev/null 2>&1
449    fi 
450    /sbin/powermt register  > /dev/null 2>&1
451    /sbin/powermig transition -startup -noprompt   > /dev/null 2>&1
452}
453
454StartMpath() {
455    if [ "`grep -i nompath $CMDLINE`" ]; then
456        return;
457    fi
458    if [ "`grep mpath $MINDI_CACHE/mountlist.txt`" ]; then
459        if [ -x /sbin/multipath ]; then
460            echo "Starting Mpath..."
461            mkdir -p /var/lib/multipath
462            cat > /etc/multipath.conf << EOF
463defaults {
464        user_friendly_names yes
465}
466EOF
467            /sbin/multipath -v 0
468            if [ -x /sbin/kpartx ]; then
469                /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
470            fi
471        fi
472    fi
473}
474
475StartRaids() {
476    local raid_devices i
477
478    if [ "`grep -i noraid /proc/cmdline`" ]; then
479        return;
480    fi
481
482    raid_devices=`grep /dev/md $MINDI_CACHE/mountlist.txt | cut -d' ' -f1`
483    if which raidstart > /dev/null 2> /dev/null ; then
484        for i in $raid_devices ; do
485            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
486                LogIt "$i is started already; no need to run 'raidstart $i'" 1
487            else
488                LogIt "Running 'raidstart $i'" 1
489                raidstart $i
490            fi
491        done
492    elif which mdrun > /dev/null 2> /dev/null ; then
493        if [ "`grep -i nomd /proc/cmdline`" ]; then
494            return;
495        fi
496        LogIt "Running 'mdrun'" 1
497        mdrun
498    elif which mdadm > /dev/null 2> /dev/null ; then
499        if [ "`grep -i nomd /proc/cmdline`" ]; then
500            return;
501        fi
502        LogIt "Running 'mdadm'" 1
503        for i in $raid_devices ; do
504            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
505                LogIt "$i is started already; no need to run 'mdadm $i'" 1
506            else
507                if [ -f /etc/mdadm.conf ] ; then
508                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm.conf" 1
509                    mdadm -A $i -c /etc/mdadm.conf
510                elif [ -f /etc/mdadm/mdadm.conf ] ; then
511                    LogIt "Running 'mdadm $i' with user supplied /etc/mdadm/mdadm.conf" 1
512                    mdadm -A $i -c /etc/mdadm/mdadm.conf
513                else
514                    LogIt "Running 'mdadm $i'" 1
515                    mdadm -Ac partitions -m dev $i
516                fi
517            fi
518        done
519    elif which dmraid > /dev/null 2> /dev/null ; then
520        if [ "`grep -i nodmraid $CMDLINE`" ]; then
521            return;
522        fi
523        for x in $(/sbin/dmraid -ay -i -p -t 2>/dev/null | grep -E  -iv "^no " |awk -F ':' '{ print $1 }') ; do
524            echo "Please send the result of /sbin/dmraid -ay -i -p -t to the devteam !!!"
525            return
526            #dmname=$(resolve_dm_name $x)
527            #[ -z "$dmname" ] && continue
528            #/sbin/dmraid  -ay -i -p "$dmname" >/dev/null 2>&1
529            #/sbin/kpartx -a -p p "/dev/mapper/$dmname"
530        done
531    else
532        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
533    fi
534
535}
536
537
538TryAgainToFindCD() {
539    local res
540    mount | grep /mnt/cdrom && return 0
541    [ "`grep "backup_media_type" $MINDI_CACHE/mondorestore.cfg 2> /dev/null | grep "cdstream"`" ] && return
542    LogIt "Trying to mount CD-ROM a 2nd time..."
543    find-and-mount-cdrom --second-try
544    res=$?
545    if [ "$res" -eq "0" ] ; then
546        CD_MOUNTED_OK=yes
547        LogIt "CD-ROM drive mounted successfully." 1
548    else
549        LogIt "I still cannot find or mount the CD-ROM drive, by the way."
550    fi
551}
552
553
554
555UseTmpfs()
556{
557    local mount_cmd
558    echo -en "Mounting /tmp/tmpfs..."
559    mkdir -p /tmp/tmpfs
560# For technical reasons, some sets are as large as 16MB.
561# I am allowing 32MB because selective restore occupies a lot of space.
562    for size in 128m 64m 48m 40m 32m ; do
563        mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
564        LogIt "Trying '$mount_cmd'"
565        $mount_cmd /tmp/tmpfs 2>> $LOGFILE
566        res=$?
567        [ "$res" -eq "0" ] && break
568    done
569    if [ "$res" -ne "0" ] ; then
570        LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
571        umount /tmp/tmpfs > /dev/null 2> /dev/null
572        rmdir /tmp/tmpfs
573        ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondo-restore
574        LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
575    else
576        LogIt "Great. Pivot succeeded w/ size=$size" 1
577        echo -en "Pivoting /tmp..."
578        umount /tmp/tmpfs
579        mkdir -p /tmp.old
580        mv /tmp/* /tmp.old/
581        rm -f /tmp/*
582        $mount_cmd /tmp
583        mv /tmp.old/* /tmp/
584        rm -rf /tmp.old
585        mkdir -p /tmp/tmpfs
586    echo "Done."
587    LogIt "Successfully mounted dynamic /tmp ramdisk"
588#   mkdir -p /tmp/tmpfs/var
589#        mv -f /var/log /tmp/tmpfs/var/log
590#        ln -sf /tmp/tmpfs/var/log /var/log
591    fi
592}
593
594
595WelcomeMessage()
596{
597    echo "********************************************************************"
598    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
599    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
600which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
601    echo "Executables and source code are covered by the GNU GPL. No warranty."
602    echo "running on $ARCH"
603    echo "********************************************************************"
604}
605
606
607EnableCcissIfAppropriate() {
608    local i fname
609    for i in 0 1 2 3 ; do
610        fname="/proc/driver/cciss/cciss$i"
611        if [ -e "$fname" ] ; then
612            LogIt "Engaging $fname"
613            echo "engage scsi" > $fname
614            LogIt "...result=$?"
615        fi
616    done
617}
618
619ModprobeAllModules() {
620
621    for m in `find /lib/modules -name '*\.ko*' -o -name '*\.o*'`; do
622        k=`basename $m | sed 's/\.ko.*$//'`
623        j=`basename $k | sed 's/\.o.*$//'`
624        echo "$DENY_MODS" | grep -q "$j "
625        if [ $? -eq 0 ]; then
626            echo "Denying $j..."
627            continue
628        fi
629        echo "Probing $j..."
630        modprobe -q $j
631    done
632}
633
634ExtractDataDisksAndLoadModules() {
635    echo "Installing additional tools ..."
636    install-additional-tools
637    # Keep the kernel silent again
638    PKLVL=`cut -f1 /proc/sys/kernel/printk`
639    echo 0 > /proc/sys/kernel/printk
640    ModprobeAllModules
641    echo $PKLVL > /proc/sys/kernel/printk
642
643    # Retry failed udev events now that local filesystems are mounted read-write
644    # (useful for rules creating network ifcfg files)
645    if [ -e "$MINDI_CACHE/USE-UDEV" ] ; then
646        if [ -x /sbin/udevadm ]; then
647            /sbin/udevadm trigger --retry-failed
648        fi
649    fi
650}
651
652# ------------------------ main -----------------------
653
654MINDI_VER=PBVER
655MINDI_REV=PBREV
656trap CaughtSoftReset SIGTERM
657LOGFILE=/var/log/mondorestore.log
658PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
659GROOVY=/tmp/groovy-stuff
660USER=root
661ARCH=`uname -m`
662
663export PATH GROOVY USER LOGFILE ARCH
664
665echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV})"
666
667mount -o remount rw /
668[ ! "$GROOVY" ] && Die "I'm not groovy!"
669for i in $GROOVY /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
670    mkdir -p $i
671done
672#/bin/update
673mount /proc/ /proc -v -t proc
674mkdir /sys 2> /dev/null
675mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
676# For ESX 3
677[ -d /proc/vmware ] && ! grep -q /vmfs /proc/mounts && mount -t vmfs /vmfs /vmfs
678rm -f /foozero
679
680if [ "`grep -i denymods $CMDLINE`" ]; then
681    export DENY_MODS="`cat $CMDLINE | sed 's~.*denymods=\"\(.*\)\".*~\1~'` mondonone"
682else
683    export DENY_MODS=" "
684fi
685if [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2> /dev/null`" ]; then
686    # Do not try to load usb storage when dealing with OBDR it makes the modprobe hang :-(
687    export DENY_MODS="usb-storage $DENY_MODS"
688fi
689if [ "`grep -i forcemods $CMDLINE`" ]; then
690    export FORCE_MODS="`cat $CMDLINE | sed 's~.*forcemods=\"\(.*\)\".*~\1~'` mondonone"
691else
692    export FORCE_MODS=" "
693fi
694
695echo "Activating a potential USB keyboard/mouse"
696StartUSBKbd
697
698if [ -f /proc/sys/kernel/exec-shield ]; then
699    echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
700fi
701
702if [ -f /proc/modules ]; then
703    echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
704fi
705
706if [ -e "$MINDI_CACHE/USE-UDEV" ] ; then
707    RunUdevd
708fi
709ExtractDevTarballs
710LaunchTerminals
711
712# Keeping kernel silent  for module insertion
713PKLVL=`cut -f1 /proc/sys/kernel/printk`
714echo 0 > /proc/sys/kernel/printk
715ModprobeAllModules
716echo $PKLVL > /proc/sys/kernel/printk
717
718EnableCcissIfAppropriate
719#-------------------------------
720#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
721#-------------------------------
722UseTmpfs
723if [ ! -e "$MINDI_CACHE/mondorestore.cfg" ] ; then
724    LogIt "Warning - $MINDI_CACHE/mondorestore.cfg not found"
725fi
726if [ "`grep -i pxe $CMDLINE`" ] || [ "`grep -i net $CMDLINE`" ]; then
727    # We need to get here exported variables from start-netfs
728    . /sbin/start-netfs
729fi
730
731if [ "`grep -i 'obdr ' $MINDI_CACHE/mondorestore.cfg 2>/dev/null`" ] || [ "`grep -i ' udev' $MINDI_CACHE/mondorestore.cfg 2>/dev/null`" ]; then
732    HandleTape
733    ExtractDataDisksAndLoadModules
734elif [ "`grep -i pxe $CMDLINE`" ]; then
735    # Simulate a local CD
736    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
737    CD_MOUNTED_OK=yes
738    ExtractDataDisksAndLoadModules
739    # Fake the conf file to force it to NFS mode, even if we made originally a CD (mandatory for mondorestore to work correctly)
740    sed -i "s/backup-media-type.*/backup-media-type netfs/" $MINDI_CACHE/mondorestore.cfg
741elif [ "`grep -i usb= $CMDLINE`" ] || [ "`grep -i usb $MINDI_CACHE/mondorestore.cfg 2>/dev/null | grep media-type`" ]; then
742    . /sbin/start-usb
743
744    # Simulate a local CD
745    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
746    CD_MOUNTED_OK=yes
747    ExtractDataDisksAndLoadModules
748else
749    HandleCDROM
750    ExtractDataDisksAndLoadModules
751    # We need to get here exported variables from start-netfs
752    . /sbin/start-netfs
753fi
754res=$?
755ConfigureLoggingDaemons
756if [ -e "$MINDI_CACHE/USE-DEVFS" ] ; then
757    umount /mnt/cdrom 2> /dev/null
758    mv /dev/cdrom /cdrom.lnk 2> /dev/null
759    CD_MOUNTED_OK=""
760    RunDevfsd
761fi
762LoadKeymap
763WelcomeMessage
764RstHW
765echo "Starting potential Raid/LVMs ..."
766PauseForRaids
767StartRaids
768StartMpath
769StartLvms
770CopyBootDevEntry
771mkdir -p /tmp/tmpfs
772sleep 2
773if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ $MINDI_CACHE/mountlist.txt`" != "" ] ; then
774    LogIt "Creating /dev/md/* softlinks just in case." 1
775    mkdir -p /dev/md
776    cp -af /dev/md0 /dev/md/0 2> /dev/null
777    cp -af /dev/md1 /dev/md/1 2> /dev/null
778    cp -af /dev/md2 /dev/md/2 2> /dev/null
779fi
780[ -e "$MINDI_CACHE/mountlist.txt" ] && cp -f $MINDI_CACHE/mountlist.txt $MINDI_CACHE/mountlist.original
781
782if ! [ "`grep -i "pxe" $CMDLINE`" ] ; then
783    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
784    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
785    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
786    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
787    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
788fi
789hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
790
791# Log some useful info
792LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV})"
793LogIt "$CMDLINE is:"
794LogIt "----------"
795cat $CMDLINE  >> $LOGFILE
796LogIt "----------"
797LogIt "df result:"
798LogIt "----------"
799df >> $LOGFILE
800LogIt "-------------"
801LogIt "mount result:"
802LogIt "-------------"
803mount >> $LOGFILE
804LogIt "-------------"
805LogIt "lsmod result:"
806LogIt "-------------"
807lsmod >> $LOGFILE
808LogIt "-------------"
809LogIt "dmesg result:"
810LogIt "-------------"
811dmesg >> $LOGFILE
812LogIt "-------------"
813LogIt "/proc/swaps:" >> $LOGFILE
814LogIt "-------------"
815cat /proc/swaps  >> $LOGFILE
816LogIt "-------------"
817LogIt "/proc/filesystems:" >> $LOGFILE
818LogIt "-------------"
819cat /proc/filesystems  >> $LOGFILE
820LogIt "-------------"
821LogIt "/proc/partitions:" >> $LOGFILE
822LogIt "-------------"
823cat /proc/partitions  >> $LOGFILE
824LogIt "-------------"
825LogIt "fdisk result:" >> $LOGFILE
826LogIt "-------------"
827fdisk -l  >> $LOGFILE
828
829ide-opt
830
831#ctrlaltdel soft
832for path in /usr.bin /usr/bin ; do
833    fname=$path/nano
834    [ -e "$fname" ] && ln -sf $fname /usr/bin/pico
835done
836res=`which nano 2> /dev/null`
837[ "$res" ] && ln -sf /usr/bin/
838for i in null stdout stdin stderr ; do
839    cp -af /dev/$i /tmp
840done
841# Not sure it's still needed, but shouldn't hurt
842if [ -e "/tmp/USE-UDEV" ] ; then
843    if [ -x /sbin/udevadm ]; then
844        /sbin/udevadm trigger --retry-failed
845    fi
846fi
847if grep "backup-media-type" $MINDI_CACHE/mondorestore.cfg > /dev/null 2> /dev/null ; then
848    LogIt "backup-media-type is specified in config file - great."
849    LogIt "Calling post-init"
850    # start-netfs moved it under /tmp as the NFS share is already unmounted
851    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
852        post=`echo $pre | sed 's|^/tmp/isodir|/tmp|'`
853    fi
854    if [ -x $pre ]; then
855        echo "Executing preliminary script $pre"
856        LogIt "Executing preliminary script $pre"
857        $pre
858    fi
859    post-init
860else
861    LogIt "backup-media-type is not specified in config file."
862    LogIt "I think this media has no archives on it."
863fi
864if [ "`grep -i "post=" $CMDLINE`" ] ; then
865    for i in `cat $CMDLINE` ; do
866        echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
867    done
868    # start-netfs moved it under /tmp as the NFS share is already unmounted
869    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
870        post=`echo $post | sed 's|^/tmp/isodir|/tmp|'`
871    fi
872    if [ -x $post ]; then
873        echo "Executing final script $post"
874        LogIt "Executing final script $post"
875        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
876            mount-me
877        fi
878        $post
879        if [ "`echo $post | grep -E '^/mnt/RESTORING'`" ]; then
880            unmount-me
881        fi
882    fi
883fi
884if grep "RESTORE" $CMDLINE > /dev/null 2> /dev/null ; then
885    echo "Rebooting in 10 seconds automatically as per reboot order"
886    echo -en "Press ^C to interrupt if you have to ..."
887    for i in 1 2 3 4 5 6 7 8 9 10 ; do
888        sleep 1
889        echo -en "."
890    done
891    echo "Boom."
892    sleep 1
893else
894    echo -en "Type 'exit' to reboot the PC\n"
895    umount /mnt/cdrom 2> /dev/null
896    mount / -o rw,remount > /dev/null 2> /dev/null
897    LogIt "Launching Shell"
898    sh
899fi
900CaughtSoftReset
901# reboot
Note: See TracBrowser for help on using the repository browser.