source: MondoRescue/branches/2.2.3/mindi/mindi@ 1336

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

mindi log file only added to mondo logfile when useful (for --custom not for other options)

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