source: MondoRescue/branches/stable/mindi/mindi@ 1097

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

Fix messages in mindi reventing its use with mondo (-V option)

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