source: MondoRescue/trunk/mindi/mindi@ 1079

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

merge -r1045:1078 £SVN_M/branches/stable

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