source: MondoRescue/branches/2.2.8/mindi/mindi@ 2794

Last change on this file since 2794 was 2794, checked in by Bruno Cornec, 13 years ago

r2165@localhost (orig r2164): bruno | 2009-03-14 00:22:18 +0100
Avoids a bug at restore time where dyn. lib. have to be found in a nosegneg dir. By removing the extra ld.so.conf.d file we avoid that.


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