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

Last change on this file since 1326 was 1326, checked in by Bruno Cornec, 17 years ago
  • MONDO_LOGFILE is rather a char* exported by each main program (consolidation of those mecanisms in .h files with ps_*)
  • One include has been created for each binary containing only the specific declarations
  • Log files are now consistent: mondoarchive.log for mondoarchive (containing also mindi.log) and mondorestore.log for mondorestore (copied from /tmp (ram) to /var/log (disk) at the end of the restore)
  • Doc updated accordingly
  • LOGFILE in restore process is now passed in the environment and not duplicated a nymore
  • LogIt is not redifined either
  • LOGFILE should be put in environment by mondoarchive for mindi's usage but that's a step left for later.
  • label-partitions-as-necessary should now work correctly for LABEL and UUID (grep -w removed)
  • Remove useless script compare-me

(All coming from 2.2.2) (remains changes in my-stuff.h coming later on)

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