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

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