source: MondoRescue/branches/stable/mindi/mindi@ 959

Last change on this file since 959 was 959, checked in by Bruno Cornec, 17 years ago

parted2fdisk.log handled later to allow for a good variable initialization

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