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

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

Attempt to fix bug #128

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