source: MondoRescue/branches/2.2.4/mindi/mindi@ 1526

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