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

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

Linker fixes for mondo
mount in logfile added for mindi

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