source: branches/2.2.10/mindi/mindi @ 2451

Last change on this file since 2451 was 2451, checked in by Bruno Cornec, 11 years ago
  • Fix a mr_asprintf usage without & causing a seg fault.
  • Adds support for grub2 conf file grub.cfg in addition to menu.lst
  • Fix for #288: only take the first result in SizeOfPartition? in case of multiple mounts
  • Improve USB log in case of error by adding the conf file

(Backport from 2.2.9)

  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 102.2 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 2451 2009-10-05 23:34:09Z bruno $
4#
5#-----------------------------------------------------------------------------
6# mindi - mini-Linux distro based on the user's filesystem & distribution
7#
8# Mindi can create a multi-image boot/root kit. The first image is the boot
9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
16ARCH=`/bin/uname -m`
17KERVERRUN=`/bin/uname -r`
18# By default we use the running kernel as a reference
19KERVER=$KERVERRUN
20
21# In case of problem with udev you can try to add udevdebug
22ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off udevtimeout=10"
23
24MINDI_REV=PBREV
25MINDI_VER=PBVER
26
27MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
28MINDI_PREFIX=XXX
29MINDI_CONF=YYY
30MINDI_SBIN=${MINDI_PREFIX}/sbin
31MINDI_LIB=LLL
32
33# Temporary directory for mindi
34TMPDIR=/tmp
35
36EXTRA_SPACE=60000       # increase if you run out of ramdisk space
37BOOT_SIZE=24576         # size of the boot disk
38
39PROMPT_MAKE_CD_IMAGE="yes"
40    # Ask if you want to make a CD Image to be written?
41    # if this is set to 'no', then the image will be created automatically
42
43PROMPT_MAKE_USB_IMAGE="yes"
44    # Ask if you want to make a USB Image to be written?
45    # if this is set to 'no', then the image will be created automatically
46
47USE_OWN_KERNEL="yes"
48    # If set to "no", you will be prompted for whether or not
49    # you want to use your own kernel, or the supplied default.
50    # If "yes" mindi will automatically use your own kernel.
51
52MY_FSTAB=/etc/fstab
53TAPE_MODS="ht st osst ide-tape ide_tape"
54SCSI_MODS="3w-xxxx 3w_xxxx 3w_9xxx 3w-9xxx 53c7,8xx a100u2w a320raid aacraid adpahci advansys aha152x aha1542 aha1740 aic79xx aic79xx_mod aic7xxx aic7xxx_mod aic7xxx_old AM53C974 atp870u BusLogic cciss cpqfc dmx3191d dpt_i2o dtc eata eata_dma eata_pio fdomain gdth g_NCR5380 i2o_block i2o_core ide-scsi ieee1394 imm in2000 initio ips iscsi iscsi_tcp libiscsi scsi_transport_iscsi isp megaraid megaraid_mm megaraid_mbox megaraid_sas mptbase mptscsih mptsas mptspi mptfc mptscsi mptctl NCR53c406a ncr53c8xx nsp32 pas16 pci2000 pci2220i pcmcia ppa psi240i qla1280 qla2200 qla2300 qla2400 qla2xxx qla2xxx_conf qlogicfas qlogicfc qlogicisp qlogicfas qlogicfas408 raw1394 scsi_mod scsi_transport_sas scsi_transport_spi scsi_transport_fc sd_mod crc_t10dif crc-t10dif seagate sg sim710 sr_mod sym53c416 sym53c8xx sym53c8xx_2 t128 tmscsim u14-34f ultrastor wd7000 vmhgfs intermodule scsi_dh scsi_tgt emcpdm emcpgpx emcpmpx emcp dc395x"
55
56# ide-probe-mod
57IDE_MODS="ide ide-floppy floppy ide-generic ide-detect ide-mod ide-disk ide_disk ide-cd ide_cd ide_cd_mod ide-cd_mod ide-cs ide-core ide_core ide-gd_mod edd paride ata_generic ata_piix libata dock via82cxxx generic nvidia ahci sata_nv cmd64x pata_amd pata_marvell pata_serverworks pata_sis amd74xx sis5513 jmicron sata_promise sata_via serverworks"
58PCMCIA_MODS="pcmcia_core ds yenta_socket"
59USB_MODS="usb-storage usb-ohci usb-uhci usbcore usb_storage input hid uhci_hcd ehci_hcd uhci-hcd ehci-hcd ohci-hcd ohci_hcd usbkbd usbhid keybdev mousedev libusual scsi_mod ff-memless"
60NET_MODS="auth_rpcgss sunrpc nfs nfs_acl lockd fscache loop mii 3c59x e100 bcm5700 bnx2 bnx2x e1000 e1000e igb eepro100 ne2k-pci tg3 libphy pcnet32 8139cp 8139too 8390 forcedeth vmxnet vmnet exportfs fuse"
61CDROM_MODS="$TAPE_MODS $IDE_MODS $USB_MODS $PCMCIA_MODS $SCSI_MODS $NET_MODS af_packet cdrom isocd isofs inflate_fs nls_iso8859-1 nls_base nls_cp437 nls_utf8 sg sr_mod zlib_inflate iso9660"
62# Those modules will only go on the backup media, not the boot media.
63EXTRA_MODS="$CDROM_MODS vfat fat loop md-mod linear raid0 raid1 xor raid10 raid5 raid456 lvm-mod dm-mod dm_mod dm-snapshot dm_snapshot dm-zero dm_zero dm-mirror dm_mirror dm-multipath dm-round-robin dm-emc dm-hp-sw dm-rdac multipath jfs xfs xfs_support pagebuf reiserfs ext2 ext3 minix nfs nfs_acl nfsd lockd sunrpc jbd mbcache ext4 jbd2 crc16"
64# Replace with that line for HP OCMP e.g.
65#DENY_MODS="MPS_Driver_Mapper mps octtldrv tscttl streams kqemu fdomain"
66DENY_MODS="kqemu"
67# Force some modules to be included
68FORCE_MODS=""
69
70LOGFILE=/var/log/mindi.log
71MINDI_CACHE=/var/cache/mindi
72BOOT_MEDIA_MESSAGE="\
73To format and restore all files automatically, type 'nuke' <enter>.\n\
74To restore some/all files interactively, type 'interactive' <enter>.\n\
75To compare the archives with your filesystem, type 'compare' <enter>.\n\
76To boot to a command-line prompt (expert mode), type 'expert' <enter>.\n\
77You may add one or more of the following parameters as well:-\n\n\
78        donteject - mondorestore will not eject the CD; this is useful if, for\n\
79                    instance, your PC's case has a concealed CD-ROM drive\n\
80        noresize  - your mountlist will not be adjusted to use your unallocated\n\
81                    hard disk space\n\
82        textonly  - do not call any Newt library routines; this is unattractive\n\
83                    but valuable if you find your Newt library has bugs in it\n\n\
84e.g. Type 'nuke donteject textonly' if you have an unstable Newt library and \n\
85a PC whose CD-ROM drive tray would be damaged if it unexpectedly ejected.\n\
86"
87FDISK=$MINDI_SBIN/parted2fdisk
88
89# Using a config file allow to overwrite some values
90MINDI_CONFIG="$MINDI_CONF/mindi.conf"
91if [ -f $MINDI_CONFIG ]; then
92    . $MINDI_CONFIG
93fi
94DEPLIST_FILE="$MINDI_CONF/deplist.conf"
95DEPLIST_FILE_MIN="$MINDI_CONF/deplist-minimal.conf"
96DEPLIST_DIR="$MINDI_CONF/deplist.d"
97
98ISO_CMD="/usr/bin/mkisofs"
99ISO_OPT="-J -r -v -p Mindi -publisher http://www.mondorescue.org -A Mindi"
100
101# Now we can create what we need
102MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
103if [ $? -ne 0 ]; then
104    df $TMPDIR
105    Die "Unable to create a temporary directory ! Check space on $TMPDIR"
106fi
107if [ _"$MINDI_TMP" = _"" ]; then
108    Die "MINDI_TMP is empty, aborting"
109fi
110if [ _"$MINDI_TMP" = _"/" ]; then
111    Die "MINDI_TMP is /, aborting"
112fi
113export MINDI_TMP
114
115# ----------------------------------------------------------------------------
116
117
118AbortHere() {
119    [ "$mountpoint" ] && umount $mountpoint 2>> $LOGFILE
120    Die "Program is terminating in response to signal received from OS/user"
121}
122
123
124Aborted() {
125    trap SIGHUP SIGTERM SIGTRAP SIGINT
126    [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
127    [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
128    Die "User abort."
129}
130
131
132AddFileToCfgIfExists() {
133    [ -e "$1" ] && echo -en "$2 `cat $1`\n" >> $3
134}
135
136
137AddKeyboardMappingFile() {
138    local mappath r included_list included_item i res ii sss
139    mappath=$1
140    KBDEPTH=$(($KBDEPTH+1))
141    [ "$KBDEPTH" -gt "128" ] && Die "Edit $MINDI_SBIN/mindi and disable FindAndAddUserKeyboardMappingFile (line 2160, approx.)"
142    if [ -e "$bigdir/$mappath" ] ; then
143        LogFile "$mappath already added" 
144        return
145    elif [ -d "$bigdir/$mappath" ] ; then
146        echo "Cannot add $mappath: it's a directory. Sorry."
147        return
148    fi
149    LogFile "Added kbd map $mappath" 
150    if [ ! -e "$mappath" ] ; then
151            mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
152        if [ ! -e "$mappath" ] ; then
153            LogAll "Cannot add $mappath: kbd map file not found"
154            return
155        fi
156    fi
157
158    mkdir -p $bigdir/etc
159    tar cf - -C / $mappath 2>> $MINDI_TMP/$$.log | (cd $bigdir ; tar xf -) || LogAll "AKMF -- Could not copy $mappath to $bigdir" $MINDI_TMP/$$.log
160    if [ "`echo $mappath | grep -F ".gz"`" ] ; then
161        included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
162    else
163        included_list=`grep -Fi include $mappath | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
164    fi
165    for included_item in $included_list ; do
166        if [ ! -e "$included_item" ] ; then
167                sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
168            [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
169            for ii in $sss ; do
170                [ -e "$ii" ] && AddKeyboardMappingFile $ii
171            done
172        else
173            AddKeyboardMappingFile $included_item
174        fi
175    done
176}
177
178
179CopyDependenciesToDirectory() {
180    local outdir incoming fname counter d found
181    outdir=$1
182    noof_lines=$2
183    mkdir -p $outdir
184    incoming=`ReadLine`
185    progress=0
186    while [ "$incoming" != "" ] ; do
187        # Non absolute file names should not arrive till here => skipped
188        if [ `echo "$incoming" | cut -c1` != '/' ]; then
189            LogAll "Unable to handle $incoming"
190            incoming=`ReadLine`
191            continue
192        fi
193        # no parent directory of incoming should be a link, copy is not possible in that case
194        d=`dirname "$incoming"`
195        found="false"
196        while [ $d != "/" -a $found = "false" ]; do
197            [ -h "$d" ] && found="true"
198            d=`dirname "$d"`
199        done
200        if [ -d "$incoming" ] && [ ! -h "$incoming" ]; then
201            find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir 0
202        elif [ -e "$incoming" ] && [ $found = "false" ]; then
203            tar cf - -C / $incoming 2>> $MINDI_TMP/$$.log | (cd $outdir ; tar xf -) || Die "Cannot copy $incoming to $outdir - did you run out of disk space?" $MINDI_TMP/$$.log
204
205            # Only uncompress modules if not using udevd
206            if [ "`echo "$incoming" | grep "lib/modules/.*\..*o\.gz"`" != "" ] && [ "`ps auxww | grep -v grep | grep -qw udevd`" != "" ]; then
207                gunzip -f $outdir/$incoming || LogAll "Cannot gunzip $outdir/$incoming"
208            fi
209            [ -x "$outdir" ] && StripExecutable $outdir "-$filename-"
210            progress=$(($progress+1))
211            LogProgress $progress $noof_lines
212        fi
213        incoming=`ReadLine`
214    done
215}
216
217
218CountItemsIn() {
219    local r
220    r=0
221    for q in $1 ; do
222        r=$(($r+1))
223    done
224    echo $r
225}
226
227
228# Last function called before exiting
229# Parameter is exit code value
230MindiExit() {
231    local my_partitions
232
233    LogFile "Mindi $MINDI_VERSION is exiting" 
234    LogFile "End date : `date`" 
235    if [ _"$MONDO_SHARE" != _"" ] ; then
236        echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
237        cat $LOGFILE >> /var/log/mondoarchive.log
238        echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
239    fi
240
241    cd /
242    sync&
243
244    # Unmount what could remain mounted
245    my_partitions=`mount | grep -F $$ | cut -f1 -d' '`
246    [ "$my_partitions" != "" ] && umount $my_partitions
247    # Clean temporary files only when standalone mindi
248    if [ _"$MINDI_TMP" != _"$MONDO_TMP" ]; then
249        rm -Rf $MINDI_TMP
250    fi
251    exit $1
252}
253
254Die() {
255    local i
256    if [ "$1" = "" ] ; then
257        LogAll "FATAL ERROR"
258    else
259        LogAll "FATAL ERROR. $1"
260    fi
261    if [ _"$2" != _"" ]; then
262        grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
263    fi
264    rm -f "$2"
265
266    LogAll "Please e-mail a copy of $LOGFILE to the mailing list."
267    LogAll "See http://www.mondorescue.org for more information."
268    LogAll "WE CANNOT HELP unless you enclose that file.\n"
269    MindiExit -1
270}
271
272
273DropOptimizedLibraries() {
274    local outdir filelist list_of_optimized_libraries optimized_lib_name vanilla_lib_name reason msg resolved res progress
275    filelist=$1
276    outdir=$2
277
278    progress=0
279    list_of_optimized_libraries=`grep "lib/i[5-7]86/" $filelist`
280    if [ "$list_of_optimized_libraries" = "" ] ; then
281        return 0
282    else
283        noof_lines=`echo $list_of_optimized_libraries | tr ' ' '\n' | wc -l`
284    fi
285    echo -en "Dropping i686-optimized libraries if appropriate"
286    for optimized_lib_name in $list_of_optimized_libraries ; do
287        reason=""
288        vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
289        echo "$vanilla_lib_name" >> $filelist
290        LogFile "Adding $vanilla_lib_name to filelist" 
291        mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null
292        rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null
293
294        # This may return multiple files
295        for resolved in `ReadAllLink $vanilla_lib_name`; do
296            LogFile "Adding as deps $resolved to filelist" 
297            vanilla_resolved_name=`echo "$resolved" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
298            mkdir -p $outdir$resolved> /dev/null 2> /dev/null
299            rmdir $outdir$resolved > /dev/null 2> /dev/null
300            ln -sf $vanilla_resolved_name $outdir$resolved
301            LogFile "Excluding deps $resolved" 
302            grep -Fvx "$resolved" "$filelist" > $filelist.tmp
303            LogFile "Replacing it with $vanilla_resolved_name" 
304            echo "$vanilla_resolved_name" >> $filelist.tmp
305            mv -f $filelist.tmp $filelist
306        done
307        progress=$(($progress+1))
308        LogProgress $progress $noof_lines
309    done
310    $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
311    mv -f $filelist.tmp $filelist
312    echo -e "$DONE"
313}
314
315
316FindAndAddUserKeyboardMappingFile() {
317    local r res mapfile mappath included_item included_list keyfile mp locale
318    LogFile "Analyzing your keyboard's configuration."
319    KEYDIR=/lib/kbd
320    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd     # Slackware
321    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
322    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
323    [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
324    [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole-setup
325    if [ ! -e "$KEYDIR" ] ; then
326        LogAll "Keyboard mapping directory not found. I shall use default map at boot-time."
327        return 0
328    fi
329    LogFile "Adding the following keyboard mapping tables: "
330    if [ -e "/etc/sysconfig/keyboard" ] ; then
331        LogFile "Red Hat-style config detected." 
332        keyfile=/etc/sysconfig/keyboard
333    elif [ -e "/etc/rc.d/rc.keymap" ] ; then
334        LogFile "Slackware-style config detected." 
335        keyfile=/etc/rc.d/rc.keymap
336    elif [ -e "/etc/rc.config" ] ; then
337        LogFile "Debian-style config detected." 
338        keyfile=/etc/rc.config
339    elif [ -e "/etc/console/boottime.kmap.gz" ] ; then
340        LogFile "Debian-style config detected." 
341        mkdir -p $bigdir/tmp
342        echo "/etc/console/boottime.kmap.gz" > $bigdir/tmp/KEYMAP-LIVES-HERE
343        KBDEPTH=0
344        mkdir -p $bigdir/etc/console
345        cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
346        echo -e "$DONE"
347        return 0
348    elif [ -e "/etc/console-setup/boottime.kmap.gz" ] ; then
349        LogFile "Ubuntu-style config detected." 
350        mkdir -p $bigdir/tmp
351        echo "/etc/console-setup/boottime.kmap.gz" > $bigdir/tmp/KEYMAP-LIVES-HERE
352        KBDEPTH=0
353        mkdir -p $bigdir/etc/console-setup
354        cp /etc/console-setup/boottime.kmap.gz $bigdir/etc/console-setup 2>> $LOGFILE
355        echo -e "$DONE"
356        return 0
357    elif [ -e "/etc/conf.d/keymaps" ] ; then
358        LogFile "Gentoo-style config detected." 
359        keyfile=/etc/conf.d/keymaps
360    else
361        LogAll "Searching for rc.config ..."
362        keyfile=`find /etc -name rc.config | head -n1`
363        if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
364            LogAll "Unknown config detected. Default keyboard map will be used."
365            return
366        else
367            LogFile "Found $keyfile" 
368        fi
369    fi
370    if [ ! -e "$KEYDIR/keymaps" ] ; then
371        LogAll "Keyboard mapping directory not found. Default keyboard map will be used."
372        return
373    fi
374    LogFile "keyfile=$keyfile" 
375    locale=`grep -F KEYTABLE "$keyfile" | tr -d '"' |cut -d'=' -f2`
376    [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'`        # Slackware
377    [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | tr -d '"' |cut -d'=' -f2`        # Gentoo
378    LogFile "locale=$locale" 
379    #
380    # Process the keymaps dir once for all
381    # AddKeyboardMappingFile will use it recursively
382    #
383    find $KEYDIR/keymaps > $MINDI_TMP/keymaps.find
384    mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep -F "/${locale}." | grep -vx " *#.*"`
385    [ ! "$mp" ] && mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
386    # If we have multiple keymaps then log it !!
387    echo "$mp" | grep -q " " >> $LOGFILE
388    if [ $? -eq 0 ]; then
389        LogAll "WARNING: Multiple keymaps found: $mp" 
390        LogFile "The following one will be used" 
391    fi
392    for i in $mp ; do
393        mappath=$i
394        [ -e "$i" ] && [ ! -d "$i" ] && break
395    done
396    if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
397            mappath=$(find / -name "*/kbd/keymaps/*/$locale")
398    fi
399    LogFile "mappath = $mappath" 
400    if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
401        LogAll "Keyboard mapping file not found. Default keyboard map will be used."
402        return
403    fi
404    mkdir -p $bigdir/tmp
405    echo "$mappath" > $bigdir/tmp/KEYMAP-LIVES-HERE
406    KBDEPTH=0
407    AddKeyboardMappingFile $mappath
408    echo -e "$DONE"
409    rm -f $MINDI_TMP/keymaps.find
410    return 0
411}
412
413
414FindIsolinuxBinary() {
415    ISOLINUX=/usr/lib/isolinux.bin
416    [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
417    [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
418    [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
419    [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
420    [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
421    [ ! -e "$ISOLINUX" ] && ISOLINUX=`find / -name isolinux.bin | grep -x "/.*/isolinux.bin"`
422    [ ! -e "$ISOLINUX" ] && Die "Please install isolinux first. If your syslinux RPM doesn't include isolinux, you may download an isolinux RPM from Mondo's website - go to http://www.mondorescue.com and click on 'Download'"
423    LogFile "Found isolinux.bin at $ISOLINUX" 
424}
425
426
427FindSpecificModuleInPath() {
428    local modpaths pwd line
429    pwd=`pwd`
430    if [ "$YOUR_KERNEL_SUCKS" ] ; then
431        cd $MINDI_TMP
432    else
433        cd /
434    fi
435    if [ ! -e "$1" ] ; then
436        LogAll "WARNING - cannot search specific path '$1'"
437        return 1
438    fi
439    modpaths=`find $1 -name $2.*o -type f`
440    #[ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"
441    [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
442    [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
443    [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
444    echo "$modpaths"
445    cd $pwd
446}
447
448
449GenerateGiantDependencyList() {
450    local incoming loc fname list_of_files i tempfile outfile progress filelist res r mapfile mappath included_list included_item old_pwd tempdepfile modres noof_lines lvmversion lvmresolved
451
452    echo -en "Analyzing dependency requirements"
453    outfile=$1
454    tempfile=$MINDI_TMP/$$.txt
455    incoming=`ReadLine`
456
457    > $tempfile
458    progress=0
459    res=0
460    noof_lines=$2
461    while [ "$incoming" != "" ] ; do
462        if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
463            incoming=`ReadLine`
464            continue
465        fi
466        if [ "$incoming" = "LVMFILES:" ] ; then
467            break
468        fi
469        filelist=`GenerateListForFile "$incoming"`
470        r=$?
471        [ "$r" -ne "0" ] && LogAll "$incoming not found"
472        res=$(($res+$r))
473#       LogFile "'$incoming' generates filelist '$filelist'"
474        for fname in $filelist ; do
475            [ "$fname" != "" ] && echo "$fname" >> $tempfile
476        done
477        progress=$(($progress+1))
478        LogProgress $progress $noof_lines
479        incoming=`ReadLine`
480    done
481    if  [ "$incoming" = "LVMFILES:" ] ; then
482        incoming=`ReadLine`
483        lvmversion=""
484        while [ "$incoming" != "" ] ; do
485            if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
486                incoming=`ReadLine`
487                continue
488            fi
489            filelist=`GenerateListForFile "$incoming"`
490            for tool in $filelist ; do
491                lvmresolved=`readlink -f $tool`
492                if [ "$tool" = "$lvmresolved" ]; then
493                    echo "$tool" >> $tempfile
494                elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
495                    if [ "$lvmversion" = "" ] ; then
496                        lvmversion=`$lvmresolved`
497                        echo "$lvmresolved" >> $tempfile
498                    fi
499                    toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
500                    if [ "$lvmversion" = "200" ]; then
501                        # pvdata and lvmcreate_initrd don't exist in LVM2
502                        case "$toolstripped" in
503                        "pvdata")
504                            continue
505                            ;;
506                        "lvmcreate_initrd")
507                            continue
508                            ;;
509                        esac
510                    fi
511                    toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
512                    if [ -e "$toolpath" ] ; then
513                        echo "$toolpath" >> $tempfile
514                        echo "$tool" >> $tempfile
515                    else
516                        toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
517                    fi
518                    if [ -e "$toolpath" ] ; then
519                        echo "$toolpath" >> $tempfile
520                        echo "$tool" >> $tempfile
521                    else
522                        echo "Where are your LVM-Tools? Couldn't find $tool"
523                    fi
524                else
525                    echo "$tool" >> $tempfile
526                fi
527            done
528            progress=$(($progress+1))
529            LogProgress $progress $noof_lines
530            incoming=`ReadLine`
531        done
532    fi
533    echo -en "$DONE\nMaking complete dependency list"
534
535    tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
536    mv -f $tempfile.new $tempfile
537    > $outfile.pre
538    progress=0
539    noof_lines=`cat $tempfile | wc -l`
540    LogFile "---------------------------------" 
541    LogFile "List of dependencies:             " 
542    LogFile "---------------------------------" 
543    for fname in `cat $tempfile` ; do
544        echo "$fname" | tee -a $LOGFILE >> $outfile.pre
545        LocateDeps $fname | tee -a $LOGFILE >> $outfile.pre
546        progress=$(($progress+1))
547        LogProgress $progress $noof_lines
548    done
549    if [ _"$MONDO_SHARE" != _"" ]; then
550        mkdir -p $bigdir/tmp
551        mkdir -p $bigdir/sbin
552        mkdir -p $bigdir/bin
553        if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
554            LogAll "\nIncorporating post-nuke tarball"
555            old_pwd=`pwd`
556            cd $bigdir
557            tar -zxf $MINDI_TMP/post-nuke.tgz 2>> $MINDI_TMP/$$.log || LogAll "Error occurred when untarring post-nuke tarball" $MINDI_TMP/$$.log
558            cd $old_pwd
559        fi
560        cp -f $MINDI_TMP/BOOTLOADER.* $bigdir 2>> $LOGFILE || LogAll "\nMondo v1.2x defaults to LILO as the bootloader, BTW."
561        if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
562            LogAll "\nIncorporating NFS-related settings"
563            for r in NETFS-* ; do
564                cp -f $MINDI_TMP/$r $bigdir/tmp 2>> $LOGFILE || Die "Cannot copy $r - did you run out of disk space?"
565                LogFile "Copying $r to ramdisk" 
566            done
567        fi
568    fi
569    tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
570    rm -f $tempfile $outfile.pre
571    [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
572    return $res
573}
574
575
576GenerateListForFile() {
577    local files_found loc fname incoming i res
578    incoming="$1"
579    files_found=""
580    res=0
581
582    for fname in $incoming ; do
583        files_found="$files_found `LocateFile $fname`"
584    done
585
586    echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
587}
588
589
590# Returns all disk devices which are part of a raid array
591GetAllRaidMembers() {
592    $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
593}
594
595
596GetFileSizeList() {
597    local i
598    for i in `find $1 -type d -o -print` ; do
599        du -sk $i
600    done
601}
602
603
604GetHomeDir() {
605    local res loc
606    loc=`which $1 2>/dev/null`
607    res=`file $loc | $AWK '{print $NF;}'`
608    dirname $res
609}
610
611
612# Check kernel filesystem capabilites for accessing initrd image
613# Could be ext2 FS (old mode) or initramfs (new mode)
614#
615# Interface definition:
616# param #1: absolute path to kernel image
617GetInitrdFilesystemToUse() {
618
619    # interface test: make sure we have one parameter
620    if [ $# -ne 1 ]; then
621        Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
622    fi
623
624    # interface parameters
625    local lvKernelImage=$1
626
627    # local constants (filesystem magic strings)
628    local lcMagicCramfs="<3>cramfs: wrong magic"
629    local lcMagicExt2fs="EXT2-fs: blocksize too small for device."
630    local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device."
631    local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs...|<6>Trying to unpack rootfs image as
632initramfs"
633
634    # local variables
635    local lvOffset
636    local lvScanRes
637    local lvUseFilesystem
638
639    # say where we are.
640    LogFile "  GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n" 
641
642    # verify that file exists
643    [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
644
645    # Kernel may be gzip compressed
646    file $lvKernelImage 2>&1 | grep -q gzip
647    if [ $? -eq 0 ]; then
648        lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicExt3fs|$lcMagicInitfs"`
649
650        # determine which filesystem to use for initrd image: ext2|3fs, gzip'ed cpio (initramfs) or cramfs
651        if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then
652            lvUseFilesystem="ext2fs"
653        elif [ `echo $lvScanRes | grep -Ec "$lcMagicExt3fs"` -eq 1 ]; then
654            lvUseFilesystem="ext3fs"
655        elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then
656            lvUseFilesystem="initramfs"
657        elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then
658            lvUseFilesystem="cramfs"
659        else
660            lvUseFilesystem="UNSUPPORTED"
661        fi
662
663    else
664        # In that case, we are after 2.6.30 and use the supported initramfs
665        lvUseFilesystem="initramfs"
666    fi
667    # say what we are using
668    LogFile "  GetInitrdFilesystemToUse(): Filesytem to use for initial ramdisk is $lvUseFilesystem.\n" 
669
670    # return file system to use
671    echo "$lvUseFilesystem"
672
673}
674
675# Searches parent raid device of given disk device
676# $1: disk device (i.e. /dev/hda1)
677GetParentRaidDev() {
678    $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
679}
680
681
682# Searches members of raid device
683# $1: raid device (/dev/md...)
684GetRaidDevMembers() {
685    $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
686}
687
688
689HackPathsToFailsafe() {
690    local incoming newpath stub i pwd
691    incoming=`ReadLine`
692    pwd=`pwd`
693    cd $MINDI_TMP
694    while [ "$incoming" != "" ] ; do
695        stub=`basename $incoming`
696        newpath=`FindSpecificModuleInPath lib/modules/$FAILSAFE_KVER $stub`
697        for i in $newpath ; do
698            echo "$i"
699        done
700        read incoming
701    done
702    cd $pwd
703}
704
705
706ListAllPartitions() {
707    local res currline partition all_partitions ap_orig remaining i j
708
709    grep -Evx " *#.*| *none.*" $MY_FSTAB | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/\/fdd|\/cdr|\/zip|\/floppy/ {print $1}'
710    [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
711    if [ -e "/vmfs/volumes" ]; then
712        # For VMWare ESX 3 get the device names of these volumes
713        vdf -P | grep -E '/vmfs/volumes' | $AWK '{print $1}'
714    fi
715    return
716}
717
718
719ListImagesForUser() {
720    local path fname
721    path=$MINDI_CACHE
722    echo -en "In the directory '$path' you will find the images:-\n"
723    for fname in `ls $path | grep -F mindi-` ; do
724        printf "%19s " $fname
725    done
726    echo " "
727}
728
729
730ListKernelModulePaths() {
731    local module_list module fname oss r kern
732    outfile=$1
733    echo -en "Analyzing modules requirements"
734    oss="/root/oss/modules"
735    module_list="$MODULES"
736    # Remove unwanted modules from list
737    for i in $DENY_MODS; do
738        module_list=`echo ${module_list} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
739        EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
740    done
741###
742### Sq-Modification ... Use kernelname for module search path if specified
743###
744    if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]
745    then
746        kern=${kernelname}
747    else
748        kern="$KERVERRUN"
749    fi
750    export KERVER=$kern
751###
752### Sq-Mod End
753###
754    noof_lines=0
755    for module in $module_list $EXTRA_MODS ; do
756        noof_lines=$(($noof_lines+1))
757    done
758    progress=0
759    for module in $module_list $EXTRA_MODS ; do
760        r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
761        LogFile "module $module --> $r" 
762        [ "$r" ] && echo "$r" >> $outfile
763        [ -f "$oss" ] && find $oss | grep -F $module >> $outfile
764        progress=$(($progress+1))
765        LogProgress $progress $noof_lines
766    done
767    find /lib/modules/$kern/modules.* -type f 2> /dev/null >> $outfile
768    [ -f "$oss" ] && find $oss.* 2> /dev/null >> $outfile
769}
770
771#
772# Critical function which computes all dependencies (dyn. lib.)
773# for a list of binaries
774#
775LocateDeps() {
776    local incoming fname deps
777    incoming="$*"
778    for fname in $incoming ; do
779        if [ ! -e "$fname" ] ; then
780            LogFile "WARNING - $fname does not exist; cannot be LDD'd." 
781            if echo $fname | grep lvm &> /dev/null ; then
782                LogFile "This warning only affects you if you are using LVM." 
783                if echo "$MODULES" | grep lvm &> /dev/null ; then
784                    LogFile "I think you are, so please take heed!" 
785                else
786                    LogFile "I don't think you are, so don't worry about it." 
787                fi
788            fi
789        elif [ -h "$fname" ] && [ -x "$fname" ] ; then
790            LogFile "$fname is softlink" 
791        else
792            ldd $fname 2> /dev/null | ProcessLDD
793        fi
794    done
795}
796
797
798# Give all symlinks recursively of a full path name
799ReadAllLink() {
800
801    incoming="$*"
802
803    for file in $incoming ; do
804        echo "$file"
805        if [ ! -h $file ]; then
806            continue
807        fi
808   
809        link=`readlink -e $file`
810        d=`dirname $file`
811        fchar=`echo $link | cut -c1`
812        # If mother dir is a link print it
813        if [ -h "$d" ]; then
814            echo "$d"
815            d=`readlink -e $d`
816        fi
817        if [ "$fchar" != "/" ]; then
818            # Relative or local link
819            ReadAllLink "$d/$link" 
820        else
821            # Absolute path
822            ReadAllLink $link 
823        fi
824    done
825}
826
827
828LocateFile() {
829    local i path fname_to_find location output resolved tmp stub cache_id loclist
830    fname_to_find="$1"
831    # It's an absolute path
832    if echo "$fname_to_find" | grep -x "/.*" ; then
833        output="$fname_to_find"
834        if [ -h "$output" ] ; then
835            output="`ReadAllLink $output` $output"
836        fi
837        echo "$output"
838        return 0
839    fi
840    # It's not an absolute path
841    output=""
842    for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin `find /usr/lib /lib /usr/local/lib /usr/X11R6/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/X11R6/lib64 -type d -maxdepth 1 2> /dev/null` ; do
843    #for path in /etc /usr /usr/bin /usr/sbin /bin /usr/X11R6/bin /sbin /usr/local/bin /usr/local/sbin /usr/lib /usr/lib64 /usr/lib64/* /lib /lib64 /lib64/* /usr/local/lib /usr/local/lib64 /usr/local/lib64/* /usr/X11R6/lib /usr/X11R6/lib64 /usr/X11R6/lib64/* ; do
844        [ -h "$path" ] && continue
845        [ ! -e "$path/$fname_to_find" ] && continue
846        output="$path/$fname_to_find $output"
847        if [ -h "$path/$fname_to_find" ] ; then
848            output="`ReadAllLink $path/$fname_to_find` $output"
849        fi
850    done
851    if [ "$output" = "" ] ; then
852        return 1
853    fi
854    echo "$output"
855    return 0
856}
857
858LogProgress() {
859    local i progress modres noof_lines
860 
861    progress=$1
862    noof_lines=$2
863
864    echo -en "\r\t\t\t\t\t\t\t\t"
865    i=$(($progress*100))
866    i=$(($i/$noof_lines))
867    echo -en "$i"
868    echo -en "%"
869    modres=$(($progress%4))
870    [ "$modres" -eq "0" ] && echo -en "\t/"
871    [ "$modres" -eq "1" ] && echo -en "\t-"
872    [ "$modres" -eq "2" ] && echo -en "\t\\"
873    [ "$modres" -eq "3" ] && echo -en "\t|"
874}
875
876# Function to log on screen only
877LogScreen() {
878    if [ -e /dev/stderr ] ; then
879        echo -e "$1" >> /dev/stderr
880    elif [ -e /usr/bin/logger ] ; then
881        /usr/bin/logger -s $1
882    fi
883}
884
885# Function to log in log file only
886LogFile() {
887
888    echo -e "$1" >> $LOGFILE
889    if [ _"$2" != _"" ]; then
890        grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
891    fi
892    rm -f "$2"
893}
894
895# Function to log in both screen and logfile
896LogAll() {
897    LogScreen "$1"
898    LogFile "$1" "$2"
899}
900
901
902# Called by TurnTgzIntoRdz, to make /tmp/mondo-restore.cfg
903MakeMondoConfigFile() {
904    local outfile use_lzo use_comp use_star
905    outfile=$1
906    > $outfile
907    [ "$TAPESIZE" ]     && echo "media-size $TAPESIZE" >> $outfile
908    [ "$TAPEDEV" ]          && echo "media-dev $TAPEDEV" >> $outfile
909    [ "$USBDEVICE" ]            && echo "usb-dev $USBDEVICE" >> $outfile
910    [ "$FILES_IN_FILELIST" ]    && echo "files-in-filelist $FILES_IN_FILELIST" >> $outfile
911    [ "$LAST_FILELIST_NUMBER" ] && echo "last-filelist-number $LAST_FILELIST_NUMBER" >> $outfile
912    [ "$INTERNAL_TAPE_BLOCK_SIZE" ] && echo "internal-tape-block-size $INTERNAL_TAPE_BLOCK_SIZE" >> $outfile
913    use_lzo=$USE_LZO; [ "$use_lzo" = "" ] && use_lzo="no"
914    use_gzip=$USE_GZIP; [ "$use_gzip" = "" ] && use_gzip="no"
915    use_lzma=$USE_LZMA; [ "$use_lzma" = "" ] && use_lzma="no"
916    use_comp=$USE_COMP; [ "$use_comp" = "" ] && use_comp="yes"
917    use_star=$USE_STAR; [ "$use_star" = "" ] && use_star="no"
918    echo "use-lzo $use_lzo" >> $outfile
919    echo "use-lzma $use_lzma" >> $outfile
920    echo "use-star $use_star" >> $outfile
921    echo "use-comp $use_comp" >> $outfile
922    echo "datestamp `date`" >> $outfile
923    [ "$ESTIMATED_TOTAL_NOOF_SLICES" ] && echo "total-slices $ESTIMATED_TOTAL_NOOF_SLICES" >> $outfile
924    AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-MOUNT  netfs-server-mount  $outfile
925    AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-PATH   netfs-server-path   $outfile
926    AddFileToCfgIfExists $MINDI_TMP/NETFS-DEV           netfs-dev           $outfile
927    AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
928    AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME   bootloader.name   $outfile
929    AddFileToCfgIfExists $MINDI_TMP/KEYMAP-LIVES-HERE keymap-lives-here $outfile
930    AddFileToCfgIfExists $MINDI_TMP/TAPEDEV-HAS-DATA-DISKS tapedev-has-data-disks $outfile
931}
932
933
934MakeMountlist() {
935    local scratchdir mountlist all_partitions current_partition \
936partition_size partition_format outstring partition_number \
937partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
938absolute_partition old_partition_fmt current_lvolume uname skip
939
940    LogFile "------------------------------------" 
941    LogFile "Your raw fstab file looks like this:" 
942    LogFile "------------------------------------" 
943    cat $MY_FSTAB >> $LOGFILE
944    LogAll "-----------------------------------" 
945    LogAll "Your mountlist will look like this:" 
946    LogAll "-----------------------------------" 
947
948# scratchdir, mountlist(OUT)
949    scratchdir=$MINDI_TMP
950    mountlist=$1
951
952# NB: partition = device
953# NB: mountpt = where the device is mounted
954
955    [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
956
957    [ "$mountlist" != "" ] && rm -Rf $mountlist
958    > $mountlist
959    all_partitions=""
960   
961    if [ $LVM != "false" ]; then
962        LogFile "Analyzing LVM..."
963        $MINDI_LIB/analyze-my-lvm > $MINDI_TMP/lvm.res
964        if [ $? -ne 0 ]; then
965            LVM="false"
966        fi
967        all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
968    fi
969    all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
970#    echo "all partitions = $all_partitions" > /dev/stderr
971    for i in $IMAGE_DEVS ; do
972        mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
973    done
974    [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
975    printf "%-15s %-15s %-15s %-15s %15s\n" DEVICE MOUNTPOINT FORMAT "SIZE MB" LABEL/UUID | tee -a $LOGFILE
976    printf "%-15s %-15s %-15s %-15s %15s\n" ------ ---------- ------  -------  ---------- | tee -a $LOGFILE
977    useless_dev="/dev/floppy /dev/fd0h1440 /dev/fd0H1440 /dev/cdrom /dev/cdrom/cdrom /dev/cdrom/cdrom1 /dev/cdrom/cdrom2 /dev/cdrom0 /dev/cdrom1 /dev/cdrom2 /dev/cdrom3 /dev/cdrw /dev/scd /dev/ram :/ /dev/sr0 /dev/sr1 /dev/cdrom1"
978    for c_p in $all_partitions ; do
979        [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] && continue
980        [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
981        if [ -h "$c_p" ] && [ "`echo "$c_p" | grep -F "/dev/hd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/sd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/md"`" = "" ] ; then
982            current_partition=`readlink -f $c_p`
983            [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
984            [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
985        else
986            current_partition="$c_p"
987        fi
988        [ "$c_p" = "none" ] && continue
989        # Debian 5 does that
990        [ "$c_p" = "proc" ] && continue
991        redhat_label=""
992        label=""
993        uuid=""
994        absolute_partition=`readlink -f $c_p`
995        partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
996
997        # Detects noauto partitions not mounted and exclude them
998        partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
999        if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" =  "" ] ; then
1000            continue
1001        fi
1002
1003        # set default in case we dont't find it
1004        str_to_find_fmt_with=$current_partition
1005
1006        # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1007        # current_partition contains only first column of /etc/fstab
1008        if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
1009            redhat_label=`echo "$current_partition" | cut -d'=' -f2`
1010            actual_dev=""
1011
1012            # 1st try, findfs - the RHEL way of finding labels and their partitions
1013            if [ -x "/sbin/findfs" ]; then
1014                actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
1015            fi
1016   
1017            # 2nd try : blkid, the good way for all LABEL except swap
1018            if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1019                actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
1020                # For LVM FS it will give a /dev/dm-# which should then be converted
1021                if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1022                    major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1023                    minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1024                    for dev in `ls /dev/mapper/*`; do
1025                        major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1026                        minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1027                        if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1028                            actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1029                            break
1030                        fi
1031                    done
1032                fi
1033            fi
1034   
1035            # 3rd try, which works on a standard partition (ext2/3), but not on swap
1036            # For LVM gives a /dev/mapper entry
1037            if [ "x$actual_dev" = "x" ]; then
1038                actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
1039            fi
1040   
1041            # 4th try, with vol_id
1042            # SWAP only
1043            if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1044                list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
1045                for dev_swap in $list_swaps ; do
1046                    dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1047                    if [ "x$dev_exists" != "x" ]; then
1048                        actual_dev=$dev_swap
1049                        break;
1050                    fi
1051                done
1052            fi
1053
1054            # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
1055            # LABEL=SW-cciss/c0d0p3 (RDP)
1056            # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
1057            # SWAP only
1058            if [ "x$actual_dev" = "x" -a  _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
1059                    skip=""
1060                    uname=$KERVERRUN
1061                    [ "`echo $uname | grep "2.4.[0-9]"`" != "" ] && skip=16
1062                    # 2.6.12 needs 16 (FC3)
1063                    [ "`echo $uname | grep "2.6.[0-1]"`" != "" ] && skip=16
1064                    # 2.6.19 and upper needs 1052
1065                    [ "`echo $uname | grep "2.6.19"`" != "" ] && skip=1052
1066                    [ "`echo $uname | grep "2.6.[2-9]"`" != "" ] && skip=1052
1067                    if [ $skip = "" ]; then
1068                        Die "Your kernel is too old. I don't know how to support labelled swap spaces with it"
1069                    fi
1070                    for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1071                    do
1072                        # Location of the swap label for kernel 2.6
1073                        try_dev_label=`dd bs=1 count=16 skip=$skip if=$try_dev 2> /dev/null`
1074                        if [ "x$try_dev_label" = "x$redhat_label" ]; then
1075                            actual_dev=$try_dev
1076                        fi
1077                    done
1078            fi
1079
1080            # Check if one of all those tries has known success
1081            if [ "x$actual_dev" != "x" ]; then
1082                current_partition=$actual_dev
1083            else
1084                Die "Your system uses a LABEL partition ($current_partition), but you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or install findfs|blkid|vol_id"
1085            fi
1086        # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1087        # current_partition contains only first column of /etc/fstab
1088        elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
1089            uuid=`echo "$current_partition" | cut -d'=' -f2`
1090            actual_dev=""
1091
1092            # 1st try, findfs - the RHEL way of finding labels and their partitions
1093            if [ -x "/sbin/findfs" ]; then
1094                actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1095            fi
1096   
1097            # 2nd try : blkid, the good way for all UUID except swap
1098            if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1099                actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
1100                # For LVM FS it will give a /dev/dm-# which should then be converted
1101                if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1102                    major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1103                    minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1104                    for dev in `ls /dev/mapper/*`; do
1105                        major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1106                        minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1107                        if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1108                            actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1109                            break
1110                        fi
1111                    done
1112                fi
1113            fi
1114   
1115            # 3th try, with vol_id
1116            if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1117                list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1118                for dev in $list_dev ; do
1119                    dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1120                    if [ "x$dev_exists" != "x" ]; then
1121                        actual_dev=$dev
1122                        break;
1123                    fi
1124                done
1125            fi
1126
1127            # 4th try, with dumpuuid (VMWare only ?) for swap
1128            if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1129                list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1130                for dev in $list_dev ; do
1131                    dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1132                    if [ "x$dev_exists" != "x" ]; then
1133                        actual_dev=$dev
1134                        break;
1135                    fi
1136                done
1137            fi
1138
1139            # Check if one of all those tries has known success
1140            if [ "x$actual_dev" != "x" ]; then
1141                current_partition=$actual_dev
1142            else
1143                Die "Your system uses a UUID partition ($current_partition),\nbut you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or\ninstall findfs|blkid|vol_id or\nrelabel the partition with the correct UUID if it's a swap partition."
1144            fi
1145        else
1146            # Needs to handle the recent OpenSUSE fancy way of dealing with fstab :-(
1147            # they use symlinks in fstab unrelated to what is shown in mount !
1148            if [ _"$partition_mountpt" = _"" ]; then
1149                # set default in case we dont't find it
1150                for tmpp in `tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -Ev "^#" | $AWK '{print $1}'`; do
1151                        if [ _"`readlink -f $tmpp`" = _"$current_partition" ]; then
1152                            str_to_find_fmt_with=$tmpp
1153                            partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$tmpp" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1154                            break;
1155                        fi
1156                done
1157            fi
1158        fi
1159
1160        partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1161        # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1162        # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1163        # the former is then a link to the latter, so we test whether
1164        # $current_partition is actually such a link or not and set
1165        # $current_lvolume accordingly. On Debian you may find more than one answer
1166        # so we remove the one corresponding to /dev/.static
1167        # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1168        # principle is the same and we need to find the link to it as well.
1169        # Note that $current_lvolume may well be an
1170        # ordinary device. It is just to make sure that we feed the right value
1171        # into any of the LVM tools if possible.
1172
1173        current_lvolume="$current_partition"
1174        if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
1175            # .static dir are a Debian specificity
1176            current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
1177            echo $current_lvolume | grep -q ' '
1178            if [ $? -eq 0 ]; then
1179                LogFile "WARNING: Multiple Logical Volumes found. Report to dev team" 
1180            fi
1181            # if it's not found, it may well be a real device such as a multipath one
1182            # /dev/mapper/mpath... Thus we revert the situation so that next test succeed
1183            if [ _"$current_lvolume" = _"" ]; then
1184                current_lvolume="$current_partition"
1185            fi
1186        fi
1187        #
1188        # End of LVM device style variation code (other than $current_lvolume).
1189
1190        if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1191            # Size computed via LVM not directly
1192            partition_size="lvm"
1193        else
1194            partition_size=`SizeOfPartition $current_partition`
1195            [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1196            [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1197            if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1198                partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1199                [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1200                [ "$partition_format" != "swap" ] && partition_format="swap"
1201                if [ "$partition_size" = "" ] ; then
1202                    totalsize=0
1203                    items=0
1204                    for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1205                        totalsize=$(($totalsize+$i))
1206                        items=$(($items+1))
1207                    done
1208                    [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1209                    [ "$partition_size" -lt "125000" ] && partition_size=125000
1210                    LogFile "I'm guessing $c_p is $(($partition_size/1024))MB" 
1211                fi
1212            fi
1213        fi
1214        [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1215        [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1216        if [ "$partition_mountpt" = "" ] ; then
1217            if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1218                if  [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1219                    partition_mountpt="raid"
1220                    partition_format="raid"
1221                else
1222                    partition_mountpt="lvm"
1223                    partition_format="lvm"
1224                fi
1225            fi
1226        fi
1227        psz=$partition_size
1228        LogFile "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)" 
1229        [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1230        if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1231            partition_mountpt="image"
1232            old_partition_fmt=$partition_format
1233            partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1234            partition_size=$(($partition_size+1)); # just in case
1235            if [ "$partition_format" = "Linux" ] ; then
1236                LogFile "Are you imaging a mounted swap partition? Silly..." 
1237                LogFile "Reverting format from $old_partition_fmt to $partition_format" 
1238                partition_format=$old_partition_fmt
1239            fi
1240        fi
1241        if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then
1242            LogFile "Excluding $current_partition from mountlist" 
1243            continue
1244        fi
1245        if [ ! "$partition_mountpt" ] ; then
1246            LogFile "------- $FDISK -l $qq log ------------" 
1247            for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
1248                partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1249                [ "$partition_format" ] && break
1250            done
1251            LogFile "------- $FDISK log end ------------" 
1252            if [ "$partition_format" = "Compaq diagnostics" ] ; then
1253                partition_format="compaq"
1254            elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1255                LogAll "Unable to find mountpoint of $current_partition - ignoring"
1256                continue
1257            fi
1258        fi
1259        if [ "$redhat_label" ]; then
1260            label="$redhat_label"
1261        elif [ "$uuid" ]; then
1262            label="$uuid"
1263        fi
1264        partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
1265        [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
1266        unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
1267        if [ "$current_partition" = "" ] ; then
1268            LogFile "Unknown partition (outstring = $unofficial_outstring)" 
1269        elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1270            if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1271                partition_mountpt=raid
1272                partition_format=raid
1273                printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1274                printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1275            else
1276                LogFile "Unknown mountpoint (outstring = $unofficial_outstring)" 
1277            fi
1278        elif [ "$partition_format" = "" ] ; then
1279            LogFile "Unknown format (outstring = $unofficial_outstring)" 
1280        elif [ "$partition_size" = "" ] ; then
1281            LogFile "Unknown partition size (outstring = $unofficial_outstring)" 
1282        elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1283            continue
1284        else
1285            if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1286                LogFile "vfat should be used instead of dos/msdos as a partition format"
1287                partition_format="vfat"
1288            fi
1289            printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1290            printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1291        fi
1292    done
1293    LogAll "-----------------------------------" 
1294}
1295
1296CheckMountlist() {
1297    local file=$1
1298    # Coherency verification
1299    ML0=`cat $file | wc -l`
1300    ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
1301    ML2=`$AWK '{print $2}' $file | sort -u | wc -l`
1302    if [ "$ML0" -ne "$ML1" ]; then
1303        LogFile "--------------------------------------------"
1304        echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE
1305        LogFile "--------------------------------------------"
1306    fi
1307    if [ "$ML0" -ne "$ML2" ]; then
1308        LogFile "--------------------------------------------"
1309        echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE
1310        LogFile "------------------------------------------------"
1311    fi
1312}
1313
1314MakeSureNumberIsInteger() {
1315    res=`echo "$1" | tr -s '\-[0-9]' ' '`
1316    if [ "$res" != " " ] && [ "$res" != "" ] ; then
1317    echo "result = '$res'"
1318        Die "$1 should be an integer"
1319    fi
1320}
1321
1322
1323OfferToMakeBootableISO() {
1324    local i old_pwd
1325    if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1326        echo -en "Shall I make a bootable CD image? (y/[n]) "
1327        read i
1328        [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1329    fi
1330    rm -Rf $MINDI_TMP/iso
1331    mkdir -p $MINDI_TMP/iso/{images,archives}
1332    cp -f $MINDI_CACHE/{*.gz,*.img} $MINDI_TMP/iso/images 2>> $LOGFILE || LogAll "OfferToMakeBootableISO: Cannot copy $MINDI_CACHE/*.gz to $MINDI_TMP/iso/images"
1333    LogFile "mindi_lib = $MINDI_LIB" 
1334    for i in memdisk memtest.bin memtest.img ; do
1335        j=$MINDI_LIB/$i
1336        k=$MINDI_TMP/iso
1337        if [ -e "$j" ] ; then
1338            LogAll "Copying $j to $k"
1339            cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1340            cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1341            if [ _"$MONDO_SHARE" != _"" ]; then 
1342                cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1343            fi
1344        fi
1345    done
1346    MakeMessageFile > $MINDI_TMP/iso/message.txt
1347    cp $kernelpath $MINDI_TMP/iso/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/iso/vmlinuz). Did you run out of disk space?"
1348    cp $MINDI_TMP/initrd.img $MINDI_TMP/iso/initrd.img 2>> $LOGFILE || Die "Cannot copy initrd.img ($MINDI_TMP/initrd.img) to $MINDI_TMP/iso/initrd.img. Did you run out of disk space?"
1349    if [ _"$MONDO_SHARE" != _"" ]; then 
1350        cp $kernelpath $MONDO_ROOT/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
1351        cp $MINDI_TMP/initrd.img $MONDO_ROOT/initrd.img 2>> $LOGFILE || Die "Cannot copy initrd.img ($MINDI_TMP/initrd.img) to $MONDO_ROOT/initrd.img. Did you run out of disk space?"
1352    fi
1353    MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
1354    if [ "$ARCH" != "ia64" ] ; then
1355        cp $ISOLINUX $MINDI_TMP/iso/isolinux.bin 2>> $LOGFILE || Die "Cannot copy isolinux.bin ($ISOLINUX) to $MINDI_TMP/iso - did you run out of disk space?"
1356    fi
1357    old_pwd=`pwd`
1358    cd $MINDI_TMP/iso
1359    if [ "$ARCH" != "ia64" ] ; then
1360        if [ _"$MONDO_SHARE" != _"" ]; then 
1361            cp -f $MINDI_TMP/iso/{isolinux.cfg,initrd.img,vmlinuz,isolinux.bin,message.txt} $MONDO_ROOT 2>> $LOGFILE || Die "Cannot copy core files to ramdisk for boot disk (under $MONDO_ROOT). Did you run out of disk space?"
1362            cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
1363        fi
1364        $ISO_CMD -U $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . > /dev/null 2> $MINDI_TMP/mkisofs.log
1365    else
1366        $ISO_CMD $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b images/mindi-bootroot.$BOOT_SIZE.img -c images/boot.cat -no-emul-boot . > /dev/null 2> $MINDI_TMP/mkisofs.log
1367        rm -f images/mindi-bootroot.$BOOT_SIZE.img
1368    fi
1369    if [ "$?" -ne "0" ] ; then
1370        LogFile "----------- $ISO_CMD's errors --------------" 
1371        cat $MINDI_TMP/mkisofs.log >> $LOGFILE
1372        echo "$ISO_CMD returned the following errors:-"
1373        cat $MINDI_TMP/mkisofs.log
1374        LogAll "Failed to create ISO image."
1375    else
1376        LogAll "Created bootable ISO image at $MINDI_CACHE/mindi.iso" 
1377    fi
1378    rm -f $MINDI_TMP/mkisofs.log
1379    cd $old_pwd
1380}
1381
1382
1383OfferToMakeBootableUSB() {
1384    local i
1385    if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1386        echo -n "Shall I make a bootable USB image ? (y/[n]) "
1387        read i
1388        [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1389        if [ "$USBDEVICE" = "" ]; then
1390            echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1391            read dev
1392            USBDEVICE=$dev
1393        fi
1394        echo "WARNING: This will erase all content on $USBDEVICE"
1395        echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1396        read i
1397        [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1398    fi
1399    rm -Rf $MINDI_TMP/usb
1400    mkdir -p $MINDI_TMP/usb
1401    USBPART="${USBDEVICE}1"
1402
1403    echo -en "Transforming $USBDEVICE in a Bootable device " 
1404    echo -en "."
1405    LogFile "Transforming $USBDEVICE in a Bootable device" 
1406    LogFile "Checking $USBDEVICE" 
1407    $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
1408    if [ $? -ne 0 ]; then
1409        LogAll "Unable to access $USBDEVICE" 
1410        LogAll "Make sure your USB device is pluged in" 
1411        exit -1
1412    fi
1413    echo -en "."
1414    LogFile "Unmounting $USBDEVICE just in case" 
1415    umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1416    # If your key has no MBR it may cause an issue
1417    # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
1418    LogFile "Preparing $USBDEVICE" 
1419    $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
1420d
1421d
1422d
1423d
1424n
1425p
14261
1427
1428
1429t
1430b
1431a
14321
1433w
1434EOF
1435    if [ $? -ne 0 ]; then
1436        LogAll "Unable to create a vfat Filesystem on $USBDEVICE" 
1437        LogAll "Make sure your USB device is pluged in" 
1438        $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1439        MindiExit -1
1440    fi
1441    LogFile "The USB device $USBDEVICE now looks like this:" 
1442    $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1443    echo -en "."
1444    LogFile "Creating a vfat filesystem on $USBPART" 
1445    mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
1446    if [ $? -ne 0 ]; then
1447        LogAll "Unable to create a vfat filesystem on $USBPART" 
1448        LogAll "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)" 
1449        $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1450        MindiExit -1
1451    fi
1452    echo -en "."
1453    LogFile "Mounting $USBPART on $MINDI_TMP/usb" 
1454    mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1455    if [ $? -ne 0 ]; then
1456        LogAll "Unable to mount $USBPART on $MINDI_TMP/usb" 
1457        LogAll "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)" 
1458        $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1459        MindiExit -1
1460    fi
1461    echo -en "."
1462    mkdir -p $MINDI_TMP/usb/images
1463    cp -f $MINDI_CACHE/*.img $MINDI_CACHE/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogAll "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
1464    echo -en "."
1465    LogFile "mindi_lib = $MINDI_LIB" 
1466    for i in memdisk memtest.bin memtest.img ; do
1467        j=$MINDI_LIB/$i
1468        k=$MINDI_TMP/usb
1469        if [ -e "$j" ] ; then
1470            LogAll "Copying $j to $k"
1471            cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1472            cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1473        fi
1474    done
1475    echo -en "."
1476    MakeMessageFile > $MINDI_TMP/usb/message.txt
1477    echo -en "."
1478    cp $kernelpath $MINDI_TMP/usb/vmlinuz 2>> $LOGFILE || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/usb/vmlinuz). Did you run out of disk space?"
1479    echo -en "."
1480    cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1481    echo -en "."
1482    MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
1483    echo -en "."
1484    umount $MINDI_TMP/usb
1485    if [ "$ARCH" != "ia64" ] ; then
1486        syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
1487        if [ "$?" -ne "0" ] ; then
1488            LogAll "----------- syslinux's errors --------------" |tee -a $LOGFILE
1489            cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1490            echo "----------- syslinux's conf --------------" |tee -a $LOGFILE
1491            cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
1492            LogAll "Failed to create USB image."
1493        else
1494            echo -e "$DONE"
1495            LogFile "Created bootable USB image on $USBDEVICE" 
1496        fi
1497        rm -f $MINDI_TMP/syslinux.log
1498    else
1499        echo "No USB boot support for ia64" 
1500        MindiExit -1
1501    fi
1502}
1503
1504
1505MakeMessageFile() {
1506   
1507    if [ -x "/bin/lsb_release" ]; then
1508        DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1509    elif [ -x "/usr/bin/pbdistrocheck" ]; then
1510        # For pb >= 0.9.8
1511        DESC=`/usr/bin/pbdistrocheck -d`
1512    else
1513        iss="/dev/null"
1514        [ -r /etc/issue.net ] && iss="/etc/issue.net"
1515        [ -r /etc/issue ] && iss="/etc/issue"
1516        DESC=`head -1 $iss`
1517    fi
1518    sed "s/ZZZZZ/$MINDI_VERSION/" $MINDI_LIB/msg-txt | sed "s/KKKKK/Kernel $KERVER/" | sed "s/AAAAA/on a $ARCH architecture/" | sed "s/TTTTT/`LC_TIME=C date`/" | sed "s/MMMMM/`hostname`/" | sed "s/DDDDD/$DESC/"
1519    if [ _"$MONDO_SHARE" != _"" ]; then
1520        if [ "$CDRECOVERY" != "yes" ] ; then
1521            if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1522                echo -en "Press <enter> to continue.\n"
1523            elif [ ! "$MINDI_TMP" ] ; then
1524                echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1525                if [ -e "$MINDI_LIB/memtest.img" ] ; then
1526                 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
1527                fi
1528            else
1529                echo -en "$BOOT_MEDIA_MESSAGE"
1530            fi
1531        else
1532            echo -en "\
1533To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1534CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1535        fi
1536    fi
1537    echo -en "\n\n\n"
1538}
1539
1540
1541MakeBootConfFile() {
1542    local options i ooo
1543    options=""
1544    # Type of boot file (elilo or syslinux/isolinux)
1545    type=$1
1546    if [ "$type" = "elilo" ]; then
1547        sep="="
1548    else
1549        sep=" "
1550    fi
1551
1552    # Generic header for conf file
1553    if [ "$type" != "elilo" ] ; then
1554        echo -en "prompt 1\ndisplay message.txt\n"
1555    else
1556        echo -en "prompt\n"
1557    fi
1558
1559    # Compute which default option to boot from
1560    if [ "$CDRECOVERY" = "yes" ] ; then
1561        echo -en "default${sep}RESTORE\n"
1562    # In case it's mondoarchive
1563    elif [ _"$MONDO_SHARE" != _"" ]; then
1564        if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1565            echo -en "default${sep}iso\n"
1566        else
1567            echo -en "default${sep}interactive\n"
1568        fi
1569    else
1570        echo -en "default${sep}expert\n"
1571    fi
1572
1573    # Handle timeout
1574    if [ "$CDRECOVERY" != "yes" ] ; then
1575        echo -en "timeout${sep}300\n"
1576    else
1577        echo -en "timeout${sep}10000\n"
1578    fi
1579    echo -en "\n"
1580
1581    # prepare which labels will be generated
1582    if [ "$CDRECOVERY" = "yes" ] ; then
1583        options="RESTORE expert"
1584    else
1585        if [ _"$MONDO_SHARE" != _"" ]; then
1586            options="interactive expert compare iso nuke isonuke"
1587        else
1588            options="expert"
1589        fi
1590    fi
1591
1592    # Generate rest of conf file
1593    for i in $options ; do
1594        ooo=$i
1595        [ "$ooo" = "RESTORE" ] && ooo="nuke"
1596        if [ "$type" = "elilo" ]; then
1597            outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/initrd.img\n\troot=/dev/ram0 append=\" rw ramdisk_size=$ramdisk_size $ooo $ADDITIONAL_BOOT_PARAMS \"\n"
1598        else
1599            ps="/"
1600            if [ "$type" = "syslinux" ]; then
1601                ps=""
1602            fi
1603            outstr="label $i\n\tkernel ${ps}vmlinuz\n\tappend initrd=${ps}initrd.img root=/dev/ram0 rw ramdisk_size=$ramdisk_size ${ooo} $ADDITIONAL_BOOT_PARAMS\n"
1604        fi
1605        echo -en "$outstr"
1606    done
1607
1608    if [ -e "$MINDI_LIB/memtest.img" ] ; then
1609        if [ "$type" = "elilo" ]; then
1610            echo -en "image=/memtest.bin\n\tlabel=memtest\n"
1611            echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
1612        else
1613            ps="/"
1614            if [ "$type" = "syslinux" ]; then
1615                ps=""
1616            fi
1617            echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
1618            echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
1619        fi
1620    fi
1621}
1622
1623
1624PrepareBootDiskImage_LILO() {
1625    local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
1626    imagesdir=$MINDI_CACHE
1627    kernelpath=$1
1628
1629    retval=0
1630    [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1631    echo -en "Making "$BOOT_SIZE"KB boot disk..."
1632    TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/initrd.img `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into initrd.img; are you SURE your kernel supports loopfs?"
1633    echo -en "..."
1634    imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1635    mountpoint=$MINDI_TMP/mountpoint.$$
1636    mkdir -p $mountpoint
1637    dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1638    mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1639    mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
1640    # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1641    mkdir -p $mountpoint/etc
1642    liloconf=$mountpoint/elilo.conf
1643
1644    MakeBootConfFile elilo > $liloconf
1645
1646    # Copy it so that CD-ROM menu entry is satisfied
1647    mountefi=0
1648    df -T | grep /boot/efi | grep -q vfat
1649    if [ $? -ne 0 ]; then
1650        mount /boot/efi
1651        if [ $? -ne 0 ]; then
1652            echo "You have to mount your EFI partition when using mindi"
1653            MindiExit -1
1654        fi
1655        mountefi=1
1656    fi
1657    el=`find /boot/efi -name elilo.efi`
1658    cp $el $mountpoint
1659    cp $liloconf $mountpoint
1660    if [ $mountefi -eq 1 ]; then
1661        umount /boot/efi 2>&1 > /dev/null
1662    fi
1663
1664    LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint..." 
1665    cp -f $MINDI_TMP/initrd.img $mountpoint 2>> $LOGFILE
1666    if [ "$?" -ne "0" ] ; then
1667        LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1668        cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1669        LogAll "Please unload some of your modules and try again."
1670        rm -f $MINDI_TMP/mtpt.$$
1671        LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1672        retval=$(($retval+1))
1673    fi
1674    MakeMessageFile > $mountpoint/message.txt
1675
1676    mkdir -p $mountpoint/tmp
1677    if [ -f "$MINDI_TMP/mondo-restore.cfg" ]; then
1678        cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp
1679    fi
1680
1681    # copy the kernel across
1682    [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1683    dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1684    free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1685    cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2>> $LOGFILE
1686    if [ "$?" -ne "0" ] ; then
1687        LogFile "Files at mountpoint ($mountpoint) :-" 
1688        du -sk $mountpoint/* >> $LOGFILE
1689        LogFile "--- end of list of files ---" 
1690        echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
1691Sorry, your kernel is too big for your image.\n" >> $LOGFILE
1692        [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1693        cd $old_pwd
1694        umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1695        rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1696        [ "$imagefile" != "" ] && rm -f $imagefile
1697        return 0
1698    fi
1699    max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
1700    LogFile "Free space left on image = $free_space KB" 
1701    LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K" 
1702    # make it bootable
1703    [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1704    [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
1705    if [ "$KERN_DISK_MADE" ] ; then
1706        LogFile "Not running LILO. It's not that kind of disk." 
1707    fi
1708
1709    cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1710    umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1711    echo -en "..."
1712    rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1713    if [ "$retval" -eq "0" ] ; then
1714        echo -en "...$DONE\n"
1715        if [ "$KERN_DISK_MADE" ] ; then
1716            LogAll "$BOOT_SIZE KB boot disks were created OK\n"
1717        fi
1718    else
1719        echo -en "...failed\n"
1720        LogAll $BOOT_SIZE"KB boot disk was NOT created\n"
1721        [ "$imagefile" != "" ] && rm -f $imagefile
1722    fi
1723    [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
1724    return $retval
1725}
1726
1727
1728PrepareBootDiskImage_ISOLINUX() {
1729    local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
1730    imagesdir=$MINDI_CACHE
1731    kernelpath=$1
1732    do_boot_root_thingy=""
1733    local retval old_pwd
1734    retval=0
1735
1736    [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1737    echo -en "Making "$BOOT_SIZE"KB boot disk..."
1738    TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/initrd.img `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into initrd.img; are you SURE your kernel supports loopfs?"
1739    echo -en "..."
1740    imagefile=$MINDI_TMP/mindi-bootroot.$BOOT_SIZE.img
1741    mountpoint=$MINDI_TMP/mountpoint.$$
1742    mkdir -p $mountpoint
1743    dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1744    LogFile "Creating vfat filesystem on $imagefile" 
1745    mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
1746    # syslinux should be run on a  local file (doen't work through NFS Cf: #297)
1747    syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1748
1749    # Only move it now to its final destination abd use it now
1750    mv $imagefile $imagesdir
1751    imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1752
1753    mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
1754
1755    # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1756    MakeMessageFile > $mountpoint/message.txt
1757    MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1758    LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..." 
1759    cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
1760    if [ "$?" -ne "0" ] ; then
1761        LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1762        cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1763        LogAll "Please unload some of your modules and try again."
1764        rm -f $MINDI_TMP/mtpt.$$
1765        LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1766        retval=$(($retval+1))
1767    fi
1768
1769    mkdir -p $mountpoint/tmp
1770    if [ -f "$MINDI_TMP/mondo-restore.cfg" ]; then
1771        cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp
1772    fi
1773
1774    # copy the kernel across
1775    [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1776    dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1777    free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1778    cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
1779    if [ "$?" -ne "0" ] ; then
1780        LogFile "Files at mountpoint ($mountpoint) :-" 
1781        du -sk $mountpoint/* >> $LOGFILE
1782        LogFile "--- end of list of files ---" 
1783        echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
1784Sorry, your kernel is too big for your image.\n" >> $LOGFILE
1785        [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1786        cd $old_pwd
1787        umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1788        rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1789
1790        [ "$imagefile" != "" ] && rm -f $imagefile
1791        return 0
1792    fi
1793    max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
1794    LogFile "Free space left on image = $free_space KB" 
1795    LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K" 
1796
1797    # make it bootable
1798    [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1799    mkdir -p $mountpoint/etc
1800    [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
1801    umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1802    echo -en "..."
1803    rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1804
1805    if [ "$retval" -eq "0" ] ; then
1806        echo -en "...$DONE\n"
1807        if [ "$KERN_DISK_MADE" ] ; then
1808            [ "$imagefile" != "" ] && rm -f $imagefile
1809            LogAll "$BOOT_SIZE KB boot disks were created OK\n"
1810        fi
1811    else
1812        echo -en "...failed\n"
1813        LogAll $BOOT_SIZE"KB boot disk was NOT created\n"
1814        [ "$imagefile" != "" ] && rm -f $imagefile
1815    fi
1816    [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
1817    return $retval
1818}
1819
1820
1821ParseModprobeForIncludes() {
1822local MODPROBE_CONF mpincfile includes include
1823
1824MODPROBE_CONF=/etc/modprobe.conf
1825mpincfile=$1
1826touch $mpincfile
1827if [ -a $MODPROBE_CONF ]; then
1828    includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
1829    if [ -n "$includes" ]; then
1830        for include in $includes
1831        do
1832            if [ -a "$include" ]; then
1833                echo $include >> $mpincfile
1834            fi
1835        done
1836    fi
1837fi
1838}
1839
1840
1841PrepareDataDiskImages() {
1842    local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
1843
1844    imagesdir=$MINDI_CACHE
1845    rm -f $imagesdir/mindi.iso
1846    needlist=$MINDI_TMP/what-we-need.txt
1847    bigdir=$MINDI_TMP/bigdir
1848    mkdir -p $bigdir/usr/bin
1849    mkdir -p $bigdir/usr/sbin
1850    includefile=$MINDI_TMP/$$.includefile.txt
1851
1852    lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
1853    if [ -e "$DEPLIST_FILE" ]; then
1854        lfiles="$DEPLIST_FILE $lfiles"
1855    fi
1856    lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
1857    ParseModprobeForIncludes $includefile
1858    lines=$(($lines+`cat $includefile | wc -l`))
1859    cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
1860    res=$?
1861    rm -f $includefile
1862    if [ "$YOUR_KERNEL_SUCKS" ]; then
1863        pwd=`pwd`
1864        cd $MINDI_TMP
1865        rm -f lkm.lis
1866        ListKernelModulePaths lkm.lis
1867        for i in `cat lkm.lis | HackPathsToFailsafe` ; do
1868            tar cf - ./$i 2>> $MINDI_TMP/$$.log | (cd $bigdir ; tar xf -) || Die "PDDI can't copy $i->$bigdir" $MINDI_TMP/$$.log
1869        done
1870        rm -f lkm.lis
1871        for i in $EXTRA_MODS ; do
1872            j=`find lib/modules/$FAILSAFE_KVER -name $i.*o.gz 2> /dev/null`
1873            [ ! "$j" ] && LogFile "WARNING - cannot find failsafe module $i.o.gz" 
1874            for k in $j ; do
1875                tar cf - $k 2>> $MINDI_TMP/$$.log | (cd $bigdir ; tar xf -) || LogAll "ERROR on module $k" $MINDI_TMP/$$.log
1876                LogFile "Added failsafe module $k to ramdisk" 
1877            done
1878        done
1879        cd $pwd
1880    else
1881        # This function appends to the file passed in param
1882        ListKernelModulePaths $needlist
1883    fi
1884    if [ "$res" -ne "0" ] ; then
1885        Die "You have $res files present in dependency list\nbut absent from filesystem."
1886    fi
1887    FindAndAddUserKeyboardMappingFile
1888    mkdir -p $bigdir/tmp
1889    if [ _"$MONDO_SHARE" != _"" ]; then
1890        MakeMondoConfigFile $MINDI_TMP/mondo-restore.cfg
1891        cp -f $MINDI_TMP/mondo-restore.cfg $bigdir/tmp &> /dev/null
1892    fi
1893    [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
1894    DropOptimizedLibraries $needlist $bigdir
1895    echo -en "Assembling dependency files"
1896
1897    CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
1898
1899    # also copy io.sys and msdos.sys, if we can find them
1900    for i in `mount | cut -d' ' -f3` ; do
1901        for j in io.sys msdos.sys ; do
1902            [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
1903        done
1904    done
1905
1906    # master boot record, too
1907    i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
1908    if [ "$i" ] ; then
1909        LogAll "Backing up $i's MBR"
1910        dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
1911        sleep 1
1912        sync
1913        j=$i
1914        [ -h "$j" ] && j=`readlink -f $j`
1915        LogAll "Creating /dev/boot_device ($j)"
1916        mkdir -p $bigdir/dev
1917        cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
1918    fi
1919
1920    old_pwd=`pwd`
1921    cd $bigdir
1922
1923    # Get terminfo content
1924    ti="usr/share/terminfo/l"
1925    if [ -d /$ti ]; then
1926        mkdir -p $ti
1927        cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "WARNING - error occurred while copying terminfo"
1928    fi
1929    if [ -e "$MONDO_SHARE/restore-scripts" ]; then
1930        cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
1931        [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
1932    fi
1933    if [ -d "/lib/dev-state" ]; then 
1934        tar cf - -C / ./lib/dev-state 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
1935    fi
1936    cd $old_pwd
1937    echo -e "$DONE"
1938    TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
1939    MakeMountlist $MINDI_TMP/mountlist.txt
1940    CheckMountlist $MINDI_TMP/mountlist.txt
1941    mkdir -p $bigdir/tmp
1942    cp -f $MINDI_TMP/mountlist.txt $bigdir/tmp/mountlist.txt 2>> $LOGFILE || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk"
1943    if [ _"$MONDO_SHARE" != _"" ]; then
1944        cp -f $bigdir/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
1945    fi
1946    if [ $LVM != "false" ]; then
1947        $MINDI_LIB/analyze-my-lvm > $bigdir/tmp/i-want-my-lvm
1948        if [ "$?" -ne "0" ]; then
1949            LVM="false"
1950            rm -f $bigdir/tmp/i-want-my-lvm
1951        fi
1952    fi
1953    cat $bigdir/tmp/mountlist.txt >> $LOGFILE
1954    LogFile "-----------------------------------"
1955
1956    LogFile -en "$FILES_IN_FILELIST" > $bigdir/FILES-IN-FILELIST
1957    echo -en "$LAST_FILELIST_NUMBER" > $bigdir/LAST-FILELIST-NUMBER 2>> $LOGFILE
1958    if [ _"$MONDO_SHARE" != _"" ]; then
1959        for q in filelist.full.gz biggielist.txt ; do
1960            [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
1961            cp -pRdf $MINDI_TMP/$q $bigdir/tmp 2>> $LOGFILE
1962        done
1963    fi
1964
1965    echo -en "Tarring and zipping the data content..."
1966    size_of_all_tools=`du -sk $bigdir | cut -f1`
1967    (cd $bigdir ; tar -b 4096 -cf - . 2>> $MINDI_TMP/$$.log | gzip -9 > $imagesdir/all.tar.gz || LogAll "Problem creating all.tar.gz" $MINDI_TMP/$$.log)
1968    du -sk $imagesdir/*gz >> $LOGFILE
1969    echo -e "$DONE"
1970
1971    FRIENDLY_OUTSTRING="Boot and data disk images were created."
1972    rm -rf $bigdir
1973    rm -f $needlist
1974}
1975
1976
1977ProcessLDD() {
1978    local incoming f d nd bd bnd
1979    read incoming
1980    while [ "$incoming" != "" ]; do
1981        # We take the full path name of the dyn. lib. we want
1982        incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
1983        for f in $incoming ; do
1984            # echo modified file name if one of the parent dir is a link
1985            # by replacing the original dirname by the destination of the link
1986            d="`dirname $f`"
1987            found="false"
1988            while [ "$d" != "/" ]; do
1989                if [ -h "$d" ]; then
1990                    nd=`readlink -f $d`
1991                    bd=`basename $d`
1992                    bnd=`basename $nd`
1993                    f=`echo $f | sed "s~/$bd/~/$bnd/~"`
1994                    echo $d
1995                fi
1996                d="`dirname $d`"
1997            done
1998
1999            echo "$f"
2000            echo "`ReadAllLink $f`"
2001        done
2002        read incoming
2003    done
2004}
2005
2006
2007Prompt() {
2008    echo -en "$1"
2009    read line
2010}
2011
2012
2013ReadLine() {
2014    local i incoming
2015    read incoming
2016    i=0
2017    while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
2018        i=$(($i+1))
2019        read incoming
2020    done
2021    echo "$incoming"
2022}
2023
2024
2025SizeOfPartition() {
2026    local devpath drive res stub
2027    device=$1
2028    if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2029        res=`SizeOfRaidPartition $device`
2030        [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2031        echo "$res"
2032        return 0
2033    fi
2034    # patch from Bill <bill@iwizard.biz> - 2003/08/25
2035    res=`$FDISK -s $device 2>> $LOGFILE`
2036    # end patch
2037    # take only the first in case of multiple mount (cifs, nfs, ...)
2038    [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
2039    [ "$res" = "" ] && res="-1"
2040    echo $res
2041    return 0
2042}
2043
2044
2045SizeOfRaidPartition() {
2046    local real_dev smallest_size silly tmp
2047
2048    silly=999999999
2049    smallest_size=$silly
2050
2051    for real_dev in `GetRaidDevMembers $1` ; do
2052        tmp=`SizeOfPartition $real_dev`
2053        [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2054    done
2055
2056    if [ "$smallest_size" = "$silly" ] ; then
2057        echo "-1"
2058        return 1
2059    else
2060        echo "$smallest_size"
2061        return 0
2062    fi
2063}
2064
2065
2066StripComments()
2067{
2068    local tempfile
2069
2070    tempfile=$MINDI_TMP/$$.strip.txt
2071    cp -f $1 $tempfile 2>> $LOGFILE
2072    $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2073    rm -f $tempfile
2074    LogFile "Stripped comments from $2" 
2075}
2076
2077
2078
2079StripExecutable()
2080{
2081    local tmpfile
2082
2083    tmpfile=$MINDI_TMP/stripped.$$.dat
2084    [ -d "$1" ] || [ -h "$1" ] && return
2085    cp -f $1 $tmpfile 2>> $LOGFILE
2086    strip $tmpfile 2> /dev/null
2087    if [ "$?" -eq "0" ] ; then
2088        cp -f $tmpfile $1 2>> $LOGFILE
2089        LogFile "Stripped binary $2" 
2090    fi
2091    rm -f $tmpfile
2092}
2093
2094KernelVer() {
2095        local fkern_ver fname
2096
2097        fname=$1
2098        file $fname | grep -q gzip
2099        if [ "$?" -eq "0" ] ; then
2100            # Used by ia64
2101            fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2102        else
2103            fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2104        fi
2105        echo "$fkern_ver"
2106}
2107
2108
2109TryToFindKernelPath() {
2110    local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2111
2112    we_want_version=$KERVERRUN
2113    possible_kernels=""
2114    duff_kernels=""
2115   
2116    if [ "$ARCH" = "ia64" ] ; then
2117       root="/boot/efi/efi"
2118    else
2119       root="/"
2120    fi
2121    for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
2122        [ ! -e "$fname" ] && continue
2123        [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2124        fkern_ver=`KernelVer $fname`
2125        [ "$fkern_ver" = "" ] && continue
2126        [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2127        [ -f "$fname" ] || continue
2128        [ -h "$fname" ] && continue
2129        kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2130        file $fname | grep -q gzip
2131        if [ "$?" -eq "0" ] ; then
2132            # Used by ia64
2133            if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2134                LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2135                duff_kernels="$fname $duff_kernels"
2136            else
2137                [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2138                possible_kernels="$fname $possible_kernels"
2139            fi
2140        else
2141            if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2142                LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2143                duff_kernels="$fname $duff_kernels"
2144            else
2145                [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2146                possible_kernels="$fname $possible_kernels"
2147            fi
2148        fi
2149    done
2150    if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2151        possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2152    fi
2153    if [ ! "$possible_kernels" ] ; then
2154        LogAll "No kernel matches exactly. Are there any duff kernels?"
2155        possible_kernels="$duff_kernels"
2156        if [ ! "$possible_kernels" ] ; then
2157            LogAll "Sorry, no duff kernels either"
2158        else
2159            LogAll "I bet you're running Debian or Gentoo, aren't you?"
2160            LogAll "Your kernel doesn't have a sane builddate. Oh well..."
2161        fi
2162    fi
2163    possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2164    noof_kernels=`CountItemsIn "$possible_kernels"`
2165    if [ "$noof_kernels" -eq "0" ] ; then
2166        LogAll "Could not find your kernel."
2167        if [ -e "/boot/vmlinuz" ] ; then
2168            LogAll "Using /boot/vmlinuz as a last resort."
2169            output=/boot/vmlinuz
2170        else
2171            output=""
2172        fi
2173    elif [ "$noof_kernels" -eq "1" ] ; then
2174        kernelpath=`echo "$possible_kernels" | sed s/' '//`
2175        LogFile "Your kernel is $kernelpath (v$KERVERRUN)" 
2176        output="$kernelpath"
2177    else
2178        for i in $possible_kernels ; do
2179            if echo $i | grep "$KERVERRUN" ; then
2180                LogAll "OK, I used my initiative and found that "
2181                LogAll "$i is probably your kernel. "
2182                output="$i"
2183                return
2184            fi
2185        done
2186        if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2187            output=/boot/vmlinuz
2188            LogFile "Schlomo, this one's for you." 
2189        else
2190            LogAll "Two or more possible kernels found. You may specify any one of them and the "
2191            LogAll "boot disks will still work, probably. If one does not work, try another."
2192            LogAll "$possible_kernels"
2193            echo ""
2194        fi
2195    fi
2196    echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2197}
2198
2199
2200TurnTgzIntoRdz() {
2201    local tgz_dir_fname rdz_fname tempfile mountpoint old_pwd nodes kernelsize maxsize res currsize not_copied j k s w needed_modules_path
2202
2203    tgz_dir_fname=$1
2204    rdz_fname=$2
2205    kernelsize=$3
2206    maxsize=$(($BOOT_SIZE-$kernelsize))
2207    maxsize=$(($maxsize*2)); # to allow for compression of 50%
2208    tempfile=$MINDI_TMP/temp.rd
2209    mountpoint=$MINDI_TMP/mnt1
2210    res=0
2211    echo -en "..."
2212    dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk ($tempfile)"
2213    echo -en "..."
2214    LogFile "Creating ext2 filesystem on $tempfile" 
2215    mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2216    echo -en "..."
2217    mkdir -p $mountpoint
2218    mount -t ext2 -o loop $tempfile $mountpoint || Die "Cannot loopmount $tempfile to $mountpoint! The reason may be missing support for loopfs or ext2 (or both) in the running kernel."
2219    echo -en "..."
2220    old_pwd=`pwd`
2221    cd $mountpoint
2222
2223    # AL04Oct08: Check whether /lib64 is a link and if so explicitly create one in rootfs
2224    if [ -h "/lib64" ]; then
2225        mkdir -p lib || LogAll "Unable to create lib in $mountpoint."
2226        ln -s lib lib64 || LogAll "/lib64 is a symbolic link, but I couldn't create it in $mountpoint."
2227    fi
2228
2229    cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
2230
2231    cd dev || Die "Can't cd to dev"
2232    tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2233    rm -f dev-entries.tgz
2234    cd ..
2235
2236    for w in insmod.static insmod.static.old ; do
2237        s=`which $w 2> /dev/null`
2238        if [ -e "$s" ] ; then
2239            tar cf - -C / $s 2> /dev/null | tar xf -
2240        fi
2241    done
2242
2243    [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2244
2245    # We need a minimal conf in the initial ramdisk
2246    mountlis=`grep -v "^#.*" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | cut -d: -f2 | sort -u`
2247    ReadAllLink $mountlis > $MINDI_TMP/mnt.lis
2248    LocateDeps `cat $MINDI_TMP/mnt.lis` >> $MINDI_TMP/deps.lis
2249    # Special for libs
2250    ReadAllLink `grep -E "/lib" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | grep -v "^#.*" | cut -d: -f2` >> $MINDI_TMP/deps.lis
2251
2252    # Initial / are trucated by tar
2253    tar cf - `cat $MINDI_TMP/mnt.lis` `sort -u $MINDI_TMP/deps.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Problem in mount analysis" $MINDI_TMP/$$.log
2254    rm -f $MINDI_TMP/deps.lis
2255
2256    # Copy of files mandatory for ssh to automate mount if sshfs is used
2257    mkdir $mountpoint/.ssh
2258    cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2259    cat > $mountpoint/bin/myssh << EOF
2260ssh -o StrictHostKeyChecking=no $*
2261EOF
2262    chmod 755 $mountpoint/bin/myssh
2263
2264    # Copy of files mandatory for ld.so
2265    cp -rp /etc/ld.so.c* $mountpoint/etc
2266
2267    # Avoid an issue on some distro (RHEL5)
2268    rm -f $mountpoint/etc/ld.so.conf.d/kernelcap*
2269
2270    mkdir -p $mountpoint/tmp
2271    # Management of udev (which includes modprobe in rules)
2272    ps auxww | grep -v grep | grep -qw udevd
2273    if [ $? -eq 0 ]; then
2274        echo "udev device manager found" > $mountpoint/tmp/USE-UDEV
2275        LogFile "udev device manager found"
2276        tar cf - -C / /etc/udev 2>> $MINDI_TMP/$$.log | tar xf -  || LogAll "Problem in /etc/udev analysis" $MINDI_TMP/$$.log
2277        # This avoids NIC remapping if on another machine at restore time on Debian at least
2278        rm -f ./etc/udev/rules.d/z[0-9][0-9]_persistent-net.rules
2279        # This avoids NIC remapping if on another machine at restore time on Ubuntu at least
2280        rm -f ./etc/udev/rules.d/[0-9][0-9]-persistent-net.rules
2281        tar cf - -C / /lib*/udev 2>> $MINDI_TMP/$$.log | tar xf -  || LogAll "Problem in /lib/udev analysis" $MINDI_TMP/$$.log
2282        if [ -x /sbin/udevd ]; then
2283            lis2=`grep -Ev '^#' $MINDI_CONF/udev.files` 
2284            lis=""
2285            # Get only the files which exist in that list
2286            # and potentially their symlink structure
2287            for i in $lis2; do
2288                if [ -h $i ]; then
2289                    j=$i
2290                    while [ -h $j ]; do
2291                        lis="$lis $j"
2292                        j=`readlink -f $j`
2293                    done
2294                    lis="$lis $j"
2295                elif [ -f $i ]; then
2296                    lis="$lis $i"
2297                fi
2298            done
2299            # And their deps
2300            LocateDeps $lis > $MINDI_TMP/udev.lis
2301            for i in $lis; do
2302                if [ "`echo $i | cut -c1`" = "/" ]; then
2303                    j=`echo $i | cut -c2-`
2304                    [ "$j" != "" ] && rm -f $j
2305                fi
2306            done
2307            tar cf - -C / $lis `sort -u $MINDI_TMP/udev.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Problem in udev.lis analysis" $MINDI_TMP/$$.log
2308            rm -f $MINDI_TMP/udev.lis
2309        else
2310            LogAll "udevd daemon not in standard place (/sbin)"
2311            LogAll "mindi will use static devices which may cause problems"
2312            rm -f $mountpoint/tmp/USE-UDEV
2313        fi
2314    fi
2315
2316    # Management of potential HW info (Proliant only at the moment)
2317    rm -rf $MINDI_CACHE/bkphw
2318    mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2319    if [ -d $MINDI_CACHE/bkphw ]; then
2320        LogAll "Hardware Information found and saved ..."
2321        cp -rp $MINDI_CACHE/bkphw .
2322        if [ -f $MINDI_CACHE/tools.files ]; then
2323            lis=`grep -Ev '^#' $MINDI_CACHE/tools.files` 
2324            LocateDeps $lis > $MINDI_TMP/tools.lis
2325            tar cf - $lis `sort -u $MINDI_TMP/tools.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Problem in tools.lis analysis" $MINDI_TMP/$$.log
2326        fi
2327        if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2328            mv -f $MINDI_CACHE/mindi-rsthw .
2329            chmod 755 ./mindi-rsthw
2330        fi
2331        rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2332    fi
2333
2334    # Management of perl scripts delivered needed at restore time
2335    mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` > $MINDI_TMP/perl.lis
2336    tar cf - `cat $MINDI_TMP/perl.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Problem in perl scripts analysis" $MINDI_TMP/$$.log
2337
2338    for w in cdrom groovy-stuff ; do
2339        mkdir -p mnt/$w
2340    done
2341
2342    tar cf - -C / /dev/fd0*[1,2][4,7,8]* 2>> $MINDI_TMP/$$.log | tar xf -  || LogAll "Problem in fd dev analysis" $MINDI_TMP/$$.log
2343
2344    cd $old_pwd
2345    echo -en "..."
2346    old_pwd=`pwd`
2347    if [ "$YOUR_KERNEL_SUCKS" ] ; then
2348        cd $MINDI_TMP
2349        needed_modules_path=lib/modules/$FAILSAFE_KVER
2350    else
2351        cd /
2352        if [ "${kernelname}" != "" ]
2353        then
2354            needed_modules_path=lib/modules/${kernelname}
2355        else
2356            needed_modules_path=lib/modules/$KERVERRUN
2357        fi
2358    fi
2359
2360    needed_modules=""
2361    list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
2362
2363    if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
2364        # For PXE boot
2365        list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2366    fi
2367    if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2368        list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2369    fi
2370    for i in $DENY_MODS; do
2371        LogFile "Removing $i from the list of modules to load" 
2372        list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2373    done
2374
2375    [ -e "$needed_modules_path" ] || LogAll "path $needed_modules_path does not exist.\n If you're not using a modular kernel then you're NUTS."
2376    for i in $list_of_groovy_mods ; do
2377        needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
2378    done
2379
2380    for i in $needed_modules ; do
2381        [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2382        [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
2383        LogFile "Adding $i ($s KB) to the rootfs" 
2384        tar cf - -C / $i 2>> $MINDI_TMP/$$.log | (cd $mountpoint ; tar xf -) || LogAll "Unable to copy $i to $mountpoint" $MINDI_TMP/$$.log
2385        # Uncompress modules if not using udev and native modprobe
2386        if [ ! -f $mountpoint/tmp/USE-UDEV ]; then
2387            if [ "`echo "$i" | grep -F ".gz"`" ]; then
2388                LogFile "Uncompressing $i" 
2389                gunzip -f $mountpoint/$i
2390            fi
2391        fi
2392    done
2393
2394    # Also copy modules.dep in case of udev so that normal modprobe works
2395    tar cf - -C / /$needed_modules_path/modules.dep 2>> $MINDI_TMP/$$.log | (cd $mountpoint ; tar xf -) || LogAll "Unable to copy modules.dep to $mountpoint" $MINDI_TMP/$$.log
2396
2397    if [ ! -e "/sbin/devfsd" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
2398        LogFile "Deleting devfsd daemon from ramdisk" 
2399        [ ! -e "/sbin/devfsd" ] && LogFile "...because /sbin/devfsd not found" 
2400        [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && LogFile "...because kernel is failsafe" 
2401        rm -f $mountpoint/sbin/devfsd
2402    fi
2403    cd $old_pwd
2404    dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2405    rm -f $mountpoint/zero
2406    if [ _"$MONDO_SHARE" != _"" ]; then
2407        MakeMondoConfigFile $mountpoint/tmp/mondo-restore.cfg
2408        cp -f $mountpoint/tmp/mondo-restore.cfg $MINDI_TMP 2>> $LOGFILE || Die "Cannot copy mondo-restore.cfg to ramdisk"
2409        cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>> $LOGFILE || Die "Cannot copy mountlist to ramdisk"
2410        echo -en "$LAST_FILELIST_NUMBER" > $mountpoint/tmp/LAST-FILELIST-NUMBER
2411    fi
2412    mkdir -p $mountpoint/proc
2413    echo "$BOOT_SIZE" > $mountpoint/tmp/$BOOT_SIZE.siz
2414
2415    LogFile "---------------------------"
2416    LogFile "Content of initial ramdisk:"
2417    LogFile "---------------------------"
2418    (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2419    LogFile "---------------------------"
2420
2421    # Determine what filesystem to use for initrd image
2422    LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." 
2423    gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2424    [ -z  gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2425    if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ]; then
2426        # say what will be used
2427        LogFile "Creating an $gvFileSystem initrd image..."
2428        # kernel expects linuxrc in ext2 filesystem
2429        ( cd $mountpoint && ln -sf sbin/init linuxrc )
2430        # unmount loop filesystem and create image file using the standard approach
2431        umount $mountpoint || Die "Cannot unmount $tempfile"
2432        dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
2433        bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
2434        ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2435        gzip -c9 ${rdz_fname}.tmp > $rdz_fname
2436        rm -f ${rdz_fname}.tmp
2437        # log that we are done
2438        LogFile "...done." 
2439    elif [ "$gvFileSystem" = "initramfs" ]; then
2440        # say what will be used
2441        LogFile "Creating a gzip'ed cpio (AKA initramfs) initrd image..." 
2442        # make sure that cpio is there
2443        which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2444        # go into filesystem
2445        cd $mountpoint
2446        # kernel expects init in cpio filesystem
2447        ln -sf sbin/init init
2448        # create cpio image file and unmount loop filesystem
2449        find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
2450        cd $old_pwd
2451        umount $mountpoint || Die "Cannot unmount $tempfile"
2452        # log that we are done
2453        LogFile "...done." 
2454    else
2455        Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2456    fi
2457
2458    if [ "$res" -eq "0" ] ; then
2459        echo -en "..."
2460    else
2461        echo -en "\rMade an rdz WITH ERRORS.           \n"
2462    fi
2463    return 0
2464}
2465
2466
2467##############################################################################
2468#----------------------------------- Main -----------------------------------#
2469##############################################################################
2470
2471# Now we can create what we need
2472mkdir -p $MINDI_TMP
2473
2474# Purge from potential old run
2475if [ _"$MINDI_CACHE" = _"" ]; then
2476    Die "MINDI_CACHE undefined"
2477fi
2478
2479if [ "$1" = "--printvar" ] ; then
2480    shift
2481    if [ _"$1" != _"" ] ; then
2482        set | grep -Ew "^$1" | cut -d= -f2
2483    fi
2484    exit 0
2485fi
2486
2487> $LOGFILE
2488LogFile "mindi v$MINDI_VERSION" 
2489LogFile "$ARCH architecture detected" 
2490LogFile "mindi called with the following arguments:" 
2491LogFile "$*"
2492LogFile "Start date : `date`" 
2493LogFile "-----------------------------" 
2494
2495[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2496
2497# Log some capital variables
2498[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2499LogFile "MONDO_SHARE = $MONDO_SHARE" 
2500LogFile "MINDI_LIB = $MINDI_LIB" 
2501LogFile "MINDI_SBIN = $MINDI_SBIN" 
2502[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2503LogFile "MINDI_CONF = $MINDI_CONF" 
2504if [ -f $MINDI_CONFIG ]; then
2505    LogFile "-----------------------------" 
2506    LogFile " Mindi configuration file    " 
2507    LogFile "-----------------------------" 
2508    grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
2509    LogFile "-----------------------------" 
2510fi
2511
2512
2513trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2514
2515# Sanity checks
2516which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2517which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2518which gawk > /dev/null 2> /dev/null || Die "Gawk is missing from your computer. Please install gawk. You may find the package on Debian's website. How did I know you're running Debian? Because only Debian would be stupid enough not to include gawk in your distribution."
2519which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2520if which awk &> /dev/null ; then
2521    if ! which gawk &> /dev/null ; then
2522        LogAll "You have awk but not gawk.\nPlease note that mindi works fine with a _sane_ awk binary.\nIf your awk binary misbehaves then please contact your vendor\nor distribution's mailing list for technical support.\n"
2523    fi
2524fi
2525which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2526[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
2527
2528[ "`echo $KERVERRUN | grep "2.4.[0-6]" | grep -v "2.4.[0-9][0-9]"`" != "" ] &&  echo "WARNING! Your kernel may have buggy loopfs code. Consider upgrading to 2.4.7"
2529
2530# Update the PATH variable if incomplete
2531if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2532    PATH=$PATH:/sbin:/usr/sbin
2533    export PATH
2534    LogFile "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." 
2535    LogFile "However, you may wish to ask your vendor to provide a permanent fix..." 
2536    LogFile " Or you might like to call 'su -' instead of 'su', for example." 
2537fi
2538
2539# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2540if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2541    source $MINDI_LIB/FindDistroFailsafe
2542    # Log kernel image
2543    LogAll "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2544else
2545    [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2546fi
2547
2548if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
2549    Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2550fi
2551
2552### BERLIOS
2553### Fix as it's not mandatory on ia64
2554if [ "$ARCH" = "ia64" ] ; then
2555    if which elilo &> /dev/null ; then
2556        LILO_EXE=elilo
2557    else
2558        LILO_EXE=`which false 2> /dev/null`
2559    fi
2560else
2561    FindIsolinuxBinary
2562fi
2563trap "Aborted" SIGTERM
2564DONE="\r\t\t\t\t\t\t\t\tDone.         "
2565kernelpath=""
2566MONDO_ROOT=/var/cache/mondo
2567mkdir -p $MONDO_ROOT
2568
2569if [ -d "/proc/lvm" ]; then
2570    # LVM v1
2571    LVMCMD=""
2572    LVM="v1"
2573elif [ -d "/dev/mapper" ]; then
2574    # LVM v2
2575    LVMCMD="lvm"
2576    LVM="v2"
2577else
2578    LVM="false"
2579fi
2580
2581if [ -e "/proc/cmdline" ]; then
2582    CMDLINE="/proc/cmdline"
2583elif [ -e "/tmp/cmdline" ]; then
2584    CMDLINE="/tmp/cmdline"
2585else
2586    CMDLINE="/dev/null"
2587fi
2588
2589LogFile "LVM set to $LVM" 
2590LogFile "----------" 
2591LogFile "mount result:" 
2592LogFile "-------------" 
2593mount >> $LOGFILE
2594LogFile "-------------" 
2595if [ -e /etc/raidtab ]; then
2596    LogFile "-------------" 
2597    LogFile "/etc/raidtab content:" 
2598    LogFile "-------------" 
2599    cat /etc/raidtab >> $LOGFILE
2600fi
2601LogFile "-------------" 
2602LogFile "cat $CMDLINE" 
2603LogFile "-------------" 
2604cat $CMDLINE >> $LOGFILE
2605LogFile "-------------" 
2606LogFile "cat /proc/swaps:" 
2607LogFile "-------------" 
2608cat /proc/swaps >> $LOGFILE
2609LogFile "-------------" 
2610LogFile "cat /proc/partitions:" 
2611LogFile "-------------" 
2612cat /proc/partitions >> $LOGFILE
2613LogFile "-------------" 
2614LogFile "cat /proc/filesystems:" 
2615LogFile "-------------" 
2616cat /proc/filesystems >> $LOGFILE
2617LogFile "-------------" 
2618LogFile "lsmod result:" 
2619LogFile "-------------" 
2620lsmod >> $LOGFILE
2621MODULES="`cat /proc/modules | $AWK '{print $1}'`"
2622if [ -x /usr/sbin/esxcfg-module ]; then
2623    LogFile "-------------" 
2624    LogFile "VMWare ESX server detected - Enabling dedicated support" 
2625    LogFile "-------------" 
2626    LogFile "VMWare modules" 
2627    LogFile "-------------" 
2628    /usr/sbin/esxcfg-module -l >> $LOGFILE
2629    MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
2630fi
2631LogFile "FORCE_MODS:" 
2632LogFile "-------------" 
2633LogFile $FORCE_MODS 
2634LogFile "-------------" 
2635LogFile "DENY_MODS:" 
2636LogFile "-------------" 
2637LogFile $DENY_MODS 
2638LogFile "-------------" 
2639LogFile "df result:" 
2640LogFile "----------" 
2641df -T >> $LOGFILE
2642LogFile "-------------" 
2643LogFile "Liste of extra modules is:" 
2644LogFile "$EXTRA_MODS" 
2645LogFile "-------------" 
2646
2647# Compute libata version
2648laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/  *//g' 2> /dev/null`
2649# If libata v2 is used then remove ide-generic as it will perturbate boot
2650if [ "`echo $MODULES | grep libata`" ]; then
2651    if [ "$laver" = "2" ]; then
2652        DENY_MODS="$DENY_MODS ide-generic"
2653        LogFile "ide-generic removed from module list as your system uses libata v2+" 
2654        LogFile "-------------" 
2655    fi
2656fi
2657
2658FLOPPY_WAS_MOUNTED=""
2659for mtpt in /media/floppy /mnt/floppy /floppy ; do
2660    if mount | grep -w $mtpt &> /dev/null ; then
2661        FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2662        umount $mtpt
2663    fi
2664done
2665
2666#
2667# If we have a USB device we need to store info
2668# and remove it from the parameters line
2669#
2670if [ "$#" -ne "0" ] ; then
2671    if [ "$1" = "--usb" ] ; then
2672        shift
2673        USBDEVICE=$1
2674        if [ _"$USBDEVICE" = _"" ]; then
2675            Die "No USB device specified"
2676        fi
2677        shift
2678    fi
2679fi
2680
2681if [ "$#" -ne "0" ] ; then
2682    if [ "$1" = "--findkernel" ] ; then
2683        res=`TryToFindKernelPath`
2684        # Avoids logfile content for mondo
2685        export MONDO_SHARE=""
2686        if [ "$res" = "" ] ; then
2687            MindiExit -1
2688        else
2689            echo "$res"
2690            MindiExit 0
2691        fi
2692    elif [ "$1" = "--locatedeps" ] ; then
2693        [ ! "$2" ] && Die "Please specify the binary to look at"
2694        LocateDeps $*
2695        # Avoids logfile content for mondo
2696        export MONDO_SHARE=""
2697        MindiExit $?
2698    elif [ "$1" = "--readalllink" ] ; then
2699        [ ! "$2" ] && Die "Please specify the binary to look at"
2700        shift
2701        ReadAllLink $*
2702        # Avoids logfile content for mondo
2703        export MONDO_SHARE=""
2704        MindiExit $?
2705    elif [ "$1" = "--makemountlist" ] ; then
2706        [ ! "$2" ] && Die "Please specify the output file"
2707        MakeMountlist $2
2708        CheckMountlist $2
2709        # Avoids logfile content for mondo
2710        export MONDO_SHARE=""
2711        MindiExit $?
2712    elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2713        echo "Mindi v$MINDI_VERSION"
2714        # Avoids logfile content for mondo
2715        export MONDO_SHARE=""
2716        MindiExit 0
2717    elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
2718        MONDO_TMP=$2
2719        # Change MINDI_TMP for the one provided by mondo
2720        # So that it can get back the built files
2721        if [ _"$MONDO_TMP" = _"" ]; then
2722            Die "MONDO_TMP is empty, aborting"
2723        fi
2724        if [ _"$MONDO_TMP" = _"/" ]; then
2725            Die "MONDO_TMP is /, aborting"
2726        fi
2727        mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2>> $LOGFILE
2728        rmdir $MINDI_TMP
2729        export MINDI_TMP=$MONDO_TMP
2730        mkdir -p $MINDI_TMP
2731
2732        # This is the scratch dir in mondo - subdir images
2733        MINDI_CACHE=$3
2734
2735        kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
2736###
2737### Sq-Modification...
2738### Attempt to locate kernel specific module path
2739### if module path is found then use it other wise use uname -r to set it...
2740###
2741        kernelname=`echo $kernelpath | cut -d'-' -f2-`
2742        LogAll "kernelname = $kernelname"
2743        LogAll "kernelpath = $kernelpath"
2744        if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
2745        then
2746           LogAll "Module path for ${kernelpath} not found..."
2747           LogAll "using running kernel\'s modules."
2748           kernelname=$KERVERRUN
2749        else
2750           LogAll "Using modules for kernel: ${kernelname}"
2751        fi
2752###
2753### end of Sq-Modification
2754###
2755        TAPEDEV=$5
2756        TAPESIZE=$6
2757        FILES_IN_FILELIST=$7
2758        USE_LZO=$8
2759        CDRECOVERY=$9
2760        if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
2761            IMAGE_DEVS=""
2762        else
2763            IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
2764        fi
2765        if [ "${11}" ] ; then
2766            LILO_OPTIONS=""
2767    #       LogAll "LILO will use conservative settings, to be compatible with older BIOSes."
2768        fi
2769        LAST_FILELIST_NUMBER=${12}
2770        ESTIMATED_TOTAL_NOOF_SLICES=${13}
2771        export EXCLUDE_DEVS="${14}"
2772        USE_COMP="${15}"
2773        USE_LILO="${16}"
2774        USE_STAR="${17}"
2775        INTERNAL_TAPE_BLOCK_SIZE="${18}"
2776        DIFFERENTIAL="${19}"
2777        USE_GZIP="${20}"
2778        USE_LZMA="${21}"
2779        NOT_BOOT="${22}"
2780        [ "$USE_COMP" = "" ] && USE_COMP=yes
2781        [ "$USE_GZIP" = "" ] && USE_GZIP=no
2782        [ "$USE_LZMA" = "" ] && USE_LZMA=no
2783        [ "$NOT_BOOT" = "" ] && NOT_BOOT=no
2784        [ "$TAPEDEV" ] && LogAll "This is a tape-based backup. Fine."
2785        [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
2786        kernelname=`echo $kernelpath | cut -d'-' -f2-`
2787        if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
2788        then
2789           LogAll "Module path for ${kernelpath} not found..."
2790           LogAll "using running kernel\'s modules."
2791           kernelname=$KERVERRUN
2792        else
2793           LogAll "Using modules for kernel: ${kernelname}"
2794        fi
2795        # MONDO_ROOT is the real scratchdir
2796        MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
2797        if [ _"$MONDO_ROOT" != _"" ]; then
2798            mkdir -p $MONDO_ROOT
2799        else
2800            Die "MONDO_ROOT is undefined"
2801        fi
2802    else
2803        LogScreen "Syntax: mindi (--custom ....)"
2804        MindiExit -1
2805    fi
2806fi
2807
2808if [ _"$MINDI_CACHE" != _"" ]; then
2809    rm -rf $MINDI_CACHE/* 2> /dev/null
2810    mkdir -p $MINDI_CACHE
2811fi
2812
2813[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2814
2815if [ _"$MONDO_SHARE" = _"" ]; then
2816    LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
2817    LogAll "Latest Mindi is available from http://www.mondorescue.org"
2818    LogAll "------------------------------------------------------------------------------"
2819else
2820    LogFile "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" 
2821fi
2822# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
2823insmod /lib/modules/$KERVERRUN/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
2824for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
2825    insmod $i >> $LOGFILE 2>> $LOGFILE
2826done
2827
2828KERN_DISK_MADE=""
2829
2830LogFile "DIFFERENTIAL = $DIFFERENTIAL" 
2831LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE" 
2832LogFile "NOT_BOOT = '$NOT_BOOT'" 
2833if [ "$NOT_BOOT" != "" ] && [ "$NOT_BOOT" != "0" ] && [ "$NOT_BOOT" != "no" ] ; then
2834    LogAll "Just creating mondo-restore.cfg and a small all.tar.gz for Mondo. Nothing else."
2835    MakeMondoConfigFile $MINDI_TMP/mondo-restore.cfg
2836    MakeMountlist $MINDI_TMP/mountlist.txt
2837    CheckMountlist $MINDI_TMP/mountlist.txt
2838    mkdir -p $MINDI_TMP/small-all/tmp
2839    cd $MINDI_TMP/small-all
2840    cp -f $MINDI_TMP/{mountlist.txt,mondo-restore.cfg,filelist.full.gz,biggielist.txt} tmp 2>> $LOGFILE || Die "Cannot copy small all.tar.gz"
2841    tar -cv ./tmp | gzip -9 > $MINDI_TMP/all.tar.gz 2>> $MINDI_TMP/$$.log || Die "Cannot make small all.tar.gz" $MINDI_TMP/$$.log
2842    sleep 2
2843    LogAll "Done. Exiting."
2844    MindiExit 0
2845fi
2846
2847if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2848    LogAll "Including the generation of a Bootable USB device on $USBDEVICE"
2849fi
2850
2851if [ "$kernelpath" = "" ] ; then
2852    [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
2853    echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2854    read ch
2855    if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2856        USE_OWN_KERNEL="yes"
2857    else
2858        USE_OWN_KERNEL="no"
2859    fi
2860    if [ "$USE_OWN_KERNEL" = "yes" ]; then
2861        YOUR_KERNEL_SUCKS=""
2862        kernelpath=`TryToFindKernelPath`
2863        if [ "$kernelpath" = "" ] ; then
2864            echo -n "Please enter kernel path : "
2865            read kernelpath
2866        fi
2867    else
2868        YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
2869    fi
2870fi
2871if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
2872    # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2873    if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
2874        source $MINDI_LIB/FindDistroFailsafe
2875        # Log kernel image
2876        LogAll "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2877        kernelpath="$FAILSAFE_KBIN"
2878        LogAll "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
2879        LogAll "The failsafe kernel is $kernelpath.\n"
2880        LogAll "However, you are still running your kernel. If Mindi fails to create your\n"
2881        LogAll "disks then it may still be a result of a problem with your kernel.\n"
2882        pwd=`pwd`
2883        cd $MINDI_TMP
2884        mkdir -p lib/modules
2885        cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
2886        cd $pwd
2887    else
2888        kernelpath=$MINDI_LIB/vmlinuz
2889        LogAll "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
2890        LogAll "However, you are still running your kernel. If Mindi fails to create your"
2891        LogAll "disks then it may still be a result of a problem with your kernel."
2892        pwd=`pwd`
2893        cd $MINDI_TMP
2894        bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
2895        cd $pwd
2896    fi
2897    YOUR_KERNEL_SUCKS="Your kernel sucks"
2898fi
2899LogFile "Mindi's temp dir=$MINDI_TMP"
2900LogFile "Mindi's output dir=$MINDI_CACHE" 
2901[ "$(($RANDOM%64))" -eq "0" ] && LogAll "Dude, I've looked inside your computer and it's really dusty..."
2902
2903[ "$YOUR_KERNEL_SUCKS" ] && [ ! "$FAILSAFE_KVER" ] && Die "Please install mindi-kernel package. You need it.\nGo to http://www.mondorescue.org and download it, then install it."
2904
2905PrepareDataDiskImages
2906
2907ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
2908rds=$(($ramdisk_size-$((ramdisk_size%4096))))
2909export ramdisk_size=$rds
2910
2911LogFile "Ramdisk will be $ramdisk_size KB" 
2912if [ "$ARCH" = "ia64" ] ; then
2913    PrepareBootDiskImage_LILO $kernelpath || Die "Failed to create ia64 image disk image."
2914else
2915    PrepareBootDiskImage_ISOLINUX $kernelpath || Die "Failed to create $ramdisk_size MB disk image."
2916fi
2917
2918[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
2919...Or type 'memtest' to test your PC's RAM thoroughly.\n"
2920
2921if [ _"$MONDO_SHARE" = _"" ]; then
2922    ListImagesForUser
2923    OfferToMakeBootableISO
2924    if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
2925        OfferToMakeBootableUSB
2926    fi
2927    LogAll "Finished."
2928elif [ "$TAPEDEV" ] ; then
2929    if [ "$ARCH" != "ia64" ] ; then
2930        # We need to keep the img file as boot file for ia64 platform
2931        rm -f $MINDI_CACHE/{*img,*iso}
2932    else
2933        rm -f $MINDI_CACHE/*iso
2934    fi
2935    if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2936        OfferToMakeBootableUSB
2937    fi
2938    OfferToMakeBootableISO
2939    if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
2940        cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
2941    else
2942        Die "Cannot find all.tar.gz, to be written to tape"
2943    fi
2944elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2945    OfferToMakeBootableUSB
2946else
2947    OfferToMakeBootableISO
2948fi
2949# cleanup
2950LogAll "$FRIENDLY_OUTSTRING"
2951for mtpt in $FLOPPY_WAS_MOUNTED ; do
2952    mount $mtpt
2953done
2954MindiExit 0
Note: See TracBrowser for help on using the repository browser.