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

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