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

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

Fix a bug in mindi for the FAILSAFE support (Scott Cummings <rsc_at_usfamily.net>)

  • Property svn:keywords set to Rev Id
File size: 112.6 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 1163 2007-02-14 19:08:25Z 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 $MONDORESTORECFG $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 if [ _"$MONDORESTORECFG" != _"" ]; then
2246 i=`grep bootloader.device $MONDORESTORECFG | cut -d'=' -f2 2> /dev/null`
2247 if [ "$i" ] ; then
2248 LogIt "Backing up $i's MBR"
2249 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
2250 sleep 1
2251 sync
2252 j=$i
2253 [ -h "$j" ] && j=`readlink -f $j`
2254 LogIt "Creating /dev/boot_device ($j)"
2255 mkdir -p $bigdir/dev
2256 cp -pRdf $j $bigdir/dev/boot_device 2> /dev/null || Die "Unable to create /dev/boot_device on ramdisk"
2257 fi
2258 fi
2259
2260 old_pwd=`pwd`
2261 cd $bigdir
2262
2263 [ -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'."
2264 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping aux-tools"
2265 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then
2266 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping x11-tools.tgz"
2267 fi
2268 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
2269 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
2270 [ "$?" -ne "0" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
2271 fi
2272 [ -d "/lib/dev-state" ] && cp --parents -pRdf /lib/dev-state . 2>> $LOGFILE
2273 cd $old_pwd
2274 echo -e "$DONE"
2275 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
2276 SplitDirectoryIntoMinidirs $bigdir $minidir_root
2277 noof_disks=$?
2278 [ "$noof_disks" -eq "0" ] && Die "Too much stuff!"
2279 MakeMountlist $MINDI_TMP/mountlist.txt
2280 mkdir -p $minidir_root/$noof_disks/tmp
2281 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"
2282 if [ _"$MONDO_SHARE" != _"" ]; then
2283 cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2284 fi
2285 [ $LVM != "false" ] && $MINDI_LIB/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm || LVM="false"
2286 cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE
2287 ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks
2288 CreateDataDiskImagesFromTarballs $tardir $imagesdir $noof_disks
2289 FRIENDLY_OUTSTRING="Boot and data disk images were created."
2290 # One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images
2291 rmdir $tardir $bigdir
2292 rm -f $needlist
2293 return $noof_disks
2294}
2295
2296
2297ProcessLDD() {
2298 local main_fname incoming j i fname f newf
2299 main_fname=$1
2300 read incoming
2301 while [ "$incoming" != "" ] ; do
2302 # We take the full path name of the dyn. lib. we want
2303 incoming=`echo "$incoming" | sed '/[[:blank:]]*.*[[:blank:]]*=>[[:blank:]]*(.*/d ; s/[[:blank:]]*.*[[:blank:]]*=>[[:blank:]]*\(\/.*\)/\1/ ; s/[[:blank:]]*\(\/.*\)[[:blank:]]*(.*/\1/'`
2304 for f in `echo "$incoming"` ; do
2305 echo "$f `ReadAllLink $f`"
2306 done
2307 read incoming
2308 done
2309}
2310
2311
2312Prompt() {
2313 echo -en "$1"
2314 read line
2315}
2316
2317
2318ReadLine() {
2319 local i incoming
2320 read incoming
2321 i=0
2322 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
2323 i=$(($i+1))
2324 read incoming
2325 done
2326 echo "$incoming"
2327}
2328
2329
2330RejigHyperlinks() {
2331 local minidir_root noof_disks fname path diskno old_pwd awk_loc gawk_loc dir i
2332 minidir_root=$1
2333 noof_disks=$2
2334
2335 old_pwd=`pwd`
2336 diskno=1
2337 while [ "$diskno" -le "$noof_disks" ] ; do
2338 mkdir -p $minidir_root/$diskno
2339 cd $minidir_root/$diskno
2340 for fname in `find -type d -o -print` ; do
2341 [ -h "$minidir_root/$diskno/$fname" ] && MoveHyperlinkSensibly $fname $minidir_root $diskno $noof_disks
2342 done
2343 diskno=$(($diskno+1))
2344 done
2345
2346 cd $old_pwd
2347 return
2348}
2349
2350
2351ReplaceIndividualLine() {
2352 local orig_file new_file lino newstring lines_total lines_remaining
2353
2354 orig_file=$1.orig
2355 mv -f $1 $orig_file || Die "Cannot move $1 to $orig_file"
2356 new_file=$1
2357 lino=$2
2358 newstring="$3"
2359 if [ "$lino" = "" ] || [ "$lino" -lt "1" ] ; then
2360 echo "Can't find string" >> $LOGFILE
2361 return 1
2362 fi
2363 lines_total=`wc -l $orig_file | $AWK '{print $1;}'`
2364 lines_remaining=$(($lines_total-$lino))
2365 head -n$(($lino-1)) $orig_file > $new_file
2366 echo "$newstring" >> $new_file
2367 echo "# The above line was added by Mindi, at the user's instruction" >> $new_file
2368 tail -n$lines_remaining $orig_file >> $new_file
2369 echo "Replace line $lino of $new_file with user-specified line, '$newstring'" >> $LOGFILE
2370 [ -x "$orig_file" ] && chmod +x $new_file
2371 rm -f $orig_file
2372 return 0
2373}
2374
2375
2376ScanCDandTape() {
2377 local i
2378
2379 for i in /dev/st0 /dev/ht0 /dev/cdrom /dev/cdrom0 /dev/cdrom 1 ; do
2380 dd if=$i of=/dev/null bs=64k count=1 &> /dev/null
2381 done
2382}
2383
2384
2385SizeOfPartition() {
2386 local devpath drive res stub
2387 device=$1
2388 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2389 res=`SizeOfRaidPartition $device`
2390 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2391 echo "$res"
2392 return 0
2393 fi
2394 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2395 res=`$FDISK -s $device 2>> $LOGFILE`
2396 # end patch
2397 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`
2398 [ "$res" = "" ] && res="-1"
2399 echo $res
2400 return 0
2401}
2402
2403
2404SizeOfRaidPartition() {
2405 local real_dev smallest_size silly tmp
2406
2407 silly=999999999
2408 smallest_size=$silly
2409
2410 for real_dev in `GetRaidDevMembers $1` ; do
2411 tmp=`SizeOfPartition $real_dev`
2412 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2413 done
2414
2415 if [ "$smallest_size" = "$silly" ] ; then
2416 echo "-1"
2417 return 1
2418 else
2419 echo "$smallest_size"
2420 return 0
2421 fi
2422}
2423
2424
2425StripComments()
2426{
2427 local tempfile
2428
2429 tempfile=$MINDI_TMP/$$.strip.txt
2430 cp -f $1 $tempfile 2>> $LOGFILE
2431 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2432 rm -f $tempfile
2433 echo "Stripped comments from $2" >> $LOGFILE
2434}
2435
2436
2437SplitDirectoryIntoMinidirs() {
2438 local bigdir minidir_root i noof_disks old_pwd res
2439
2440 bigdir=$1
2441 minidir_root=$2
2442 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
2443
2444 TryToFitDataIntoSeveralDirs $bigdir $minidir_root
2445 noof_disks=$?
2446 if [ "$noof_disks" -eq "0" ] ; then
2447 echo "Failed to fit data into several dirs."
2448 return 0
2449 fi
2450 RejigHyperlinks $minidir_root $noof_disks
2451 [ "$bigdir" != "" ] && rm -Rf $bigdir/*
2452 return $noof_disks
2453}
2454
2455
2456StripExecutable()
2457{
2458 local tmpfile
2459
2460 tmpfile=$MINDI_TMP/stripped.$$.dat
2461 [ -d "$1" ] || [ -h "$1" ] && return
2462 cp -f $1 $tmpfile 2>> $LOGFILE
2463 strip $tmpfile 2> /dev/null
2464 if [ "$?" -eq "0" ] ; then
2465 cp -f $tmpfile $1 2>> $LOGFILE
2466 echo "Stripped binary $2" >> $LOGFILE
2467 fi
2468 rm -f $tmpfile
2469}
2470
2471
2472TemporarilyCompressAllFiles() {
2473 local i orig_fname out_fname out_list
2474
2475 i=0
2476 out_list=$2/compressed/compressed.txt
2477 mkdir -p $2/compressed
2478 > $out_list
2479 for orig_fname in $1 ; do
2480 out_fname=$2/compressed/$orig_fname.gz
2481 mkdir -p $out_fname 2> /dev/null
2482 rmdir $out_fname 2> /dev/null
2483 gzip -c6 $orig_fname > $out_fname 2> /dev/null
2484 i=$(((($i+1))%15))
2485 [ "$i" -eq "0" ] && echo -en "."
2486 du -sk $out_fname >> $out_list
2487 done
2488}
2489
2490
2491TryToFindKernelPath() {
2492 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2493
2494 we_want_version=`uname -r`
2495 possible_kernels=""
2496 duff_kernels=""
2497
2498 if [ "$ARCH" = "ia64" ] ; then
2499 root="/boot/efi/efi"
2500 else
2501 root="/"
2502 fi
2503 for fname in `find $root -maxdepth 2 -type f | grep -F lin | grep -Ev '^/proc/|^/net/'` ; do
2504 [ ! -e "$fname" ] && continue
2505 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2506 file $fname | grep -q gzip
2507 if [ "$?" -eq "0" ] ; then
2508 # Used by ia64
2509 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2510 else
2511 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2512 fi
2513 [ "$fkern_ver" = "" ] && continue
2514 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2515 [ -f "$fname" ] || continue
2516 [ -h "$fname" ] && continue
2517 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2518 file $fname | grep -q gzip
2519 if [ "$?" -eq "0" ] ; then
2520 # Used by ia64
2521 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2522 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2523 duff_kernels="$fname $duff_kernels"
2524 else
2525 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2526 possible_kernels="$fname $possible_kernels"
2527 fi
2528 else
2529 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2530 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2531 duff_kernels="$fname $duff_kernels"
2532 else
2533 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2534 possible_kernels="$fname $possible_kernels"
2535 fi
2536 fi
2537 done
2538 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2539 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2540 fi
2541 if [ ! "$possible_kernels" ] ; then
2542 LogIt "No kernel matches exactly. Are there any duff kernels?"
2543 possible_kernels="$duff_kernels"
2544 if [ ! "$possible_kernels" ] ; then
2545 LogIt "Sorry, no duff kernels either"
2546 else
2547 LogIt "I bet you're running Debian or Gentoo, aren't you?"
2548 LogIt "Your kernel doesn't have a sane builddate. Oh well..."
2549 fi
2550 fi
2551 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2552 noof_kernels=`CountItemsIn "$possible_kernels"`
2553 if [ "$noof_kernels" -eq "0" ] ; then
2554 LogIt "Could not find your kernel."
2555 if [ -e "/boot/vmlinuz" ] ; then
2556 LogIt "Using /boot/vmlinuz as a last resort."
2557 output=/boot/vmlinuz
2558 else
2559 output=""
2560 fi
2561 elif [ "$noof_kernels" -eq "1" ] ; then
2562 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2563 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE
2564 output="$kernelpath"
2565 else
2566 for i in $possible_kernels ; do
2567 if echo $i | grep "`uname -r`" ; then
2568 LogIt "OK, I used my initiative and found that "
2569 LogIt "$i is probably your kernel. "
2570 output="$i"
2571 return
2572 fi
2573 done
2574 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2575 output=/boot/vmlinuz
2576 echo "Schlomo, this one's for you." >> $LOGFILE
2577 else
2578 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2579 LogIt "boot disks will still work, probably. If one does not work, try another."
2580 LogIt "$possible_kernels"
2581 echo ""
2582 fi
2583 fi
2584 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2585}
2586
2587
2588TryToFitDataIntoSeveralDirs() {
2589 local bigdir minidir_root noof_disks diskno list_of_files filename old_pwd progress
2590 local i retval noof_disks total_files list_of_devs
2591
2592 bigdir=$1
2593 minidir_root=$2
2594 BIG_CLUNKY_SIZE_COUNTER=0
2595 retval=0
2596 noof_disks=1
2597
2598 echo -en "\r \rDividing data into several groups..."
2599 old_pwd=`pwd`
2600 cd $bigdir
2601 list_of_files=`GetFileSizeList . | sort -nr | cut -f2 | grep -Fv "/dev/"`
2602 progress=0
2603 total_files=`CountItemsIn "$list_of_files"`
2604 if [ "`echo "$filename" | grep -x "/dev/.*"`" ] ; then
2605 filesize=1
2606 fi
2607 mkdir -p $minidir_root/$noof_disks
2608 if [ -e "dev" ] ; then
2609 echo "Copying dev/* to $minidir_root/$noof_disks" >> $LOGFILE
2610 cp --parents -pRdf dev $minidir_root/$noof_disks 2>> $LOGFILE
2611 fi
2612 TemporarilyCompressAllFiles "$list_of_files" $minidir_root
2613 for filename in $list_of_files ; do
2614 AddFileToDir $filename $minidir_root $noof_disks
2615 i=$?
2616 if [ "$i" -gt "$noof_disks" ] ; then
2617 noof_disks=$i
2618 echo -en "\r\t\t\t\t\t\t($noof_disks disks)"
2619 fi
2620 if [ "$i" -eq "0" ] ; then
2621 LogIt "Cannot add file $filename to minidir $minidir_root"
2622 retval=$(($retval+1))
2623 fi
2624 progress=$(($progress+1))
2625 echo -en "\r\t\t\t\t\t\t\t\t$(($progress*100/$total_files))% complete\r"
2626 done
2627 cd $old_pwd
2628 echo -en "\rThe files have been subdivided into $noof_disks directories. \r"
2629 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/compressed
2630 if [ "$retval" -gt "0" ] ; then
2631 return 0
2632 else
2633 return $noof_disks
2634 fi
2635}
2636
2637
2638TurnTgzIntoRdz() {
2639 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
2640
2641 tgz_dir_fname=$1
2642 rdz_fname=$2
2643 ramdisksize=$3
2644 disksize=$4
2645 kernelsize=$5
2646 maxsize=$(($disksize-$kernelsize))
2647 maxsize=$(($maxsize*2)); # to allow for compression of 50%
2648 tempfile=$MINDI_TMP/temp.rd
2649 mountpoint=$MINDI_TMP/mnt1
2650 res=0
2651 echo -en "..."
2652 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"
2653 echo -en "..."
2654 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
2655 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE
2656 echo -en "..."
2657 mkdir -p $mountpoint
2658 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."
2659 echo -en "..."
2660 old_pwd=`pwd`
2661 cd $mountpoint
2662 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
2663 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
2664 cd dev || Die "Can't cd to dev"
2665 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2666 rm -f dev-entries.tgz
2667 cd ..
2668
2669 for w in insmod.static insmod.static.old ; do
2670 s=`which $w 2> /dev/null`
2671 if [ -e "$s" ] ; then
2672 cp --parents -af $s . 2>> $LOGFILE
2673 fi
2674 done
2675
2676 mkdir -p tmp
2677 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2678 for w in cdrom floppy groovy-stuff ; do
2679 mkdir -p mnt/$w
2680 done
2681 #if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then
2682 #ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"
2683 #fi
2684 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
2685 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
2686 fi
2687
2688 lsmod > tmp/original-lsmod.txt
2689
2690 cp --parents -Rdf /dev/fd0*[1,2][4,7,8]* . 2> /dev/null
2691 cd $old_pwd
2692 echo -en "..."
2693 MakeModuleLoadingScript $TMPMODPROBE_FLAG $mountpoint/sbin/insert-all-my-modules
2694 echo -en "..."
2695 old_pwd=`pwd`
2696 if [ "$YOUR_KERNEL_SUCKS" ] ; then
2697 cd $MINDI_TMP
2698 floppy_modules_path=lib/modules/$FAILSAFE_KVER
2699 else
2700 cd /
2701###
2702### Sq-Modification... Use kernel name in module path if specified.
2703###
2704 #floppy_modules_path=lib/modules/`uname -r`
2705 if [ "${kernelname}" != "" ]
2706 then
2707 floppy_modules_path=lib/modules/${kernelname}
2708 else
2709 floppy_modules_path=lib/modules/`uname -r`
2710 fi
2711###
2712### Sq-Modification end
2713###
2714 fi
2715 floppy_modules=""
2716 if [ "$disksize" -lt "2880" ] ; then
2717 list_of_groovy_mods="$FLOPPY_MODS $IDE_MODS ide-scsi sr_mod cdrom isocd isofs `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
2718 else
2719 list_of_groovy_mods="$CDROM_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
2720 fi
2721 if [ "$NFS_DEV" != "" ] ; then
2722 # For PXE boot
2723 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2724 fi
2725 [ -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."
2726 for i in $list_of_groovy_mods ; do
2727 floppy_modules="$floppy_modules `FindSpecificModuleInPath $floppy_modules_path $i`"
2728 done
2729 for i in $floppy_modules ; do
2730 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2731 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
2732 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
2733 cp -df $i $mountpoint/ 2>/dev/null || LogIt "Unable to copy $i to $mountpoint"
2734 [ "`echo "$i" | grep -F ".gz"`" ] && gunzip -f $mountpoint/`basename $i`
2735 done
2736 if [ ! -e "/sbin/devfsd" ] || [ "$disksize" -lt "2880" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
2737 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE
2738 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE
2739 [ "$disksize" -lt "2880" ] && echo "...because disksize = $disksize" >> $LOGFILE
2740 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE
2741 rm -f $mountpoint/sbin/devfsd
2742 fi
2743 cd $old_pwd
2744 [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
2745 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2746 rm -f $mountpoint/zero
2747 mkdir -p $mountpoint/tmp
2748 if [ _"$MONDO_SHARE" != _"" ]; then
2749 cp -f $MONDO_CACHE/mondo-restore.cfg $mountpoint/tmp &> /dev/null || Die "Cannot copy mondo-restore.cfg to ramdisk"
2750 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
2751 fi
2752 mkdir -p $mountpoint/proc
2753 echo "$disksize" > $mountpoint/tmp/$disksize.siz
2754 find $mountpoint -name CVS -exec rm -rf '{}' \;
2755 # Determine what filesystem to use for initrd image
2756 echo "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." >> $LOGFILE
2757 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2758 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2759 case "$gvFileSystem" in
2760 "ext2fs")
2761 # say what will be used
2762 echo "Creating an ext2 initrd image..." >> $LOGFILE
2763 # kernel expects linuxrc in ext2 filesystem
2764 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2765 # unmount loop filesystem and create image file using the standard approach
2766 umount $mountpoint || Die "Cannot unmount $tempfile"
2767 dd if=$tempfile bs=1k 2> /dev/null | gzip -v9 > $rdz_fname 2> /dev/null
2768 # log that we are done
2769 echo "...done." >> $LOGFILE
2770 ;;
2771 "initramfs")
2772 # say what will be used
2773 echo "Creating a gzip'ed cpio (AKA initramfs) initrd image..." >> $LOGFILE
2774 # make sure that cpio is there
2775 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2776 # go into filesystem
2777 cd $mountpoint
2778 # kernel expects init in cpio filesystem
2779 ln -sf sbin/init init
2780 # create cpio image file and unmount loop filesystem
2781 find . -print | cpio -o -H newc | gzip -9 > $old_pwd/$rdz_fname 2> /dev/null
2782 cd $old_pwd
2783 umount $mountpoint || Die "Cannot unmount $tempfile"
2784 # log that we are done
2785 echo "...done." >> $LOGFILE
2786 ;;
2787 *)
2788 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2789 ;;
2790 esac
2791 if [ "$res" -eq "0" ] ; then
2792 echo -en "..."
2793 else
2794 echo -en "\rMade an rdz WITH ERRORS. \n"
2795 fi
2796 return 0
2797}
2798
2799
2800WhichOfTheseModulesAreLoaded() {
2801 local modname loaded_modules
2802 loaded_modules=" `lsmod | tr -s ' ' '\t' | cut -f1 | grep -Fvx "Modules" | tr '\n' ' '` "
2803 for modname in $1 ; do
2804 [ "`echo "$loaded_modules" | grep -F " $modname "`" ] && echo "$modname"
2805 done
2806}
2807
2808
2809ZipMinidirsIntoTarballs() {
2810 local minidir_root tardir noof_disks diskno old_pwd i
2811 minidir_root=$1
2812 tardir=$2
2813 noof_disks=$3
2814
2815 echo -en "Tarring and zipping the group`PluralOrNot $noof_disks`..."
2816 mkdir -p $tardir
2817 mkdir -p $minidir_root/all
2818 old_pwd=`pwd`
2819 diskno=1
2820 while [ "$diskno" -le "$noof_disks" ] ; do
2821 cd $minidir_root/$diskno || LogIt "WARNING - cannot cd to $minidir_root/$diskno"
2822 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."
2823 diskno=$(($diskno+1))
2824 echo -n "..."
2825 cp -pRdf * $minidir_root/all 2>> $LOGFILE
2826 done
2827 mkdir -p $minidir_root/all/tmp
2828 cd $minidir_root/all
2829 size_of_all_tools=`du -sk . | cut -f1`
2830 if [ _"$MONDO_SHARE" != _"" ]; then
2831 for q in filelist.full.gz biggielist.txt ; do
2832 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
2833 cp -pRdf $MINDI_TMP/$q tmp/ 2>> $LOGFILE
2834 done
2835 mkdir -p $minidir_root/all/tmp
2836 fi
2837 tar -b 4096 -cf - * 2> /dev/null | gzip -9 > $tardir/all.tar.gz
2838 dd if=/dev/zero bs=1k count=64 >> $imagesdir/all.tar.gz 2> /dev/null
2839 [ "`du -sm $imagesdir/all.tar.gz | cut -f1`" -ge "30" ] && Die "You have too many tools in your shed"
2840 cd $old_pwd
2841 [ "$minidir_root" != "" ] && rm -Rf $minidir_root
2842 echo -e "$DONE"
2843}
2844
2845
2846##############################################################################
2847#----------------------------------- Main -----------------------------------#
2848##############################################################################
2849
2850# Now we can create what we nedd
2851mkdir -p $MINDI_TMP
2852
2853# Purge from potential old run
2854if [ _"$MINDI_CACHE" = _"" ]; then
2855 Die "MINDI_CACHE undefined"
2856fi
2857rm -rf $MINDI_CACHE 2> /dev/null
2858mkdir -p $MINDI_CACHE
2859
2860
2861if [ "$1" = "--printvar" ] ; then
2862 shift
2863 if [ _"$1" != _"" ] ; then
2864 set | egrep "^$1" | cut -d= -f2
2865 fi
2866 MindiExit 0
2867fi
2868
2869> $LOGFILE
2870echo "mindi v$MINDI_VERSION" >> $LOGFILE
2871echo "$ARCH architecture detected" >> $LOGFILE
2872echo "mindi called with the following arguments:" >> $LOGFILE
2873echo "$@" >> $LOGFILE
2874echo "Start date : `date`" >> $LOGFILE
2875echo "-----------------------------" >> $LOGFILE
2876
2877if [ -e "/etc/conf.modules" ] && [ ! -e "/etc/modules.conf" ] ; then
2878 LogIt "WARNING - Ancient distro detected." 1
2879 ln -sf /etc/conf.modules /etc/modules.conf
2880fi
2881[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2882
2883# Log some capital variables
2884[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2885echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
2886echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE
2887echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE
2888[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2889echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE
2890if [ -f $MINDI_CONF ]; then
2891 echo "-----------------------------" >> $LOGFILE
2892 echo " Mindi configuration file " >> $LOGFILE
2893 echo "-----------------------------" >> $LOGFILE
2894 cat $MINDI_CONF >> $LOGFILE
2895 echo "-----------------------------" >> $LOGFILE
2896fi
2897
2898
2899trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2900
2901# Sanity checks
2902which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2903which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2904which 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."
2905which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2906if which awk &> /dev/null ; then
2907 if ! which gawk &> /dev/null ; then
2908 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"
2909 fi
2910fi
2911which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2912[ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"
2913
2914[ "`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"
2915# If we have a 2.6 kernel, the system uses module-init-tools which means that we
2916# may have the modprobe configuration spread out across multiple files in
2917# directory /etc/modprobe.d. If this is the case we concatenate these files into
2918# a temporary file for further processing. Otherwise we continue in the standard
2919# way. Note further that in case /etc/modprobe.d exists, we use it and ignore
2920# /etc/modprobe.conf which is exactly what module-init-tools does. The temporary
2921# modprobe.conf file is created in MakeModuleLoadingScript. AL041128.
2922if [ -d "/etc/modprobe.d" ] && [ `uname -r | cut -c1-3` == "2.6" ] ; then
2923 TMPMODPROBE_FLAG="Y"
2924else
2925 TMPMODPROBE_FLAG="N"
2926 [ -e "/etc/modprobe.conf" ] && [ ! -e "/etc/modules.conf" ] && ln -sf /etc/modprobe.conf /etc/modules.conf
2927 [ ! -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..."
2928fi
2929
2930# Update the PATH variable if incomplete
2931if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2932 PATH=$PATH:/sbin:/usr/sbin
2933 export PATH
2934 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE
2935 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE
2936 echo " Or you might like to call 'su -' instead of 'su', for example." >> $LOGFILE
2937fi
2938
2939# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2940if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2941 source $MINDI_LIB/FindDistroFailsafe
2942 # Log kernel image
2943 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2944else
2945 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2946fi
2947
2948if ! which mkfs.vfat &> /dev/null ; then
2949 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2950fi
2951
2952### BERLIOS
2953### Fix as it's not mandatory on ia64
2954if [ "$ARCH" = "ia64" ] ; then
2955 if which elilo &> /dev/null ; then
2956 LILO_EXE=elilo
2957 else
2958 LILO_EXE=`which false`
2959 fi
2960else
2961 FindIsolinuxBinary
2962 FindLiloBinary
2963fi
2964trap "Aborted" SIGTERM
2965DONE="\r\t\t\t\t\t\t\t\tDone. "
2966CHOPSIZE=240
2967BIGNO=0
2968MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
2969
2970#
2971# Kernel management: Attempt to locate kernel specific module path
2972# if module path is found then use it other wise use uname -r to set it...
2973#
2974#
2975kernelpath="$mindi_kernel"
2976if [ "$kernelpath" = "NATIVE" ]; then
2977 kernelpath=""
2978fi
2979if [ "$kernelpath" = "" ]; then
2980 kernelpath=`TryToFindKernelPath`
2981fi
2982kernelname=`echo $kernelpath | cut -d'-' -f2-`
2983echo "kernelname = $kernelname" >> $LOGFILE
2984echo "kernelpath = $kernelpath" >> $LOGFILE
2985if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
2986then
2987 echo "Module path for ${kernelpath} not found..." >> $LOGFILE
2988 echo "using running kernel\'s modules." >> $LOGFILE
2989 kernelname=`uname -r`
2990else
2991 echo "Using modules for kernel: ${kernelname}" >> $LOGFILE
2992fi
2993
2994if [ -d "/proc/lvm" ]; then
2995 # LVM v1
2996 LVMCMD=""
2997 LVM="v1"
2998elif [ -d "/dev/mapper" ]; then
2999 # LVM v2
3000 LVMCMD="lvm"
3001 LVM="v2"
3002else
3003 LVM="false"
3004fi
3005echo "LVM set to $LVM" >> $LOGFILE
3006echo "----------" >> $LOGFILE
3007echo "df result:" >> $LOGFILE
3008echo "----------" >> $LOGFILE
3009df -T >> $LOGFILE
3010echo "-------------" >> $LOGFILE
3011echo "mount result:" >> $LOGFILE
3012echo "-------------" >> $LOGFILE
3013mount >> $LOGFILE
3014echo "-------------" >> $LOGFILE
3015echo "lsmod result:" >> $LOGFILE
3016echo "-------------" >> $LOGFILE
3017lsmod >> $LOGFILE
3018echo "-------------" >> $LOGFILE
3019echo "Liste of extra modules is:" >> $LOGFILE
3020echo "$EXTRA_MODS" >> $LOGFILE
3021echo "-------------" >> $LOGFILE
3022
3023
3024FLOPPY_WAS_MOUNTED=""
3025for mtpt in /media/floppy /mnt/floppy /floppy ; do
3026 if mount | grep -w $mtpt &> /dev/null ; then
3027 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
3028 umount $mtpt
3029 fi
3030done
3031
3032#
3033# If we have a USB device we need to store info
3034# and remove it from the parameters line
3035#
3036if [ "$#" -ne "0" ] ; then
3037 if [ "$1" = "--usb" ] ; then
3038 shift
3039 USBDEVICE=$1
3040 if [ _"$USBDEVICE" = _"" ]; then
3041 Die "No USB device specified"
3042 fi
3043 shift
3044 fi
3045fi
3046
3047#
3048# Default value for parameters coming from mondo potentially
3049#
3050if [ "$ARCH" = "ia64" ] ; then
3051 USE_LILO=yes
3052else
3053 USE_LILO=no
3054fi
3055
3056#
3057# These variables are normaly only significant in a mondo environment
3058# Not enforced yet
3059#
3060CDRECOVERY="no"
3061NOT_BOOT="no"
3062EXCLUDE_DEVS=""
3063IMAGE_DEVS=""
3064NFS_DEV=""
3065
3066#
3067# Deal with parameters
3068#
3069if [ "$#" -ne "0" ] ; then
3070 if [ "$1" = "--findkernel" ] ; then
3071 res=`TryToFindKernelPath`
3072 if [ "$res" = "" ] ; then
3073 MindiExit -1
3074 else
3075 echo "$res"
3076 MindiExit 0
3077 fi
3078 elif [ "$1" = "--makemountlist" ] ; then
3079 [ ! "$2" ] && Die "Please specify the output file"
3080 MakeMountlist $2
3081 MindiExit $?
3082 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
3083 echo "Mindi v$MINDI_VERSION"
3084 MindiExit 0
3085 elif [ "$1" = "--custom" ] ; then
3086 if [ _"$MONDO_SHARE" = _"" ]; then
3087 Die "--custom is reserved for mondoarchive calls"
3088 fi
3089 MONDO_TMP=$2
3090 # Change MINDI_TMP for the one provided by mondo
3091 # So that it can get back the built files
3092 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
3093 rmdir $MINDI_TMP
3094 MINDI_TMP=$MONDO_TMP
3095 mkdir -p $MINDI_TMP
3096 # This is the scratch dir in mondo
3097 MINDI_CACHE=$3
3098 if [ _"$MINDI_CACHE" != _"" ]; then
3099 mkdir -p $MINDI_CACHE
3100 fi
3101
3102 if [ ! -e "$MONDORESTORECFG" ]; then
3103 Die "MONDORESTORECFG undefined. Use an uptodate mondoarchive version"
3104 fi
3105
3106 if [ ! -e "$MONDO_CACHE" ]; then
3107 Die "MONDO_CACHE undefined. Use an uptodate mondoarchive version"
3108 else
3109 #
3110 # Get from mondo our additional configuration
3111 #
3112 echo "Using $MONDO_CACHE/mindi.conf as additional config file"
3113 if [ -f $MONDO_CACHE/mindi.conf ]; then
3114 . $MONDO_CACHE/mindi.conf
3115 echo "-----------------------------" >> $LOGFILE
3116 echo " Mondo configuration file " >> $LOGFILE
3117 echo "-----------------------------" >> $LOGFILE
3118 cat $MONDO_CACHE/mindi.conf >> $LOGFILE
3119 echo "-----------------------------" >> $LOGFILE
3120 else
3121 Die "No mindi.conf file created by mondo. Aborting"
3122 fi
3123 fi
3124
3125 echo "Here is your $MONDORESTORECFG file:" >> $LOGFILE
3126 echo "------------------------------------" >> $LOGFILE
3127 cat $MONDORESTORECFG >> $LOGFILE
3128 echo "-----------------------------------" >> $LOGFILE
3129
3130 CDRECOVERY=`grep use-cdrecovery $MONDORESTORECFG | cut -d'=' -f2`
3131 NOT_BOOT=`grep non-bootable $MONDORESTORECFG | cut -d'=' -f2`
3132 USE_LILO=`grep use-lilo $MONDORESTORECFG | cut -d'=' -f2`
3133 EXCLUDE_DEVS=`grep excluded-devs $MONDORESTORECFG | cut -d'=' -f2`
3134 NFS_DEV=`grep nfs-dev $MONDORESTORECFG | cut -d'=' -f2`
3135 VALUE=`grep image-devs $MONDORESTORECFG | cut -d'=' -f2`
3136 if [ "$VALUE" = "(null)" ] || [ "$VALUE" = "" ] ; then
3137 IMAGE_DEVS=""
3138 else
3139 IMAGE_DEVS="`echo "$VALUE" | tr '|' ' '`"
3140 fi
3141 [ "$CDRECOVERY" = "yes" ] && [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
3142 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
3143 if [ _"$MONDO_ROOT" != _"" ]; then
3144 mkdir -p $MONDO_ROOT
3145 else
3146 Die "MONDO_ROOT is undefined"
3147 fi
3148 else
3149 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
3150 MindiExit -1
3151 fi
3152fi
3153#ScanCDandTape
3154[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3155if [ "$CDRECOVERY" = "yes" ] ; then
3156 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg
3157 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg
3158else
3159 iso_cfg_file=$MINDI_LIB/isolinux.cfg
3160 sys_cfg_file=$MINDI_LIB/syslinux.cfg
3161fi
3162
3163[ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"
3164if [ _"$MONDO_SHARE" = _"" ]; then
3165 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION"
3166 LogIt "Latest Mindi is available from http://www.mondorescue.org"
3167 LogIt "BusyBox sources are available from http://www.busybox.net"
3168else
3169 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> /var/log/mondo-archive.log
3170fi
3171if [ -f $MINDI_LIB/rootfs/bin/busybox ]; then
3172 LogIt "Mindi-`$MINDI_LIB/rootfs/bin/busybox 2>&1 | head -1`"
3173else
3174 LogIt "Unable to find mindi-busybox, please install it"
3175 MindiExit -1
3176fi
3177
3178# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
3179insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
3180for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
3181 insmod $i >> $LOGFILE 2>> $LOGFILE
3182done
3183
3184KERN_DISK_MADE=""
3185
3186if [ "$NOT_BOOT" = "yes" ]; then
3187 LogIt "Just creating a small all.tar.gz for Mondo. Nothing else."
3188 mkdir -p $MINDI_TMP/small-all/tmp
3189 MakeMountlist $MINDI_TMP/small-all/tmp/mountlist.txt
3190 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"
3191 cd $MINDI_TMP/small-all
3192 tar -cv tmp | gzip -9 > $MINDI_CACHE/all.tar.gz || Die "Cannot make small all.tar.gz"
3193 sync
3194 LogIt "Done. Exiting."
3195 MindiExit 0
3196fi
3197
3198if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3199 LogIt "Including the generation of a Bootable USB device on $USBDEVICE"
3200fi
3201if [ "$kernelpath" = "" ] ; then
3202 if [ _"$MONDO_SHARE" != _"" ]; then
3203 Die "Please use -k <path> to specify kernel."
3204 fi
3205 if [ $INTERACTIVE == "yes" ]; then
3206 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
3207 read ch
3208 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
3209 USE_OWN_KERNEL="yes"
3210 fi
3211 fi
3212 if [ "$USE_OWN_KERNEL" = "yes" ]; then
3213 YOUR_KERNEL_SUCKS=""
3214 kernelpath=`TryToFindKernelPath`
3215 if [ "$kernelpath" = "" ] ; then
3216 echo -n "Please enter kernel path : "
3217 read kernelpath
3218 fi
3219 else
3220 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
3221 fi
3222fi
3223if [ _"$MONDO_SHARE" = _"" ] && [ $INTERACTIVE = "yes" ] && [ "$ARCH" != "ia64" ] ; then
3224 echo -en "Would you like to use LILO (instead of syslinux)\nfor your boot CD/floppies (y/[n]) ?"
3225 read ch
3226 if [ "$ch" = "y" ] || [ "$ch" = "Y" ] ; then
3227 USE_LILO=yes
3228 fi
3229fi
3230if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
3231 # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
3232 if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
3233 source $MINDI_LIB/FindDistroFailsafe
3234 # Log kernel image
3235 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
3236 kernelpath="$FAILSAFE_KBIN"
3237 LogIt "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
3238 LogIt "The failsafe kernel is $kernelpath.\n"
3239 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"
3240 LogIt "disks then it may still be a result of a problem with your kernel.\n"
3241 pwd=`pwd`
3242 cd $MINDI_TMP
3243 mkdir -p lib/modules
3244 cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
3245 cd $pwd
3246 else
3247 kernelpath=$MINDI_LIB/vmlinuz
3248 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
3249 LogIt "However, you are still running your kernel. If Mindi fails to create your"
3250 LogIt "disks then it may still be a result of a problem with your kernel."
3251 pwd=`pwd`
3252 cd $MINDI_TMP
3253 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
3254 cd $pwd
3255 fi
3256 YOUR_KERNEL_SUCKS="Your kernel sucks"
3257fi
3258echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
3259[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
3260
3261[ "$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."
3262
3263rm -f $MINDI_CACHE/{*img,*gz,*iso}
3264
3265PrepareDataDiskImages $MINDI_CACHE
3266noof_disks=$?
3267ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
3268rds=$(($ramdisk_size-$((ramdisk_size%4096))))
3269ramdisk_size=$rds
3270
3271echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE
3272if [ "$USE_LILO" = "yes" ] ; then
3273 if [ "$ARCH" = "ia64" ] ; then
3274 PrepareBootDiskImage_LILO $MINDI_CACHE $IA64_BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create ia64 floppy disk image."
3275 else
3276 if ! PrepareBootDiskImage_LILO $MINDI_CACHE 2880 $kernelpath $ramdisk_size ; then
3277 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3278 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
3279 PrepareBootDiskImage_LILO $MINDI_CACHE 5760 $kernelpath $ramdisk_size || Die "Failed to create 2.88MB floppy disk image."
3280 fi
3281 fi
3282else
3283 if ! PrepareBootDiskImage_SYSLINUX $MINDI_CACHE 2880 $kernelpath $ramdisk_size ; then
3284 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3285 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
3286 PrepareBootDiskImage_SYSLINUX $MINDI_CACHE 5760 $kernelpath $ramdisk_size || Die "Failed to create 5.76MB floppy disk image."
3287 fi
3288fi
3289
3290[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
3291...Or type 'memtest' to test your PC's RAM thoroughly.\n"
3292
3293if [ _"$MONDO_SHARE" = _"" ]; then
3294 ListImagesForUser $MINDI_CACHE
3295 if [ "$PROMPT_WRITE_BOOT_FLOPPIES" = "yes" ]; then
3296 OfferToCopyImagesToDisks $MINDI_CACHE $boot_dev $FDDEVICE
3297 fi
3298 OfferToMakeBootableISO $MINDI_CACHE
3299 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3300 OfferToMakeBootableUSB $MINDI_CACHE
3301 fi
3302 LogIt "Finished."
3303elif [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] ; then
3304 rm -f $MINDI_CACHE/{*img,*gz,*iso}
3305 OfferToMakeBootableISO $MINDI_CACHE
3306 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3307 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
3308 else
3309 Die "Cannot find all.tar.gz, to be written to tape"
3310 fi
3311elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3312 OfferToMakeBootableUSB $MINDI_CACHE
3313else
3314 OfferToMakeBootableISO $MINDI_CACHE
3315fi
3316# cleanup
3317LogIt "$FRIENDLY_OUTSTRING"
3318for mtpt in $FLOPPY_WAS_MOUNTED ; do
3319 mount $mtpt
3320done
3321MindiExit 0
Note: See TracBrowser for help on using the repository browser.