source: MondoRescue/branches/2.2.5/mindi/mindi@ 1565

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