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

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

Try to add USB support for mondoarchive with new functions

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