source: branches/stable/mindi/rootfs/sbin/init @ 1581

Last change on this file since 1581 was 1581, checked in by bruno, 12 years ago

Continue to remove floppy support

  • Property svn:keywords set to Id
File size: 15.3 KB
Line 
1#!/bin/sh
2#
3# $Id: init 1581 2007-07-27 00:11:55Z bruno $
4#
5# init script launched during the restore process
6#------------------------------------------------------------
7
8
9CaughtSoftReset() {
10    trap SIGTERM
11    reboot
12}
13
14
15ConfigureLoggingDaemons() {
16    echo -en "Running klogd..."
17    klogd -c 2 > /dev/null 2> /dev/null
18    echo -en "Done.\nRunning syslogd..."
19    syslogd > /dev/null 2> /dev/null
20    echo "Done."
21    LogIt "klogd and syslogd have been started."
22}
23
24
25
26CopyBootDevEntry() {
27    local outfile devfile
28    devfile=/dev/boot_device
29    outfile=`cat /BOOTLOADER.DEVICE 2> /dev/null`
30    [ ! "$outfile" ] && return 0
31    echo -en "Copying boot device to $outfile..."
32    if [ -e "$outfile" ] ; then
33    echo "OK."
34    return 0
35    fi
36    mkdir -p $outfile
37    rmdir $outfile
38    cp -pRdf $devfile $outfile
39    if [ "$?" -ne "0" ] ; then
40    echo "Failed."
41    return 1
42    else
43    echo "OK."
44    return 0
45    fi
46}
47
48
49
50Die() {
51    LogIt "Fatal error! $1" 1
52    exit 1
53}
54
55
56
57ExtractDevTarballs() {
58    cd /
59    for fname in ataraid.tgz ida.tgz i2o.tgz rd.tgz raw.tgz cciss.tgz nst.tgz dm.tgz vc.tgz ; do
60        if [ ! -e "/$fname" ] ; then
61            LogIt "/$fname not found; cannot extract to /." 1
62        else
63            echo -en "\rExtracting /$fname...     "
64            tar -zxf /$fname || LogIt "Error occurred while extracting /$fname"
65        fi
66    done
67    echo -en "\r"
68    LogIt "Extracted additional /dev entries OK.     " 1
69}
70
71
72
73LaunchTerminals() {
74    openvt 2 /bin/sh
75    openvt 3 /bin/sh
76    openvt 4 /bin/sh
77    openvt 5 /bin/sh
78    openvt 6 /bin/sh
79    openvt 7 /bin/sh /sbin/wait-for-petris
80}
81
82
83LoadKeymap() {
84    local fname
85    fname=`grep keymap-lives-here /tmp/mondo-restore.cfg | cut -d'=' -f2 2> /dev/null`
86    [ "$fname" = "" ] && return
87    if which loadkeys > /dev/null 2> /dev/null ; then
88        loadkeys $fname
89# loadkmap != loadkeys
90#    elif which loadkmap > /dev/null 2> /dev/null ; then
91#        loadkmap < $fname
92    else
93        LogIt "Using default keyboard map." 1
94    fi
95}
96
97
98UntarTapeStuff() {
99    local old_pwd res
100    old_pwd=`pwd`
101    cd $GROOVY
102    [ "$1" != "" ] && tapedev=$1
103    [ ! "$tapedev" ] && tapedev=`grep media-dev /tmp/mondo-restore.cfg | tr -s ' ' ' ' | cut -d'=' -f2`
104#    tar -zxf $tapedev
105    dd if=$tapedev bs=32k count=1024 | tar -zx
106    res=$?
107    if [ "$res" -eq "0" ] ; then
108    grep -v media-dev /tmp/mondo-restore.cfg > /tmp/mr.cfg
109    echo "media-dev=$tapedev" >> /tmp/mr.cfg
110        cp -f /tmp/mr.cfg /tmp/mondo-restore.cfg
111    fi
112    cd $old_pwd
113    return $res
114}
115
116HandleTape() {
117    local res tapedev
118    tapedev="" ; # will be set by UntarTapeStuff()
119    cd $GROOVY
120    UntarTapeStuff $tapedev || UntarTapeStuff /dev/st0 || UntarTapeStuff /dev/osst0 || UntarTapeStuff /dev/ht0
121    res=$?
122    while [ "$res" -ne "0" ] ; do
123        LogIt "$tapedev failed to act as extended data disk for booting." 1
124        LogIt "Please specify an alternate tape device," 1
125        LogIt "or hit <Enter> to boot from CD." 1
126        echo -en "---> "
127        read tapedev
128        if [ "$tapedev" ] ; then
129            LogIt "User specified $tapedev instead"
130            UntarTapeStuff $tapedev
131            res=$?
132        else
133            LogIt "User opted not to specify an alternate tapedev"
134            res=1
135        break
136        fi
137    done
138
139    if [ "$res" -ne "0" ] ; then
140        cd /
141        LogIt "Failed to use tape as extended datadisk. Reverting to cd." 1
142        HandleCDROM
143        res=$?
144    else
145    #   clear
146        LogIt "Using tape as extended datadisk. Good." 3
147        echo "Using tape as extd ddisk." > /tmp/TAPEDEV-HAS-DATA-DISKS
148        res=0
149        CD_MOUNTED_OK=yes
150    fi
151    return $res
152}
153
154
155
156HHandleCDROM() {
157    find-and-mount-cdrom
158    res=$?
159    if [ "$res" -ne "0" ] ; then
160        LogIt "First call to find-and-mount-cdrom failed." 1
161        LogIt "Sleeping for 3 seconds and trying again." 1
162        sleep 3
163        find-and-mount-cdrom
164        res=$?
165    fi
166    if [ "$res" -eq "0" ] ; then
167        LogIt "OK, I am running on a CD-ROM. Good." 3
168        CD_MOUNTED_OK=yes
169    else
170        LogIt "OK, I am unable to go on. You seem to be missing a driver" 3
171        LogIt "Your archives are probably fine but" 3
172        LogIt "your tape streamer and/or CD-ROM drive are eccentric. :-)" 3
173        CD_MOUNTED_OK=""
174    fi
175    return 0
176}
177
178
179HowMuchFreeSpaceOnRamdisk() {
180   df -m -P | grep /dev/ram | head -n1 | tr -s '\t' ' ' | cut -d' ' -f4
181}
182
183
184
185InsertEssentialModules() {
186#   Load the VIA IDE module first thing if it exists (requires ide-core).
187#   This is to ensure that DMA is working for VIA chipsets with 2.6 kernels.
188    for module in /ide-core.ko /via82cxxx.ko; do
189        [ -f "$module" ] && MyInsmod $module > /dev/null 2> /dev/null
190    done
191#   Then load the remaining modules in normal (i.e. arbitrary) order.
192    for j in 1 2 3 4 5 ; do
193        for i in `ls /*.*o* 2> /dev/null` ; do
194            [ -f "$i" ] && MyInsmod $i > /dev/null 2> /dev/null
195        done
196    done
197}
198
199
200
201PauseForRaids() {
202    if [ "`dmesg | grep -i "RAID Controller"`" != "" ] || [ "`dmesg | grep -i "Vendor: 3ware"`" != "" ] ; then
203        LogIt "RAID controller(s) detected. Pausing 10 seconds to let them warm up." 1
204        echo -en "Pausing..."
205        for i in 1 2 3 4 5 6 7 8 9 10 ; do
206            sleep 1
207            echo -en "$(($i*10))%..."
208        done
209        echo "Done."
210    fi
211}
212
213
214# 06/13/2002 --- DuckX's & Hugo's new routine
215# 10/11/2003 --- added a simple devfsd.conf file
216# 01/24/2005 --- cater for arbitrary locations of devfsd.conf by using the
217#                config file path compiled into devfsd
218RunDevfsd() {
219    loc=`which devfsd 2> /dev/null`
220    if [ "$loc" != "" ] ; then
221    LogIt "Devfs found. Testing kernel support..."
222    if [ ! -e "/dev/.devfsd" ] ; then
223        mount -t devfs devfs /dev 2>> $LOGFILE
224            if [ "$?" -ne "0" ] ; then
225        LogIt "Error while trying to mount devfs"
226        else
227        LogIt "Devfs mounted OK"
228        fi
229    fi
230    #check if the kernel supports devfs
231    if [ -e "/dev/.devfsd" ] ; then
232        [ -d "/proc/1" ] || mount -n /proc
233        LogIt "Kernel support found. Creating config file and starting devfsd"
234        conffile=`strings $loc | grep -E "devfsd.conf$"`
235        [ "$conffile" ] || conffile="/etc/devfsd.conf"
236        confpath=`echo $conffile | sed "s/\/devfsd\.conf$//"`
237        [ -d "$confpath" ] || mkdir -p $confpath
238        echo -en "REGISTER .* MKOLDCOMPAT\nUNREGISTER .* RMOLDCOMPAT\n" > $conffile
239        devfsd /dev &
240        sleep 5
241    else
242        LogIt "No devfs kernel support."
243    fi
244    fi
245}
246
247
248
249
250
251
252#RunDevfsd() {
253#    loc=`which devfsd 2> /dev/null`
254#    if [ "$loc" != "" ] ; then
255#        LogIt "Starting devfsd"
256#        devfsd /dev &
257#        sleep 5
258#    fi
259#}
260
261
262
263SpaceTests() {
264    [ -e "/tmp/filelist.full" ] && cp /tmp/filelist.full /tmp/FLF
265    if [ "`HowMuchFreeSpaceOnRamdisk`" -le "3" ] ; then
266        LogIt "Ramdisk is a bit smaller than I would like." 1
267        LogIt "Please re-run Mondo/Mindi but edit mindi first" 1
268        LogIt "and set EXTRA_SPACE to something high, e.g. 8000" 1
269        Die "Aborting. Please reboot."
270    fi
271    rm -f /tmp/FLF
272}
273
274
275
276StartLvms() {
277    if [ -e "/tmp/i-want-my-lvm" ] ; then
278        LogIt "Scanning LVM's..." 1
279        if which lvm ; then
280            MyInsmod dm-mod
281            MyInsmod dm_mod
282            lvm vgscan --mknodes
283        else
284            vgscan
285        fi
286        grep -E "^#.*vgchange" /tmp/i-want-my-lvm | sed "s/^#[ ]*//" > /tmp/start-lvm
287        chmod +x /tmp/start-lvm
288        echo -en "Starting LVM's..."
289        /tmp/start-lvm &
290        for i in 1 2 3 4 5 ; do
291        echo -en "."
292        sleep 1
293        done
294        echo "Done."
295    fi
296# If necessary, cannibalize 'analyze-my-lvm'; copy some of its code here,
297# pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
298    LogIt "LVM's have been started."
299}
300
301
302StartRaids() {
303    local raid_devices i
304
305    raid_devices=`grep /dev/md /tmp/mountlist.txt | cut -d' ' -f1`
306    if which raidstart > /dev/null 2> /dev/null ; then
307        for i in $raid_devices ; do
308            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
309                LogIt "$i is started already; no need to run 'raidstart $i'" 1
310            else
311                LogIt "Running 'raidstart $i'" 1
312                raidstart $i
313            fi
314        done
315    elif which mdrun > /dev/null 2> /dev/null ; then
316        LogIt "Running 'mdrun'" 1
317        mdrun
318    elif which mdadm > /dev/null 2> /dev/null ; then
319        LogIt "Running 'mdadm'" 1
320        for i in $raid_devices ; do
321            if grep `basename $i` /proc/mdstat > /dev/null 2> /dev/null ; then
322                LogIt "$i is started already; no need to run 'mdadm $i'" 1
323            else
324                LogIt "Running 'mdadm $i'" 1
325                mdadm -Ac partitions -m dev $i
326            fi
327        done
328    else
329        LogIt "Warning: Neither 'raidstart' nor 'mdrun''found. RAID devices may not have started." 1
330    fi
331
332}
333
334
335TryAgainToFindCD() {
336    local res
337    mount | grep /mnt/cdrom && return 0
338    [ "`grep "backup_media_type" /tmp/mondo-restore.cfg | grep "cdstream"`" ] && return
339    LogIt "Trying to mount CD-ROM a 2nd time..."
340    find-and-mount-cdrom --second-try
341    res=$?
342    if [ "$res" -eq "0" ] ; then
343        CD_MOUNTED_OK=yes
344        LogIt "CD-ROM drive mounted successfully." 1
345    else
346        LogIt "I still cannot find or mount the CD-ROM drive, by the way."
347    fi
348}
349
350
351
352UseTmpfs()
353{
354    local mount_cmd
355    echo -en "Mounting /tmp/tmpfs..."
356    mkdir -p /tmp/tmpfs
357# For technical reasons, some sets are as large as 16MB.
358# I am allowing 32MB because selective restore occupies a lot of space.
359    for size in 64m 48m 40m 32m ; do
360        mount_cmd="mount /dev/shm -t tmpfs -o size=$size" ; # was 34m until 04/2003
361        LogIt "Trying '$mount_cmd'"
362    $mount_cmd /tmp/tmpfs 2>> $LOGFILE
363    res=$?
364    [ "$res" -eq "0" ] && break
365    done
366    if [ "$res" -ne "0" ] ; then
367        LogIt "Failed. I could not run '$mount_cmd /tmp/tmpfs'. Your kernel is BROKEN or you do not have enough RAM." 1
368        umount /tmp/tmpfs > /dev/null 2> /dev/null
369    rmdir /tmp/tmpfs
370        ln -sf /mnt/RESTORING/tmp /tmp/tmpfs; # used by mondo-restore
371    LogIt "Failed to mount /tmp/tmpfs; using ugly softlink instead"
372    else
373        LogIt "Great. Pivot succeeded w/ size=$size" 1
374        echo -en "Pivoting /tmp..."
375        umount /tmp/tmpfs
376        mkdir -p /tmp.old
377        mv -f /tmp/* /tmp.old/
378        $mount_cmd /tmp
379        mv /tmp.old/* /tmp/
380        rmdir /tmp.old
381        mkdir -p /tmp/tmpfs
382        mkdir -p $GROOVY
383    echo "Done."
384    LogIt "Successfully mounted dynamic /tmp ramdisk"
385#   mkdir -p /tmp/tmpfs/var
386#        mv -f /var/log /tmp/tmpfs/var/log
387#        ln -sf /tmp/tmpfs/var/log /var/log
388    fi
389}
390
391
392WelcomeMessage()
393{
394    echo "********************************************************************"
395    echo "MINDI-LINUX by Mondo Dev Team - web site: http://www.mondorescue.org"
396    echo "Boot disk based on AlfaLinux & Trinux. BusyBox by Erik Andersen."
397which petris > /dev/null 2> /dev/null && echo "Petris was written by Peter Seidler <p.seidler@mail1.stofanet.dk>."
398    echo "Executables and source code are covered by the GNU GPL. No warranty."
399    echo "running on $ARCH"
400    echo "********************************************************************"
401}
402
403
404EnableCcissIfAppropriate() {
405    local i fname
406    for i in 0 1 2 3 4 5 6 7 8 9 ; do
407        fname="/proc/driver/cciss/cciss$i"
408        if [ -e "$fname" ] ; then
409            LogIt "Engaging $fname"
410            echo "engage scsi" > $fname
411            LogIt "...result=$?"
412        fi
413    done
414}
415
416
417ExtractDataDisksAndLoadModules() {
418    echo "Installing additional tools ..."
419    install-additional-tools
420    echo "Inserting modules ..."
421    insert-all-my-modules >> $LOGFILE 2>> $LOGFILE
422}
423
424# ------------------------ main -----------------------
425
426MINDI_VER=VVV
427MINDI_REV=RRR
428trap CaughtSoftReset SIGTERM
429LOGFILE=/tmp/mondorestore.log
430PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/mondo:/usr/games
431GROOVY=/tmp/groovy-stuff
432USER=root
433export PATH GROOVY USER LOGFILE
434
435echo "Welcome to init (from mindi ${MINDI_VER}-r${MINDI_REV}"
436
437mount -o remount rw /
438[ ! "$GROOVY" ] && Die "I'm not groovy!"
439for i in $GROOVY /mnt/floppy /mnt/cdrom /mnt/isodir /var/local/petris /tmp/isodir; do
440    mkdir -p $i
441done
442#/bin/update
443mount /proc/ /proc -v -t proc
444mkdir /sys 2> /dev/null
445mount /sys/ /sys -v -t sysfs 2>> $LOGFILE
446rm -f /foozero
447
448echo 0 > /proc/sys/kernel/exec-shield 2>> /dev/null
449
450ExtractDevTarballs
451LaunchTerminals
452InsertEssentialModules
453EnableCcissIfAppropriate
454#-------------------------------
455#WHOLIVESINAPINEAPPLEUNDERTHESEA#;# --- don't touch this :)
456#-------------------------------
457UseTmpfs
458if [ ! -e "/tmp/mondo-restore.cfg" ] ; then
459    LogIt "Warning - /tmp/mondo-restore.cfg not found"
460fi
461
462if [ "`grep -i 'tape ' /tmp/mondo-restore.cfg`" ] || [ "`grep -i udev /tmp/mondo-restore.cfg`" ] ; then
463    HandleTape
464    ExtractDataDisksAndLoadModules
465elif [ "`grep -i pxe /proc/cmdline`" ]; then
466    # We need to get here exported variables from start-nfs
467    . /sbin/start-nfs
468
469    # Simulate a local CD
470    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
471    CD_MOUNTED_OK=yes
472    ExtractDataDisksAndLoadModules
473else
474    HandleCDROM
475    ExtractDataDisksAndLoadModules
476    # We need to get here exported variables from start-nfs
477    . /sbin/start-nfs
478fi
479res=$?
480ConfigureLoggingDaemons
481if [ -e "/tmp/USE-DEVFS" ] ; then
482    umount /mnt/cdrom 2> /dev/null
483    mv /dev/cdrom /cdrom.lnk 2> /dev/null
484    CD_MOUNTED_OK=""
485    RunDevfsd
486fi
487echo "Starting potential Raid/LVMs ..."
488PauseForRaids
489StartRaids
490StartLvms
491CopyBootDevEntry
492LoadKeymap
493mkdir -p /tmp/tmpfs
494sleep 2
495#clear
496if [ -e "/dev/md0" ] && [ ! -e "/dev/md/0" ] && [ "`grep /dev/md/ /tmp/mountlist.txt`" != "" ] ; then
497    LogIt "Creating /dev/md/* softlinks just in case." 1
498    mkdir -p /dev/md
499    cp -af /dev/md0 /dev/md/0 2> /dev/null
500    cp -af /dev/md1 /dev/md/1 2> /dev/null
501    cp -af /dev/md2 /dev/md/2 2> /dev/null
502fi
503export ARCH=`uname -m`
504WelcomeMessage
505# SpaceTests; # Mandrake Linux 8.1 doesn't like this
506[ -e "/tmp/mountlist.txt" ] && cp -f /tmp/mountlist.txt /tmp/mountlist.original
507
508if ! [ "`grep -i "pxe" /proc/cmdline`" ] ; then
509    res="`cat /mnt/cdrom/archives/THIS-CD-NUMBER 2> /dev/null`"
510    [ "$res" != "1" ] && [ "$res" != "" ] && Die "This is CD #$res in the series. Please insert CD #1."
511    [ -e "/cdrom.lnk" ] && mv -f /cdrom.lnk /dev/cdrom && mount /dev/cdrom /mnt/cdrom && CD_MOUNTED_OK=yes
512    [ "$CD_MOUNTED_OK" != "yes" ] && TryAgainToFindCD
513    #mount | grep cdrom > /dev/null 2> /dev/null || mount /dev/cdrom /mnt/cdrom >> $LOGFILE 2>> $LOGFILE
514fi
515hack-cfg-if-necessary || LogIt "Cannot find hack-cfg-if-necessary"
516openvt 8 /usr/bin/tail -f $LOGFILE
517
518# Log some useful info
519LogIt "init (from mindi v$MINDI_VER-r${MINDI_REV}"
520LogIt "/proc/cmdline is:"
521cat /proc/cmdline  >> $LOGFILE
522LogIt "df result:"
523LogIt "----------"
524df >> $LOGFILE
525LogIt "-------------"
526LogIt "mount result:"
527LogIt "-------------"
528mount >> $LOGFILE
529LogIt "-------------"
530LogIt "lsmod result:"
531LogIt "-------------"
532lsmod >> $LOGFILE
533LogIt "-------------"
534LogIt "dmesg result:"
535LogIt "-------------"
536dmesg >> $LOGFILE
537
538#-------------------------------
539#ABSORBENTANDYELLOWANDPOROUSISHE#;# --- don't touch this either :)
540#-------------------------------
541
542#ctrlaltdel soft
543for path in /usr.bin /usr/bin ; do
544    fname=$path/nano
545    [ -e "$fname" ] && ln -sf $fname /usr/bin/pico
546done
547res=`which nano 2> /dev/null`
548[ "$res" ] && ln -sf /usr/bin/
549for i in null stdout stdin stderr ; do
550    cp -af /dev/$i /tmp
551done
552if grep "backup-media-type" /tmp/mondo-restore.cfg > /dev/null 2> /dev/null ; then
553    LogIt "backup-media-type is specified in config file - great."
554    LogIt "Calling post-init $mountlist"
555    post-init
556else
557    LogIt "backup-media-type is not specified in config file."
558    LogIt "I think this media has no archives on it."
559fi
560echo -en "Type 'exit' to reboot the PC\n"
561umount /mnt/cdrom 2> /dev/null
562mount / -o rw,remount > /dev/null 2> /dev/null
563LogIt "Launching Shell"
564sh
565CaughtSoftReset
566# reboot
Note: See TracBrowser for help on using the repository browser.