source: branches/2.2.10/mindi/mindi @ 2816

Last change on this file since 2816 was 2816, checked in by Bruno Cornec, 9 years ago

svn merge (in svk) -r 2714:2773 2.2.9 in 2.2.10

r4207@localhost (orig r2716): bruno | 2011-02-03 01:29:51 +0100

  • Increase boot size again to support better fedora 13/14


r4208@localhost (orig r2717): bruno | 2011-02-12 15:43:36 +0100

  • Excluding vmhgfs FS for VMWare guests mounting areas of the host.


r4209@localhost (orig r2718): bruno | 2011-02-18 00:30:35 +0100
-Extend EXTRA-SIZE for Debian 6.0 (at least)


r4210@localhost (orig r2719): bruno | 2011-02-18 00:45:40 +0100

  • Fix #462 (removes temp dir if analyze-my-lvm launched in stand alonae mode)


r4213@localhost (orig r2722): bruno | 2011-02-25 18:44:47 +0100

  • Fixes for RHEL6 support at least around dm extensions, bnx2x and cp210x dependencies


r4214@localhost (orig r2723): bruno | 2011-02-25 19:00:17 +0100

  • Adds a restore quiet option


r4215@localhost (orig r2724): bruno | 2011-02-25 19:43:50 +0100

  • Adds support for dm-log used on RHEL6 as well.


r4216@localhost (orig r2725): bruno | 2011-02-25 21:26:54 +0100

  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3


r4217@localhost (orig r2726): bruno | 2011-02-26 11:38:29 +0100

  • Fix error introduced in previous patch in the if/then/else case without member in the then


r4218@localhost (orig r2727): bruno | 2011-02-26 12:05:33 +0100

  • With mindi-busybox 1.18.3 the syntax of openvt changed. This patch keeps a compatible init script for both previous and current version.


r4219@localhost (orig r2728): bruno | 2011-02-26 15:27:40 +0100

  • Latest lvdisplay print MiB instead of MB. Impact on analyze-my-lvm fixed.


r4220@localhost (orig r2729): bruno | 2011-02-26 16:39:32 +0100

  • Adds feature rpc to mindi-busybox in case of need



r4221@localhost (orig r2730): bruno | 2011-02-26 16:42:43 +0100

  • Adds the rebot command to the list of mandatory ones at restore time


r4222@localhost (orig r2731): bruno | 2011-02-26 17:37:13 +0100

  • Adds functions and /bin/loadkeys (new location) to minimal set of commands to have
  • provides a makemessage option to mindi and this function now works with pbdistrocheck
  • Do not create an error when a phys device has 0 size and is a /dev/dm-* device


r4223@localhost (orig r2732): bruno | 2011-02-26 19:07:43 +0100

  • Syntax fix


r4224@localhost (orig r2733): bruno | 2011-02-26 19:51:16 +0100

  • Fix test on dm which was made in wrong sense
  • Adds a driver to allow raid456 to work


r4225@localhost (orig r2734): bruno | 2011-02-26 20:55:00 +0100

  • Fix 2 redirections issues


r4317@localhost (orig r2737): bruno | 2011-03-13 13:12:57 +0100

  • Add support for libahci driver, mandatory for debian 6.


r4318@localhost (orig r2738): bruno | 2011-03-13 14:46:37 +0100

  • Update from Lester Wade (lester.wade_at_hp.com) incorporating latest ML feedbacks


r4319@localhost (orig r2739): bruno | 2011-03-13 17:49:15 +0100

  • Updated Lab for TES 2011


r4323@localhost (orig r2743): bruno | 2011-03-20 01:37:40 +0100

  • Fix a seg fault bug when using the GUI in case exclude_paths was NULL (mc_at_carreira.com.pt)


r4324@localhost (orig r2744): bruno | 2011-03-20 19:38:14 +0100

  • Adds Arch Linux Keyboard support (mc_at_carreira.com.pt)


r4325@localhost (orig r2745): bruno | 2011-03-20 19:48:01 +0100

  • Avoids coredump again when exclude_path is NULL with mr_make_devlist_from_pathlist (feedback from mc_at_carreira.com.pt)


r4326@localhost (orig r2746): bruno | 2011-03-20 19:39:47 +0100

  • Remove blkid from busybox to solve #435


r4327@localhost (orig r2747): bruno | 2011-03-20 19:43:22 +0100

  • Adds reboot to fix #435


r4328@localhost (orig r2748): bruno | 2011-03-22 00:58:07 +0100

  • Fix Arch Linux kbd printed in log file now instead of screen.


r4329@localhost (orig r2749): bruno | 2011-03-22 00:59:58 +0100

  • Again increase size for boot env to support better fedora 14 and other latest distros


r4356@localhost (orig r2750): bruno | 2011-03-25 19:30:01 +0100

  • Improve Arch Linux support for mindi tools (mc_at_carreira.com.pt)


r4357@localhost (orig r2751): bruno | 2011-03-25 19:48:33 +0100

  • Accept to work with either wodim or cdreord and genisoimage or mkisofs


r4358@localhost (orig r2752): bruno | 2011-03-25 20:20:49 +0100

  • Documents option -v of mondoarchive


r4359@localhost (orig r2753): bruno | 2011-03-29 01:34:30 +0200

  • Use modprobe instead of insmod to load loop, cd, ... modules (in order to force them at rstore time). Also drop very old aes support for mdk 9.2


r4360@localhost (orig r2754): bruno | 2011-03-29 01:38:49 +0200

  • Arch Linux support for boot message of mindi (mc_at_carreira.com.pt) using /etc/arch-release and pacman.log


r4383@localhost (orig r2755): bruno | 2011-04-07 09:49:38 +0200

  • Adds a UdevadmTrigger? function at restore time to deal with the various syntax formats changes ddepending on version (mc_at_carreira.com.pt)


r4384@localhost (orig r2756): bruno | 2011-04-07 10:05:24 +0200

  • Increase again sizes for Debian 6 support (victor.gattegno_at_hp.com)


r4385@localhost (orig r2757): bruno | 2011-04-07 10:13:00 +0200
Conform to the report of size really !


r4386@localhost (orig r2758): bruno | 2011-04-07 11:31:12 +0200

  • Improved message for Arch Linux for rebuilding the initrd (mc_at_carreira.com.pt)


r4390@localhost (orig r2759): bruno | 2011-04-12 01:15:00 +0200

  • Typo in Web site


r4392@localhost (orig r2761): bruno | 2011-04-14 00:23:38 +0200

  • Adds download references for latest versions.


r4394@localhost (orig r2763): bruno | 2011-04-16 00:35:08 +0200

  • Adds support for MT back mandatory for OBDR.


r4395@localhost (orig r2764): bruno | 2011-04-20 12:18:46 +0200
Function resize_drive_proportionately_to_suit_new_drives

  • Integrate some mr_asprintf
  • Use systematically long long data types in all computation to match the struct mountlist_reference size member and have correct precision
  • Apply JB general_at_itpsg.com patch to make the partition resizing work properly according to the drive size (keeping all calculation in KB and converting only for display)


r4396@localhost (orig r2765): bruno | 2011-04-21 11:20:58 +0200

  • Remove very old code creating confusing symlinks pico to nano in init (patch from MC). Fix #477


r4397@localhost (orig r2766): bruno | 2011-04-21 11:57:44 +0200

  • text's are properly centered in open_and_list_dir (Patch from Chucky). Fix #404.


r4398@localhost (orig r2767): bruno | 2011-04-21 12:49:40 +0200

  • Attempt to fix #432 with a better message at a start.


r4399@localhost (orig r2768): bruno | 2011-04-21 13:00:37 +0200

Log content of mondo-restore.cfg


r4400@localhost (orig r2769): bruno | 2011-04-21 13:48:52 +0200

  • Introduce a new bkpinfo member (subdir) to support storing the subdir under which ISO images are stored on an external HDD. Should fix mostly #433.


r4401@localhost (orig r2770): bruno | 2011-04-21 14:14:52 +0200

  • Fix compilation issues due to level of visibility of functions


r4402@localhost (orig r2771): bruno | 2011-04-22 01:49:03 +0200

  • Adds GUI support for compresion type. Fix half of #468.


r4403@localhost (orig r2772): bruno | 2011-04-22 02:00:07 +0200

  • Adds support of ext attr through the GUI. Fix second part of #468


r4404@localhost (orig r2773): bruno | 2011-04-22 02:22:24 +0200

  • Propose more variables in the mindi.conf example
  • More explicit messages when size unsufficient in mindi for kernel + initrd as per #471
  • Better loging of labeling in mondo when in nuke mode


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