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

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

Attempt to fix bug #129

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