source: MondoRescue/trunk/mindi/mindi@ 1085

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

merge -r1081:1082 $SVN_M/branches/stable

  • Property svn:keywords set to Rev Id
File size: 113.3 KB
RevLine 
[1]1#!/bin/bash
2
[181]3# $Id: mindi 1085 2007-01-30 10:06:16Z 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"
[1085]579 rm -f $MINDI_TMP/keymaps.find
[135]580 return 0
[1]581}
582
583
584FindIsolinuxBinary() {
585 ISOLINUX=/usr/lib/isolinux.bin
586 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
587 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
588 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
589 [ ! -e "$ISOLINUX" ] && ISOLINUX=`locate isolinux.bin | grep -x "/.*/isolinux.bin"`
590 [ ! -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'"
591 echo "Found isolinux.bin at $ISOLINUX" >> $LOGFILE
592}
593
594
595FindLiloBinary() {
[135]596 if which lilo &> /dev/null ; then
[932]597 if which lilo.real > /dev/null 2> /dev/null ; then
598 LILO_EXE=lilo.real
[979]599 LogIt "lilo.real found; will be used instead of lilo (*grumble* *mutter*)"
[932]600 else
601 LILO_EXE=lilo
602 fi
603 $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]604 else
[932]605 LILO_EXE=`which false`
[1]606 fi
607}
608
[932]609
[1]610FindSensibleBootBFile() {
[135]611 local i out last
612 out=""
613 last=""
614 for i in `find /boot -type f | grep -v chain | grep -v os2 | sort -u` ; do
[1]615 if [ "`strings $i 2> /dev/null | head -n1`" = "LILO" ] ; then
[135]616 out="$out $i"
[932]617 last="$i"
[1]618 fi
[135]619 done
620 echo "$last"
[1]621}
622
623
624FindSpecificModuleInPath() {
[135]625 local modpaths pwd line
626 pwd=`pwd`
627 if [ "$YOUR_KERNEL_SUCKS" ] ; then
[956]628 cd $MINDI_TMP
[135]629 else
[588]630 cd /
[135]631 fi
632 if [ ! -e "$1" ] ; then
[979]633 LogIt "WARNING - cannot search specific path '$1'"
[588]634 return 1
[135]635 fi
636 modpaths=`find $1 -name $2.*o -type f`
637 [ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"
638 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
639 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
640 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
641 echo "$modpaths"
642 cd $pwd
[1]643}
644
645
646GenerateGiantDependencyList() {
[135]647 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]648
[135]649 echo -en "Analyzing dependency requirements"
650 outfile=$1
[956]651 tempfile=$MINDI_TMP/$$.txt
[135]652 incoming=`ReadLine`
[1]653
[135]654 > $tempfile
655 progress=0
656 res=0
657 noof_lines=$2
658 while [ "$incoming" != "" ] ; do
[863]659 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
660 incoming=`ReadLine`
661 continue
662 fi
663 if [ "$incoming" = "LVMFILES:" ] ; then
664 break
665 fi
[135]666 filelist=`GenerateListForFile "$incoming"`
667 r=$?
[979]668 [ "$r" -ne "0" ] && LogIt "$incoming not found"
[135]669 res=$(($res+$r))
[863]670# echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE
[135]671 for fname in $filelist ; do
[863]672 [ "$fname" != "" ] && echo "$fname" >> $tempfile
[135]673 done
674 progress=$(($progress+1))
675 echo -en "\r\t\t\t\t\t\t\t\t"
676 i=$(($progress*100))
677 i=$(($i/$noof_lines))
678 echo -en "$i"
679 echo -en "%"
680 modres=$(($progress%4))
681 [ "$modres" -eq "0" ] && echo -en "\t/"
682 [ "$modres" -eq "1" ] && echo -en "\t-"
683 [ "$modres" -eq "2" ] && echo -en "\t\\"
684 [ "$modres" -eq "3" ] && echo -en "\t|"
685 incoming=`ReadLine`
[1]686 done
[863]687 if [ "$incoming" = "LVMFILES:" ] ; then
688 incoming=`ReadLine`
689 lvmversion=""
690 while [ "$incoming" != "" ] ; do
691 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
692 incoming=`ReadLine`
693 continue
694 fi
695 filelist=`GenerateListForFile "$incoming"`
696 for tool in $filelist ; do
697 lvmresolved=`readlink -f $tool`
698 if [ "$tool" == "$lvmresolved" ]; then
699 echo "$tool" >> $tempfile
700 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
701 if [ "$lvmversion" = "" ] ; then
702 lvmversion=`$lvmresolved`
703 echo "$lvmresolved" >> $tempfile
704 fi
705 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
706 if [ "$lvmversion" == "200" ]; then
707 # pvdata and lvmcreate_initrd don't exist in LVM2
708 case "$toolstripped" in
709 "pvdata")
710 continue
711 ;;
712 "lvmcreate_initrd")
713 continue
714 ;;
715 esac
716 fi
717 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
718 if [ -e "$toolpath" ] ; then
719 echo "$toolpath" >> $tempfile
720 echo "$tool" >> $tempfile
721 else
722 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
723 fi
724 if [ -e "$toolpath" ] ; then
725 echo "$toolpath" >> $tempfile
726 echo "$tool" >> $tempfile
727 else
728 echo "Where are your LVM-Tools? Couldn't find $tool"
729 fi
730 else
731 echo "$tool" >> $tempfile
732 fi
733 done
734 progress=$(($progress+1))
735 echo -en "\r\t\t\t\t\t\t\t\t"
736 i=$(($progress*100))
737 i=$(($i/$noof_lines))
738 echo -en "$i"
739 echo -en "%"
740 modres=$(($progress%4))
741 [ "$modres" -eq "0" ] && echo -en "\t/"
742 [ "$modres" -eq "1" ] && echo -en "\t-"
743 [ "$modres" -eq "2" ] && echo -en "\t\\"
744 [ "$modres" -eq "3" ] && echo -en "\t|"
745 incoming=`ReadLine`
746 done
[135]747 fi
748 echo -en "$DONE\nMaking complete dependency list"
[1]749
[278]750 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
[135]751 mv -f $tempfile.new $tempfile
752 > $outfile.pre
753 progress=0
754 noof_lines=`cat $tempfile | wc -l`
755 for fname in `cat $tempfile` ; do
[932]756 echo "$fname" >> $outfile.pre
757 LocateDeps $fname >> $outfile.pre
758 progress=$(($progress+1))
[135]759 echo -en "\r\t\t\t\t\t\t\t\t"
760 i=$(($progress*100))
761 i=$(($i/$noof_lines))
762 echo -en "$i"
763 echo -en "%"
[932]764 modres=$(($progress%4))
[135]765 [ "$modres" -eq "0" ] && echo -en "\t/"
766 [ "$modres" -eq "1" ] && echo -en "\t-"
767 [ "$modres" -eq "2" ] && echo -en "\t\\"
768 [ "$modres" -eq "3" ] && echo -en "\t|"
769 done
[1079]770 if [ _"$MONDO_SHARE" != _"" ]; then
[932]771 mkdir -p $bigdir/tmp
772 mkdir -p $bigdir/sbin
773 mkdir -p $bigdir/bin
[956]774 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
[979]775 LogIt "\nIncorporating post-nuke tarball"
[932]776 old_pwd=`pwd`
777 cd $bigdir
[979]778 tar -zxf $MINDI_TMP/post-nuke.tgz || LogIt "Error occurred when untarring post-nuke tarball"
[932]779 cd $old_pwd
[135]780 fi
[979]781 if cp -f $MINDI_TMP/mondo*restore $bigdir/usr/bin 2>> $LOGFILE ; then
[932]782 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre
783 else
[979]784 LogIt "Cannot find mondo*restore in mondo's tempdir, $MINDI_TMP"
785 LogIt "I bet you've got a spare copy of Mondo or Mindi floating around on your system."
[932]786 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."
787 Die "Odd."
788 fi
[979]789 cp -f $MINDI_TMP/BOOTLOADER.* $bigdir 2> /dev/null || LogIt "\nMondo v1.2x defaults to LILO as the bootloader, BTW."
[956]790 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[979]791 LogIt "Incorporating NFS-related settings"
[932]792 for r in NFS-* ISO-PREFIX ; do
[979]793 cp -f $MINDI_TMP/$r $bigdir/tmp 2>> $LOGFILE || Die "Cannot copy $r - did you run out of disk space?"
[932]794 echo "Copying $r to ramdisk" >> $LOGFILE
795 done
796 fi
[1]797 fi
[932]798 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
[135]799 rm -f $tempfile $outfile.pre
800 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
801 return $res
[1]802}
803
804
805GenerateListForFile() {
[135]806 local files_found loc fname incoming i res
807 incoming="$1"
808 files_found=""
809 res=0
[1]810
[135]811 for fname in $incoming ; do
812 files_found="$files_found `LocateFile $fname`"
813 done
[1]814
[135]815 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
[1]816}
817
818
819# Returns all disk devices which are part of a raid array
820GetAllRaidMembers() {
[135]821 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
[1]822}
823
824
825GetFileSizeList() {
[135]826 local i
827 for i in `find $1 -type d -o -print` ; do
828 du -sk $i
829 done
[1]830}
831
832
833GetHomeDir() {
[135]834 local res loc
835 loc=`which $1 2>/dev/null`
836 res=`file $loc | $AWK '{print $NF;}'`
837 dirname $res
[1]838}
839
840
841# Searches parent raid device of given disk device
842# $1: disk device (i.e. /dev/hda1)
843GetParentRaidDev() {
[135]844 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
[1]845}
846
847
848# Searches members of raid device
849# $1: raid device (/dev/md...)
850GetRaidDevMembers() {
[135]851 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
[1]852}
853
854
855HackPathsToFailsafe() {
[135]856 local incoming newpath kver stub i pwd
857 kver=`uname -r`
858 incoming=`ReadLine`
859 pwd=`pwd`
[956]860 cd $MINDI_TMP
[135]861 while [ "$incoming" != "" ] ; do
[932]862 stub=`basename $incoming`
863 newpath=`FindSpecificModuleInPath lib/modules/$FAILSAFE_KVER $stub`
864 for i in $newpath ; do
865 echo "$i"
866 done
867 read incoming
[1]868 done
[135]869 cd $pwd
[1]870}
871
872
873ListAllPartitions() {
[135]874 local res currline partition all_partitions ap_orig remaining i j
[1]875
[979]876 grep -vx " *#.*" $MY_FSTAB | grep -vx " *none.*" | $AWK '/^\/dev\/[imhs]d||^LABEL\=\/|^UUID=/ && !/fdd|cdr|zip|floppy/ {print $1}'
[135]877 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
878 return
[1]879}
880
881
882ListImagesForUser() {
[135]883 local path fname
884 path=$1
885 echo -en "In the directory '$path' you will find the images:-\n"
[687]886 for fname in `ls $path | grep -F mindi-` ; do
[135]887 printf "%19s " $fname
888 done
889 echo " "
[1]890}
891
892
893ListKernelModulePaths() {
[135]894 local module_list module fname oss r kern
895 oss="/root/oss/modules"
[300]896 module_list="`lsmod | sed -n '2,$s/ .*//p'`"
[1]897###
898### Sq-Modification ... Use kernelname for module search path if specified
899###
[135]900 # kern="`uname -r`"
901 if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]
902 then
[300]903 kern=${kernelname}
[135]904 else
[300]905 kern="`uname -r`"
[135]906 fi
[1]907###
908### Sq-Mod End
909###
[135]910 for module in $module_list $EXTRA_MODS ; do
911 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
[300]912 echo "module $module --> $r" >> $LOGFILE
913 [ "$r" ] && echo "$r"
[687]914 [ -f "$oss" ] && find $oss | grep -F $module
[135]915 done
916 find /lib/modules/$kern/modules.* -type f 2> /dev/null
917 [ -f "$oss" ] && find $oss.* 2> /dev/null
[1]918}
919
920
921LocateDeps() {
[135]922 local incoming fname deps
923 incoming="$1"
924 for fname in $incoming ; do
925 if [ ! -e "$fname" ] ; then
[979]926 echo "WARNING - $fname does not exist; cannot be LDD'd." >> $LOGFILE
[764]927 if echo $fname | grep lvm &> /dev/null ; then
928 echo "This warning only affects you if you are using LVM." >> $LOGFILE
929 if lsmod | grep lvm &> /dev/null ; then
930 echo "I think you are, so please take heed!" >> $LOGFILE
931# LogIt "Where is liblvm? You need it."
932 else
933 echo "I don't think you are, so don't worry about it." >> $LOGFILE
934 fi
935 fi
[135]936 elif [ -h "$fname" ] && [ -x "$fname" ] ; then
[764]937 echo "$fname is softlink" >> $LOGFILE
[135]938 else
939 ldd $fname 2> /dev/null | ProcessLDD $fname
940 fi
941 done
[1]942}
943
[932]944
[863]945# Give all symlinks recursively of a full path name
946ReadAllLink() {
947 file="$1"
[1]948
[863]949 if [ ! -h $file ]; then
950 echo "$file"
951 return 0
952 fi
[1]953
[1043]954 link=`readlink -f $file`
[863]955 d=`dirname $file`
956 if [ ! -e "$link" -a ! -e "$d/$link" ]; then
957 echo "Problem with dead link on $file -> $link" >> $LOGFILE
958 fi
[1079]959 if [ -h "$d" ]; then
960 echo "$link $d"
[863]961 else
[1079]962 echo "$link"
963 fi
[863]964}
965
[932]966
[1]967LocateFile() {
[135]968 local i path fname_to_find location output resolved tmp stub cache_id loclist
969 fname_to_find="$1"
[863]970 if echo "$fname_to_find" | grep -x "/.*" ; then
971 output="$fname_to_find"
972 if [ -h "$output" ] ; then
973 output="`ReadAllLink $output` $output"
[135]974 fi
[863]975 echo "$output"
976 return 0
[135]977 fi
978 output=""
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?"
[1085]1507 find $imagesdir -type f > $MINDI_TMP/imagesdir.files
1508 i=`grep -F "/mindi-root.1" $MINDI_TMP/imagesdir.files 2> /dev/null`
1509 j=`grep -F "/mindi-boot" $MINDI_TMP/imagesdir.files | grep -Ev '2880|5760'`
[932]1510 if [ "$i" ] ; then
1511 CopyImageToDisk $j $data_dev "boot disk"
1512 CopyImageToDisk $i $data_dev "root disk"
1513 else
1514 CopyImageToDisk $j $boot_dev "boot/root disk"
1515 fi
1516 count=1
[1085]1517 for i in `grep -F mindi-data $MINDI_TMP/imagesdir.files` ; do
[932]1518 CopyImageToDisk $i $data_dev "data disk #$count"
1519 count=$(($count+1))
1520 done
[1085]1521 rm -f $MINDI_TMP/imagesdir.files
[932]1522}
1523
1524
[1]1525OfferToMakeBootableISO() {
[135]1526 local i old_pwd
[1079]1527 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[979]1528 echo -en "Shall I make a bootable CD image? (y/[n]) "
[135]1529 read i
1530 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1531 fi
[956]1532 if [ ! "$MINDI_TMP" ] ; then
[1079]1533 LogIt "NB: Mindi's bootable CD always uses isolinux or elilo."
[979]1534 LogIt "For a bootable CD w/LILO, please use Mondo."
[135]1535 fi
[956]1536 rm -Rf $MINDI_TMP/iso
1537 mkdir -p $MINDI_TMP/iso/{images,archives,isolinux}
[979]1538 cp -f $1/*.img $1/*.gz $MINDI_TMP/iso/images 2>> $LOGFILE || LogIt "OfferToMakeBootableISO: Cannot copy $i to $MINDI_TMP/iso/images"
[135]1539 old_pwd=`pwd`
[956]1540 cd $MINDI_TMP/iso
[181]1541 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
[135]1542 for i in memdisk memtest.bin memtest.img ; do
[956]1543 j=$MINDI_LIB/$i
1544 k=$MINDI_TMP/iso/isolinux
1545 if [ -e "$j" ] ; then
[979]1546 LogIt "Copying $j to $k"
[956]1547 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1548 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
[1079]1549 if [ _"$MONDO_SHARE" != _"" ]; then
1550 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1551 fi
[956]1552 fi
[135]1553 done
[956]1554 MakeSyslinuxMessageFile $MINDI_TMP/iso/isolinux/message.txt
[1079]1555 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]1556 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/iso/isolinux/initrd.img 2>> $LOGFILE
[1079]1557 if [ _"$MONDO_SHARE" != _"" ]; then
1558 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?"
1559 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?"
1560
1561 fi
[135]1562 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
[956]1563 cd $MINDI_TMP/iso/isolinux
[1079]1564 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]1565 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[1079]1566 perl -pi -e 's/interactive/iso/' isolinux.cfg
[135]1567 fi
1568 if [ "$ARCH" != "ia64" ] ; then
[1079]1569 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]1570 cp $ISOLINUX ../ 2>> $LOGFILE
[135]1571 fi
[956]1572 cd $MINDI_TMP/iso
[135]1573 if [ "$ARCH" != "ia64" ] ; then
[1079]1574 if [ _"$MONDO_SHARE" != _"" ]; then
1575 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?"
1576 cp -f $MONDO_SHARE/autorun . 2>> $LOGFILE
1577 fi
[956]1578 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]1579 else
[956]1580 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]1581 fi
1582 if [ "$?" -ne "0" ] ; then
[932]1583 echo "----------- mkisofs's errors --------------" >> $LOGFILE
[956]1584 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
[932]1585 echo "mkisofs returned the following errors:-"
[956]1586 cat $MINDI_TMP/mkisofs.log
[979]1587 LogIt "Failed to create ISO image."
[135]1588 else
[956]1589 echo "Created bootable ISO image at $CACHE_LOC/mindi.iso" >> $LOGFILE
[135]1590 fi
[956]1591 rm -f $MINDI_TMP/mkisofs.log
[135]1592 cd $old_pwd
[1]1593}
1594
1595
[1079]1596OfferToMakeBootableUSB() {
1597 local i old_pwd
1598 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1599 echo "Shall I make a bootable USB image ?"
1600 echo -en "WARNING: This will erase all content on $USBDEV (y/[n]) "
1601 read i
1602 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1603 fi
1604 rm -Rf $MINDI_TMP/usb
1605 mkdir -p $MINDI_TMP/usb
1606 USBPART="${USBDEV}1"
1607
1608 echo -en "Transforming $USBDEV in a Bootable device "
1609 echo -en "."
1610 echo "Transforming $USBDEV in a Bootable device" >> $LOGFILE
1611 echo "Checking $USBDEV" >> $LOGFILE
1612 $FDISK -l $USBDEV 2>&1 >> $LOGFILE
1613 if [ $? -ne 0 ]; then
1614 echo "Unable to access $USBDEV" | tee -a $LOGFILE
1615 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1616 MindiExit -1
1617 fi
1618 echo -en "."
1619 echo "Erasing $USBDEV" >> $LOGFILE
1620 $FDISK $USBDEV 2>&1 >> $LOGFILE << EOF
1621d
1622d
1623d
1624d
1625n
1626p
16271
1628
1629
1630t
1631b
1632a
16331
1634w
1635EOF
1636 if [ $? -ne 0 ]; then
1637 echo "Unable to create a vfat Filesystem on $USBDEV" | tee -a $LOGFILE
1638 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1639 $FDISK -l $USBDEV 2>&1 | tee -a $LOGFILE
1640 MindiExit -1
1641 fi
1642 echo -en "."
1643 echo "Creating a vfat filesystem on $USBPART" >> $LOGFILE
1644 mkfs -t vfat $USBPART 2>&1 >> $LOGFILE
1645 if [ $? -ne 0 ]; then
1646 echo "Unable to create a vfat filesystem on $USBPART" | tee -a $LOGFILE
1647 echo "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)" | tee -a $LOGFILE
1648 $FDISK -l $USBDEV 2>&1 | tee -a $LOGFILE
1649 MindiExit -1
1650 fi
1651 echo -en "."
1652 echo "Mounting $USBPART on $MINDI_TMP/usb" >> $LOGFILE
1653 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1654 if [ $? -ne 0 ]; then
1655 echo "Unable to mount $USBPART on $MINDI_TMP/usb" | tee -a $LOGFILE
1656 echo "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)" | tee -a $LOGFILE
1657 $FDISK -l $USBDEV 2>&1 | tee -a $LOGFILE
1658 MindiExit -1
1659 fi
1660 echo -en "."
1661 mkdir -p $MINDI_TMP/usb/{images,archives}
1662 cp -f $1/*.img $1/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogIt "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/iso/images"
1663 echo -en "."
1664 old_pwd=`pwd`
1665 cd $MINDI_TMP/usb
1666 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1667 for i in memdisk memtest.bin memtest.img ; do
1668 j=$MINDI_LIB/$i
1669 k=$MINDI_TMP/usb
1670 if [ -e "$j" ] ; then
1671 LogIt "Copying $j to $k"
1672 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1673 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
1674 if [ _"$MONDO_SHARE" != _"" ]; then
1675 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1676 fi
1677 fi
1678 done
1679 echo -en "."
1680 MakeSyslinuxMessageFile $MINDI_TMP/usb/message.txt
1681 echo -en "."
1682 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?"
1683 echo -en "."
1684 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1685 echo -en "."
1686 if [ _"$MONDO_SHARE" != _"" ]; then
1687 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?"
1688 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?"
1689
1690 fi
1691 echo -en "."
1692 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
1693 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?"
1694 echo -en "."
1695 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
1696 perl -pi -e 's/interactive/iso/' syslinux.cfg
1697 fi
1698 cd $old_pwd
1699 echo -en "."
1700 if [ "$ARCH" != "ia64" ] ; then
1701 if [ _"$MONDO_SHARE" != _"" ]; then
1702 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?"
1703 cp -f $MONDO_SHARE/autorun $MONDO_ROOT 2>> $LOGFILE
1704 fi
1705 umount $MINDI_TMP/usb
1706 syslinux $USBPART 2>> $MINDI_TMP/syslinux.log
1707 else
1708 echo "No USB boot support for ia64" | tee -a $LOGFILE
1709 umount $MINDI_TMP/usb
1710 MindiExit -1
1711 fi
1712 echo -en "."
1713 if [ "$?" -ne "0" ] ; then
1714 echo "----------- syslinux's errors --------------" |tee -a $LOGFILE
1715 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1716 LogIt "Failed to create USB image."
1717 else
1718 echo -e "$DONE"
1719 echo "Created bootable USB image on $USBDEV" >> $LOGFILE
1720 fi
1721 rm -f $MINDI_TMP/syslinux.log
1722}
1723
1724
[1]1725PluralOrNot() {
[135]1726 [ "$1" -gt "1" ] && echo -en "s"
[1]1727}
1728
1729
1730MakeMessageFile() {
[135]1731 local disksize
1732 disksize=$1
[687]1733 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
[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%"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]1735 else
[276]1736 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]1737 fi
1738 if [ "$disksize" -gt "2880" ] ; then
[1079]1739 if [ _"$MONDO_SHARE" != _"" ]; then
[932]1740 if [ "$CDRECOVERY" != "yes" ] ; then
[956]1741 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[932]1742 echo -en "Press <enter> to continue.\n"
[956]1743 elif [ ! "$MINDI_TMP" ] ; then
[932]1744 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1745 else
1746 echo -en "$BOOT_MEDIA_MESSAGE"
1747 fi
[236]1748 fi
[135]1749 fi
[1]1750 fi
[135]1751 if [ "$CDRECOVERY" = "yes" ] ; then
1752 echo -en "\
[1]1753To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1754CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
[135]1755 fi
1756 echo -en "\n\n\n"
[1]1757}
1758
1759
1760write_full_floppy_of_kernel() {
[135]1761 local mtpt image old_pwd res disksize
[1]1762
[135]1763 res=0
1764 old_pwd=`pwd`
1765 KERN_DISK_MADE=1
1766 disksize=$3
1767 rand1=$RANDOM
1768 rand2=$RANDOM
[956]1769 image=$MINDI_TMP/$rand1.$rand2.img
1770 mtpt=$MINDI_TMP/$rand1.$rand2.mtpt
[979]1771 dd if=/dev/zero of=$image bs=1k count=$disksize &> /dev/null
[1079]1772 echo "Creating ext2 filesystem on $image" >> $LOGFILE
[979]1773 mke2fs -N 26 -F $image &> /dev/null
[135]1774 mkdir -p $mtpt
1775 mount -o loop $image $mtpt
1776 cd $mtpt
1777 mkdir -p {dev,tmp,boot}
[979]1778 cp -f $1 vmlinuz 2>> $LOGFILE
[135]1779 if [ "$?" -ne "0" ] ; then
[979]1780 LogIt "Failed to copy $1 to ramdisk"
[135]1781 cd $old_pwd
1782 umount $mtpt
1783 rmdir $mtpt
1784 rm $image
1785 return 1
1786 fi
[1]1787
[135]1788 rdev vmlinuz 2,0
1789 rdev -R vmlinuz 0
1790 rdev -r vmlinuz 49152
[1]1791
[979]1792 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
[135]1793 losetup /dev/loop0 > /dev/null 2> /dev/null
[979]1794 [ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary."
[135]1795 CopyBootBFile $mtpt/boot.b
[1]1796
[135]1797 MakeLiloConfFile $disksize >> bdlilo.conf
[1]1798
[135]1799 chmod 644 bdlilo.conf
1800 MakeMessageFile $disksize > message
1801 lilo -v -C bdlilo.conf -r $mtpt
1802 res=$?
[1]1803
[135]1804 cd $old_pwd
1805 umount $mtpt
1806 mv -f $image $2
1807 rmdir $mtpt
[1]1808
[135]1809 return $res
[1]1810}
1811
1812
1813MakeLiloConfFile() {
[135]1814 local disksize options i ooo
1815 disksize=$1
1816 options=""
[932]1817
1818 if [ "$ARCH" != "ia64" ] ; then
1819 echo -en "boot=/dev/loop0\ndisk=/dev/loop0\n"
1820 fi
1821 if [ "$disksize" -eq "2880" ] ; then
1822 echo -en "bios=0x00\nsectors=36\nheads=2\ncylinders=80\n"
1823 elif [ "$disksize" -eq "1722" ] ; then
1824 echo -en "bios=0x00\nsectors=21\nheads=2\ncylinders=82\n"
1825 elif [ "$disksize" -gt "2880" ] ; then
1826 /bin/true
1827 else
1828 echo -en "bios=0x00\nsectors=18\nheads=2\ncylinders=80\n"
1829 fi
1830 if [ "$ARCH" != "ia64" ] ; then
1831 echo -en "install=/boot.b\nmap=/boot.map\n"
1832 fi
[135]1833 if [ "$CDRECOVERY" = "yes" ] ; then
1834 echo -en "default=RESTORE\n"
[1079]1835 elif [ "$disksize" -gt "2880" ] && [ _"$MONDO_SHARE" != _"" ]; then
[956]1836 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[292]1837 echo -en "default=iso\n"
1838 else
1839 echo -en "default=interactive\n"
1840 fi
[1]1841 else
[292]1842 echo -en "default=expert\n"
[1]1843 fi
[292]1844
1845 echo -en "prompt\n"
[135]1846 if [ "$ARCH" != "ia64" ] ; then
1847 echo -en "vga=normal\nbackup=/dev/null\nmessage=/message\n"
1848 fi
1849 if [ "$CDRECOVERY" != "yes" ] ; then
[932]1850 echo -en "timeout=300\n"
[135]1851 fi
1852 echo -en "\n"
1853 if [ "$CDRECOVERY" = "yes" ] ; then
[932]1854 options="RESTORE expert"
[135]1855 elif [ "$disksize" -gt "2880" ] ; then
[1079]1856 if [ _"$MONDO_SHARE" != _"" ]; then
[956]1857 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[135]1858 options="iso"
1859 else
1860 options="interactive expert compare iso nuke isonuke"
[1]1861# hda hdb hdc hdd"
[135]1862 fi
1863 else
1864 options="expert"
[932]1865 fi
[135]1866 else
[292]1867 options="expert"
[135]1868 fi
1869 for i in $options ; do
[932]1870 ooo=$i
1871 [ "$ooo" = "RESTORE" ] && ooo="nuke"
1872 if [ "$ARCH" = "ia64" ] ; then
1873 rootpart="root=/dev/ram0\n\t"
1874 else
1875 rootpart=""
1876 fi
[1079]1877 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]1878
[932]1879 outstr=$outstr" $ooo_mode"
1880 outstr=$outstr"\"\n"
1881 if [ "$disksize" = "1440" ] ; then
1882 echo -en "$outstr" | sed s/initrd=.*// | grep -v root=
1883 else
1884 echo -en "$outstr"
1885 fi
[135]1886 done
[1]1887}
1888
1889
1890PrepareBootDiskImage_LILO() {
[135]1891 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
1892 imagesdir=$1
1893 disksize=$2
1894 kernelpath=$3
1895 ramdisksize=$4
[1]1896
[135]1897 retval=0
1898 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1899 echo -en "Making "$disksize"KB boot disk..."
[956]1900 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]1901 if [ "$ARCH" != "ia64" ] ; then
1902 [ "$disksize" != "1722" ] && [ "$disksize" != "2880" ] && [ "$disksize" != "5760" ] && Die "PDBI - disksize is $disksize - bad size"
1903 fi
1904 echo -en "..."
1905 imagefile=$imagesdir/mindi-bootroot.$disksize.img
[956]1906 mountpoint=$MINDI_TMP/mountpoint.$$
[135]1907 mkdir -p $mountpoint
1908 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"
1909 if [ "$ARCH" = "ia64" ] ; then
[979]1910 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1911 t=vfat
[135]1912 else
[1079]1913 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
[979]1914 mke2fs -N 26 -m 0 -F $imagefile >> $LOGFILE 2>> $LOGFILE
1915 t=ext2
[135]1916 fi
[979]1917 mount -t $t -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
1918 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[135]1919 mkdir -p $mountpoint/etc
1920 if [ "$ARCH" != "ia64" ] ; then
1921 liloconf=$mountpoint/etc/lilo.conf
1922 else
[932]1923 liloconf=$mountpoint/elilo.conf
[135]1924 fi
1925 old_pwd=`pwd`
1926 cd $mountpoint
1927 if [ "$ARCH" != "ia64" ] ; then
[979]1928 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
[135]1929 fi
1930 cd $old_pwd
1931 losetup /dev/loop0 > /dev/null 2> /dev/null
[979]1932 [ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary."
[135]1933 CopyBootBFile $mountpoint/boot.b
[1]1934
[135]1935 MakeLiloConfFile $disksize > $liloconf
[1]1936
[1079]1937 # Copy it so that CD-ROM menu entry is satisfied
1938 if [ "$ARCH" = "ia64" ] ; then
1939 mountefi=0
1940 df -T | grep /boot/efi | grep -q vfat
1941 if [ $? -ne 0 ]; then
1942 mount /boot/efi
1943 if [ $? -ne 0 ]; then
1944 echo "You have to mount your EFI partition when using mindi"
1945 MindiExit -1
1946 fi
1947 mountefi=1
1948 fi
1949 cp /boot/efi/elilo.efi $mountpoint
1950 cp $liloconf $mountpoint/elilo.efi $mountpoint/efi/boot
1951 if [ $mountefi -eq 1 ]; then
1952 umount /boot/efi 2>&1 > /dev/null
1953 fi
1954 fi
1955
[956]1956 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint..." >> $LOGFILE
1957 cp -f $MINDI_TMP/mindi.rdz $mountpoint 2>> $LOGFILE
[135]1958 if [ "$?" -ne "0" ] ; then
[979]1959 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[956]1960 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[979]1961 LogIt "Please unload some of your modules and try again."
[956]1962 rm -f $MINDI_TMP/mtpt.$$
[979]1963 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[135]1964 retval=$(($retval+1))
1965 fi
1966 MakeMessageFile $disksize > $mountpoint/message
[1]1967
[135]1968 mkdir -p $mountpoint/tmp
[956]1969 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[181]1970 if [ -e "$MINDI_LIB/memtest.img" ] ; then
[135]1971 echo -en "image=/memtest.bin\nlabel=memtest\nn" >> $liloconf
1972 echo -en "image=/memdisk\nlabel=memtest\nappend=\"initrd=memtest.img\"\n" >> $liloconf
[1]1973# echo "Yep, this is a multi-function CD" > $mountpoint/MULTIFUNC
[135]1974 fi
[1]1975
[932]1976 # copy the kernel across
[135]1977 rm -Rf $mountpoint/lost+found
1978 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
[309]1979 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[135]1980 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2> /dev/null
1981 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then
[932]1982 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
1983 du -sk $mountpoint/* >> $LOGFILE
1984 echo "--- end of list of files ---" >> $LOGFILE
1985 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
[1]1986Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE
[135]1987 rm -f $mountpoint/vmlinuz
[932]1988 cd $old_pwd
[135]1989 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[979]1990 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[932]1991 # losetup /dev/loop0 -d
1992 res=0
[135]1993 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 1440
[932]1994 res=$(($res+$?))
[979]1995 cp -f $MINDI_TMP/mindi.rdz $imagesdir/mindi-root.1440.img 2>> $LOGFILE
[932]1996 res=$(($res+$?))
1997 rm -f $imagefile
1998 if [ "$res" -ne "0" ]; then
[979]1999 LogIt "WARNING - failed to create 1.44MB boot/root floppies"
[932]2000 rm -f $imagesdir/mindi-*.1440.img
2001 fi
2002 return $res
[382]2003 fi
[309]2004 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[135]2005 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
2006 echo "Free space left on floppy = $free_space KB" >> $LOGFILE
2007 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE
[1]2008# make it bootable
[135]2009 rm -f $mountpoint/zero
[979]2010 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[135]2011 if [ "$disksize" -gt "2880" ] && [ ! "$KERN_DISK_MADE" ] ; then
2012 if [ "$ARCH" != "ia64" ] ; then
2013 $LILO_EXE $LILO_OPTIONS -r $mountpoint >> $LOGFILE 2>> $LOGFILE
2014 else
2015 /bin/true
2016 fi
2017 elif [ ! "$KERN_DISK_MADE" ] ; then
[1]2018# 12/28/2001 - if 1.72MB floppy then don't use LILO's optimizations at all
[932]2019 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE
[135]2020 else
[932]2021 echo "Not running LILO. It's not that kind of disk." >> $LOGFILE
[135]2022 fi
[932]2023
2024 # BERLIOS does not test necessarily what it expects
[135]2025 if [ $? -ne "0" ] ; then
[932]2026 if [ "`grep -F "/tmp/dev.0" $LOGFILE`" ] ; then
[979]2027 LogIt "The '/tmp/dev.0' error is NOT Mindi's fault. It is LILO's."
2028 LogIt "Please reboot your PC as a workaround."
2029 Die "LILO sneezed and Mindi caught a cold. Please read the README / FAQ."
[932]2030 fi
2031 echo "$LILO_EXE -r $mountpoint ...failed."
2032 echo -en "Press ENTER to continue."; read line
[979]2033 LogIt "Cannot run lilo on $mountpoint\nPlease upgrade/downgrade your version of LILO. It has a bug."
[932]2034 retval=$(($retval+1))
[1]2035 fi
[979]2036 cp -f $liloconf $MINDI_TMP/lilo.conf 2>> $LOGFILE
[135]2037 if [ "$ARCH" = "ia64" ] ; then
[979]2038 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
[135]2039 fi
2040 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2041 echo -en "..."
[979]2042 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[135]2043 if [ "$retval" -eq "0" ] ; then
[149]2044 echo -en "...$DONE\r"
2045 if [ "$KERN_DISK_MADE" ] ; then
2046 LogIt "... $disksize KB boot disks were created OK\r"
2047 fi
[1]2048 else
[149]2049 echo -en "...failed\r"
2050 LogIt $disksize"KB boot disk was NOT created\r"
2051 rm -f $imagefile
[1]2052 fi
[979]2053 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[135]2054 return $retval
[1]2055}
2056
2057
2058PrepareBootDiskImage_SYSLINUX() {
[135]2059 local disksize imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
2060 imagesdir=$1
2061 disksize=$2
2062 kernelpath=$3
2063 ramdisksize=$4
2064 do_boot_root_thingy=""
2065 local retval old_pwd
2066 retval=0
[932]2067
[135]2068 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
2069 echo -en "Making "$disksize"KB boot disk..."
[956]2070 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]2071 [ "$disksize" != "1722" ] && [ "$disksize" != "2880" ] && [ "$disksize" != "5760" ] && Die "PDBI - disksize is $disksize - bad size"
2072 echo -en "..."
2073 imagefile=$imagesdir/mindi-bootroot.$disksize.img
[956]2074 mountpoint=$MINDI_TMP/mountpoint.$$
[135]2075 mkdir -p $mountpoint
[1]2076# If I format a 1722KB data file & run syslinux on it, the resultant image
2077# won't boot. So, I have formatted a floppy, called syslinux on/to it, and
2078# used 'dd' to copy it to sys-disk.raw (zipped to sys-disk.raw.gz).
2079# If I extract it, mount it, copy my files to it, etc. then the resultant
2080# image _is_ bootable. I don't know why syslinux and/or mkfs.vfat won't
2081# play nicely and I don't care. :) I have worked around the problem. -Hugo, 06/27/2002
[135]2082 if [ "$disksize" = "1722" ] ; then
[181]2083 gzip -dc $MINDI_LIB/sys-disk.raw.gz > $imagefile || Die "Cannot dd blank file"
[135]2084 else
2085 dd if=/dev/zero of=$imagefile bs=1k count=$disksize &> /dev/null || Die "Cannot dd blank file"
[1079]2086 echo "Creating vfat filesystem on $imagefile" >> $LOGFILE
[979]2087 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
2088 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
[135]2089 fi
[979]2090 mount -t vfat -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
[932]2091
2092 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[135]2093 old_pwd=`pwd`
2094 MakeSyslinuxMessageFile $mountpoint/message.txt
2095 cd $mountpoint
2096 [ -e "$sys_cfg_file" ] || Die "Obi Wan, word up?"
2097 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $mountpoint > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to tmp_root"
[956]2098 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[1079]2099 perl -pi -e 's/interactive/iso/' syslinux.cfg
[135]2100 fi
2101 cd $old_pwd
[956]2102 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint/initrd.img..." >> $LOGFILE
2103 cp -f $MINDI_TMP/mindi.rdz $mountpoint/initrd.img 2>> $LOGFILE
[135]2104 if [ "$?" -ne "0" ] ; then
[979]2105 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[956]2106 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[979]2107 LogIt "Please unload some of your modules and try again."
[956]2108 rm -f $MINDI_TMP/mtpt.$$
[979]2109 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[135]2110 retval=$(($retval+1))
2111 fi
[1]2112
[135]2113 mkdir -p $mountpoint/tmp
[956]2114 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[1]2115
[932]2116 # copy the kernel across
[135]2117 rm -Rf $mountpoint/lost+found
2118 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
[309]2119 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[135]2120 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
2121 if [ "$?" -ne "0" ] || [ "$FORCE_DUAL_FLOPPIES" = "yes" ] ; then
[292]2122 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
2123 du -sk $mountpoint/* >> $LOGFILE
2124 echo "--- end of list of files ---" >> $LOGFILE
2125 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
[1]2126Sorry, your kernel is too big for a boot/root floppy.\nI'll try the new boot/root two-disk thingy.\n" >> $LOGFILE
[135]2127 rm -f $mountpoint/vmlinuz
[292]2128 cd $old_pwd
[135]2129 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[979]2130 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[1]2131
[135]2132 res=0
2133 write_full_floppy_of_kernel $kernelpath $imagesdir/mindi-boot.1440.img 1440
2134 res=$(($res+$?))
[979]2135 cp -f $MINDI_TMP/mindi.rdz $imagesdir/mindi-root.1440.img 2>> $LOGFILE
[135]2136 res=$(($res+$?))
2137 rm -f $imagefile
[382]2138 if [ "$res" -ne "0" ]; then
[979]2139 LogIt "WARNING - failed to create 1.44MB boot/root floppies"
[382]2140 rm -f $imagesdir/mindi-*.1440.img
2141 fi
[135]2142 return $res
2143 fi
[309]2144 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[135]2145 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
2146 echo "Free space left on floppy = $free_space KB" >> $LOGFILE
2147 echo "Max kernel size on $disksize KB floppy (est'd) = $max_kernel_size K" >> $LOGFILE
[932]2148
2149 # make it bootable
[135]2150 rm -f $mountpoint/zero
2151 mkdir -p $mountpoint/etc
[979]2152 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[135]2153 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2154 echo -en "..."
[979]2155 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[1]2156
[135]2157 if [ "$retval" -eq "0" ] ; then
2158 echo -en "...$DONE\r"
2159 if [ "$KERN_DISK_MADE" ] ; then
2160 rm -f $imagefile
[149]2161 LogIt "... $disksize KB boot disks were created OK\r"
[135]2162 fi
2163 else
[149]2164 echo -en "...failed\r"
2165 LogIt $disksize"KB boot disk was NOT created\r"
2166 rm -f $imagefile
[135]2167 fi
[979]2168 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[135]2169 return $retval
[1]2170}
2171
2172
[561]2173PrepareDataDiskImages() {
[1079]2174 local needlist bigdir minidir_root tardir diskdir imagesdir res i j k old_pwd lines lfiles
[561]2175
2176 imagesdir=$1
2177 rm -f $imagesdir/mindi-*.img $imagesdir/[0-9]*.tar.gz $imagesdir/mindi.iso
[956]2178 needlist=$MINDI_TMP/what-we-need.txt
2179 bigdir=$MINDI_TMP/bigdir
2180 minidir_root=$MINDI_TMP/minidir
[561]2181 mkdir -p $minidir_root
2182 mkdir -p $bigdir/usr/bin
[956]2183 tardir=$MINDI_TMP/tardir
[561]2184
[1079]2185 if [ -e "$DEPLIST_FILE" ]; then
2186 lfiles="$DEPLIST_FILE $DEPLIST_DIR/*"
2187 else
2188 lfiles="$DEPLIST_DIR/*"
2189 fi
2190 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
2191 cat $lfiles | GenerateGiantDependencyList $needlist $lines
[561]2192 res=$?
2193 if [ "$YOUR_KERNEL_SUCKS" ]; then
[932]2194 pwd=`pwd`
[956]2195 cd $MINDI_TMP
[561]2196 for i in `ListKernelModulePaths | HackPathsToFailsafe` ; do
[979]2197 cp --parents -pRdf ./$i $bigdir 2>> $LOGFILE || Die "PDDI can't cp $i->$bigdir"
[932]2198 if [ "`du -sk $i | cut -f1`" -lt "$(($CHOPSIZE*2))" ] ; then
[979]2199 cp --parents -pRdf $i $bigdir 2>> $LOGFILE
[932]2200 else
2201 ChopUpAndCopyFile $i $bigdir $CHOPSIZE $BIGNO
2202 BIGNO=$(($BIGNO+1))
2203 fi
[561]2204 done
[932]2205 for i in $EXTRA_MODS ; do
2206 j=`find lib/modules/$FAILSAFE_KVER -name $i.*o 2> /dev/null`
[979]2207 [ ! "$j" ] && echo "WARNING - cannot find failsafe module $i.o" >> $LOGFILE
[932]2208 for k in $j ; do
2209 if [ "`du -sk $k | cut -f1`" -lt "$CHOPSIZE" ] ; then
[979]2210 cp --parents -pRdf $k $bigdir 2>> $LOGFILE
[932]2211 else
2212 ChopUpAndCopyFile $k $bigdir $CHOPSIZE $BIGNO
2213 BIGNO=$(($BIGNO+1))
2214 fi
2215 echo "Added failsafe module $k to ramdisk" >> $LOGFILE
2216 done
2217 done
2218 cd $pwd
[561]2219 else
[932]2220 ListKernelModulePaths >> $needlist
[561]2221 fi
2222 if [ "$res" -ne "0" ] ; then
2223 Die "You have $res file`PluralOrNot $res` present in dependency list\nbut absent from filesystem."
2224 fi
2225 FindAndAddUserKeyboardMappingFile
2226 mkdir -p $bigdir/tmp
[1079]2227 if [ _"$MONDO_SHARE" != _"" ]; then
[956]2228 MakeMondoConfigFile $MINDI_TMP/mondo-restore.cfg
2229 cp -f $MINDI_TMP/mondo-restore.cfg $bigdir/tmp &> /dev/null
[561]2230 fi
2231 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
2232 DropOptimizedLibraries $needlist $bigdir
2233 echo -en "Assembling dependency files"
2234 CopyDependenciesToDirectory < $needlist $bigdir
2235
[932]2236 # also copy io.sys and msdos.sys, if we can find them
[561]2237 for i in `mount | cut -d' ' -f3` ; do
[932]2238 for j in io.sys msdos.sys ; do
[979]2239 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
[932]2240 done
[561]2241 done
2242
[932]2243 # master boot record, too
[956]2244 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
[561]2245 if [ "$i" ] ; then
[979]2246 LogIt "Backing up $i's MBR"
[932]2247 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
2248 sleep 1
2249 sync
2250 j=$i
2251 [ -h "$j" ] && j=`readlink -f $j`
[979]2252 LogIt "Creating /dev/boot_device ($j)"
[932]2253 mkdir -p $bigdir/dev
[956]2254 cp -pRdf $j $bigdir/dev/boot_device 2> /dev/null || Die "Unable to create /dev/boot_device on ramdisk"
[561]2255 fi
2256
2257 old_pwd=`pwd`
2258 cd $bigdir
2259
2260 [ -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]2261 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping aux-tools"
[561]2262 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then
[979]2263 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping x11-tools.tgz"
[561]2264 fi
[1079]2265 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
[561]2266 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
[1079]2267 [ "$?" -ne "0" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
[561]2268 fi
[979]2269 [ -d "/lib/dev-state" ] && cp --parents -pRdf /lib/dev-state . 2>> $LOGFILE
[561]2270 cd $old_pwd
2271 echo -e "$DONE"
2272 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
2273 SplitDirectoryIntoMinidirs $bigdir $minidir_root
2274 noof_disks=$?
2275 [ "$noof_disks" -eq "0" ] && Die "Too much stuff!"
[956]2276 MakeMountlist $MINDI_TMP/mountlist.txt
[561]2277 mkdir -p $minidir_root/$noof_disks/tmp
[956]2278 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]2279 if [ _"$MONDO_SHARE" != _"" ]; then
2280 cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2281 fi
[979]2282 [ $LVM != "false" ] && $MINDI_LIB/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm || LVM="false"
[561]2283 cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE
2284 ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks
2285 CreateDataDiskImagesFromTarballs $tardir $imagesdir $noof_disks
2286 FRIENDLY_OUTSTRING="Boot and data disk images were created."
[932]2287 # One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images
[561]2288 rmdir $tardir $bigdir
2289 rm -f $needlist
2290 return $noof_disks
2291}
2292
2293
[1]2294ProcessLDD() {
[135]2295 local main_fname incoming j i fname f newf
2296 main_fname=$1
2297 read incoming
2298 while [ "$incoming" != "" ] ; do
[863]2299 # We take the full path name of the dyn. lib. we want
2300 incoming=`echo "$incoming" | sed '/[[:blank:]]*.*[[:blank:]]*=>[[:blank:]]*(.*/d ; s/[[:blank:]]*.*[[:blank:]]*=>[[:blank:]]*\(\/.*\)/\1/ ; s/[[:blank:]]*\(\/.*\)[[:blank:]]*(.*/\1/'`
2301 for f in `echo "$incoming"` ; do
2302 echo "$f `ReadAllLink $f`"
[135]2303 done
2304 read incoming
2305 done
[1]2306}
2307
2308
2309Prompt() {
[135]2310 echo -en "$1"
2311 read line
[1]2312}
2313
2314
2315ReadLine() {
[135]2316 local i incoming
2317 read incoming
2318 i=0
2319 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
[932]2320 i=$(($i+1))
2321 read incoming
[135]2322 done
2323 echo "$incoming"
[1]2324}
2325
2326
2327RejigHyperlinks() {
[135]2328 local minidir_root noof_disks fname path diskno old_pwd awk_loc gawk_loc dir i
2329 minidir_root=$1
2330 noof_disks=$2
[1]2331
[135]2332 old_pwd=`pwd`
2333 diskno=1
2334 while [ "$diskno" -le "$noof_disks" ] ; do
[863]2335 mkdir -p $minidir_root/$diskno
[135]2336 cd $minidir_root/$diskno
2337 for fname in `find -type d -o -print` ; do
2338 [ -h "$minidir_root/$diskno/$fname" ] && MoveHyperlinkSensibly $fname $minidir_root $diskno $noof_disks
2339 done
[932]2340 diskno=$(($diskno+1))
[135]2341 done
[1]2342
[135]2343 cd $old_pwd
2344 return
[1]2345}
2346
2347
2348ReplaceIndividualLine() {
[135]2349 local orig_file new_file lino newstring lines_total lines_remaining
[932]2350
[135]2351 orig_file=$1.orig
2352 mv -f $1 $orig_file || Die "Cannot move $1 to $orig_file"
2353 new_file=$1
2354 lino=$2
2355 newstring="$3"
2356 if [ "$lino" = "" ] || [ "$lino" -lt "1" ] ; then
[932]2357 echo "Can't find string" >> $LOGFILE
2358 return 1
[135]2359 fi
[979]2360 lines_total=`wc -l $orig_file | $AWK '{print $1;}'`
[135]2361 lines_remaining=$(($lines_total-$lino))
2362 head -n$(($lino-1)) $orig_file > $new_file
2363 echo "$newstring" >> $new_file
2364 echo "# The above line was added by Mindi, at the user's instruction" >> $new_file
2365 tail -n$lines_remaining $orig_file >> $new_file
2366 echo "Replace line $lino of $new_file with user-specified line, '$newstring'" >> $LOGFILE
2367 [ -x "$orig_file" ] && chmod +x $new_file
2368 rm -f $orig_file
2369 return 0
[1]2370}
2371
2372
2373ScanCDandTape() {
2374 local i
2375
2376 for i in /dev/st0 /dev/ht0 /dev/cdrom /dev/cdrom0 /dev/cdrom 1 ; do
[135]2377 dd if=$i of=/dev/null bs=64k count=1 &> /dev/null
[1]2378 done
2379}
2380
2381
2382SizeOfPartition() {
[135]2383 local devpath drive res stub
2384 device=$1
[687]2385 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
[932]2386 res=`SizeOfRaidPartition $device`
2387 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2388 echo "$res"
2389 return 0
[135]2390 fi
[932]2391 # patch from Bill <bill@iwizard.biz> - 2003/08/25
[979]2392 res=`$FDISK -s $device 2>> $LOGFILE`
[932]2393 # end patch
[687]2394 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`
[135]2395 [ "$res" = "" ] && res="-1"
2396 echo $res
2397 return 0
[1]2398}
2399
2400
2401SizeOfRaidPartition() {
[135]2402 local real_dev smallest_size silly tmp
[1]2403
[135]2404 silly=999999999
2405 smallest_size=$silly
[1]2406
[135]2407 for real_dev in `GetRaidDevMembers $1` ; do
[932]2408 tmp=`SizeOfPartition $real_dev`
2409 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
[135]2410 done
[1]2411
[135]2412 if [ "$smallest_size" = "$silly" ] ; then
[932]2413 echo "-1"
2414 return 1
[135]2415 else
[932]2416 echo "$smallest_size"
2417 return 0
[135]2418 fi
[1]2419}
2420
2421
2422StripComments()
2423{
[135]2424 local tempfile
[932]2425
[956]2426 tempfile=$MINDI_TMP/$$.strip.txt
[979]2427 cp -f $1 $tempfile 2>> $LOGFILE
[276]2428 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
[135]2429 rm -f $tempfile
2430 echo "Stripped comments from $2" >> $LOGFILE
[1]2431}
2432
2433
2434SplitDirectoryIntoMinidirs() {
[135]2435 local bigdir minidir_root i noof_disks old_pwd res
[932]2436
[135]2437 bigdir=$1
2438 minidir_root=$2
2439 rm -Rf $minidir_root/*
[1]2440
[135]2441 TryToFitDataIntoSeveralDirs $bigdir $minidir_root
2442 noof_disks=$?
2443 if [ "$noof_disks" -eq "0" ] ; then
[932]2444 echo "Failed to fit data into several dirs."
[135]2445 return 0
2446 fi
2447 RejigHyperlinks $minidir_root $noof_disks
2448 rm -Rf $bigdir/*
[932]2449 return $noof_disks
[1]2450}
2451
2452
2453StripExecutable()
2454{
[135]2455 local tmpfile
[932]2456
[956]2457 tmpfile=$MINDI_TMP/stripped.$$.dat
[135]2458 [ -d "$1" ] || [ -h "$1" ] && return
[979]2459 cp -f $1 $tmpfile 2>> $LOGFILE
[135]2460 strip $tmpfile 2> /dev/null
2461 if [ "$?" -eq "0" ] ; then
[979]2462 cp -f $tmpfile $1 2>> $LOGFILE
[932]2463 echo "Stripped binary $2" >> $LOGFILE
[135]2464 fi
2465 rm -f $tmpfile
[1]2466}
2467
2468
2469TemporarilyCompressAllFiles() {
[135]2470 local i orig_fname out_fname out_list
[1]2471
[135]2472 i=0
2473 out_list=$2/compressed/compressed.txt
2474 mkdir -p $2/compressed
2475 > $out_list
2476 for orig_fname in $1 ; do
2477 out_fname=$2/compressed/$orig_fname.gz
2478 mkdir -p $out_fname 2> /dev/null
2479 rmdir $out_fname 2> /dev/null
2480 gzip -c6 $orig_fname > $out_fname 2> /dev/null
2481 i=$(((($i+1))%15))
2482 [ "$i" -eq "0" ] && echo -en "."
2483 du -sk $out_fname >> $out_list
2484 done
[1]2485}
2486
2487
2488TryToFindKernelPath() {
[135]2489 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
[932]2490
[135]2491 we_want_version=`uname -r`
2492 possible_kernels=""
2493 duff_kernels=""
[1]2494
[135]2495 if [ "$ARCH" = "ia64" ] ; then
2496 root="/boot/efi/efi"
2497 else
2498 root="/"
2499 fi
[687]2500 for fname in `find $root -maxdepth 2 -type f | grep -F lin | grep -Ev '^/proc/|^/net/'` ; do
[932]2501 [ ! -e "$fname" ] && continue
[135]2502 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
[932]2503 file $fname | grep -q gzip
2504 if [ "$?" -eq "0" ] ; then
2505 # Used by ia64
[135]2506 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[932]2507 else
[135]2508 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[932]2509 fi
[135]2510 [ "$fkern_ver" = "" ] && continue
[687]2511 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
[932]2512 [ -f "$fname" ] || continue
2513 [ -h "$fname" ] && continue
2514 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2515 file $fname | grep -q gzip
2516 if [ "$?" -eq "0" ] ; then
2517 # Used by ia64
2518 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[979]2519 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
[932]2520 duff_kernels="$fname $duff_kernels"
2521 else
[687]2522 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
[135]2523 possible_kernels="$fname $possible_kernels"
[932]2524 fi
[135]2525 else
[932]2526 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[979]2527 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
[932]2528 duff_kernels="$fname $duff_kernels"
2529 else
[687]2530 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
[135]2531 possible_kernels="$fname $possible_kernels"
[932]2532 fi
[135]2533 fi
2534 done
2535 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
[932]2536 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
[135]2537 fi
2538 if [ ! "$possible_kernels" ] ; then
[979]2539 LogIt "No kernel matches exactly. Are there any duff kernels?"
[135]2540 possible_kernels="$duff_kernels"
2541 if [ ! "$possible_kernels" ] ; then
[979]2542 LogIt "Sorry, no duff kernels either"
[135]2543 else
[979]2544 LogIt "I bet you're running Debian or Gentoo, aren't you?"
2545 LogIt "Your kernel doesn't have a sane builddate. Oh well..."
[135]2546 fi
2547 fi
[278]2548 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
[135]2549 noof_kernels=`CountItemsIn "$possible_kernels"`
2550 if [ "$noof_kernels" -eq "0" ] ; then
[979]2551 LogIt "Could not find your kernel."
[932]2552 if [ -e "/boot/vmlinuz" ] ; then
[979]2553 LogIt "Using /boot/vmlinuz as a last resort."
[932]2554 output=/boot/vmlinuz
[135]2555 else
[932]2556 output=""
2557 fi
[135]2558 elif [ "$noof_kernels" -eq "1" ] ; then
2559 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2560 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE
2561 output="$kernelpath"
2562 else
2563 for i in $possible_kernels ; do
2564 if echo $i | grep "`uname -r`" ; then
[932]2565 LogIt "OK, I used my initiative and found that "
[979]2566 LogIt "$i is probably your kernel. "
[932]2567 output="$i"
2568 return
2569 fi
[135]2570 done
[932]2571 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2572 output=/boot/vmlinuz
2573 echo "Schlomo, this one's for you." >> $LOGFILE
2574 else
[979]2575 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2576 LogIt "boot disks will still work, probably. If one does not work, try another."
2577 LogIt "$possible_kernels"
[135]2578 echo ""
[932]2579 fi
[1]2580 fi
[135]2581 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
[1]2582}
2583
2584
2585TryToFitDataIntoSeveralDirs() {
[135]2586 local bigdir minidir_root noof_disks diskno list_of_files filename old_pwd progress
2587 local i retval noof_disks total_files list_of_devs
[932]2588
[135]2589 bigdir=$1
2590 minidir_root=$2
2591 BIG_CLUNKY_SIZE_COUNTER=0
2592 retval=0
2593 noof_disks=1
[1]2594
[135]2595 echo -en "\r \rDividing data into several groups..."
2596 old_pwd=`pwd`
2597 cd $bigdir
[687]2598 list_of_files=`GetFileSizeList . | sort -nr | cut -f2 | grep -Fv "/dev/"`
[135]2599 progress=0
2600 total_files=`CountItemsIn "$list_of_files"`
2601 if [ "`echo "$filename" | grep -x "/dev/.*"`" ] ; then
2602 filesize=1
2603 fi
2604 mkdir -p $minidir_root/$noof_disks
2605 if [ -e "dev" ] ; then
2606 echo "Copying dev/* to $minidir_root/$noof_disks" >> $LOGFILE
[979]2607 cp --parents -pRdf dev $minidir_root/$noof_disks 2>> $LOGFILE
[135]2608 fi
2609 TemporarilyCompressAllFiles "$list_of_files" $minidir_root
2610 for filename in $list_of_files ; do
2611 AddFileToDir $filename $minidir_root $noof_disks
[932]2612 i=$?
2613 if [ "$i" -gt "$noof_disks" ] ; then
2614 noof_disks=$i
2615 echo -en "\r\t\t\t\t\t\t($noof_disks disks)"
2616 fi
2617 if [ "$i" -eq "0" ] ; then
[979]2618 LogIt "Cannot add file $filename to minidir $minidir_root"
[932]2619 retval=$(($retval+1))
2620 fi
[135]2621 progress=$(($progress+1))
[932]2622 echo -en "\r\t\t\t\t\t\t\t\t$(($progress*100/$total_files))% complete\r"
[135]2623 done
2624 cd $old_pwd
2625 echo -en "\rThe files have been subdivided into $noof_disks directories. \r"
2626 rm -Rf $minidir_root/compressed
2627 if [ "$retval" -gt "0" ] ; then
[932]2628 return 0
[135]2629 else
[932]2630 return $noof_disks
[135]2631 fi
[1]2632}
2633
2634
2635TurnTgzIntoRdz() {
[135]2636 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]2637
[135]2638 tgz_dir_fname=$1
2639 rdz_fname=$2
2640 ramdisksize=$3
2641 disksize=$4
2642 kernelsize=$5
2643 maxsize=$(($disksize-$kernelsize))
2644 maxsize=$(($maxsize*2)); # to allow for compression of 50%
[956]2645 tempfile=$MINDI_TMP/temp.rd
2646 mountpoint=$MINDI_TMP/mnt1
[135]2647 res=0
2648 echo -en "..."
2649 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"
2650 echo -en "..."
[1079]2651 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
[135]2652 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE
2653 echo -en "..."
2654 mkdir -p $mountpoint
[463]2655 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]2656 echo -en "..."
2657 old_pwd=`pwd`
2658 cd $mountpoint
[979]2659 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
[135]2660 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
2661 cd dev || Die "Can't cd to dev"
2662 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2663 rm -f dev-entries.tgz
2664 cd ..
[1]2665
[135]2666 for w in insmod.static insmod.static.old ; do
[932]2667 s=`which $w 2> /dev/null`
2668 if [ -e "$s" ] ; then
[979]2669 cp --parents -af $s . 2>> $LOGFILE
[932]2670 fi
[135]2671 done
[1]2672
[135]2673 mkdir -p tmp
2674 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2675 for w in cdrom floppy groovy-stuff ; do
2676 mkdir -p mnt/$w
2677 done
[932]2678 #if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then
2679 #ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"
2680 #fi
[135]2681 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
[932]2682 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
[135]2683 fi
[1]2684
[135]2685 lsmod > tmp/original-lsmod.txt
2686
2687 cp --parents -Rdf /dev/fd0*[1,2][4,7,8]* . 2> /dev/null
2688 cd $old_pwd
2689 echo -en "..."
2690 MakeModuleLoadingScript $TMPMODPROBE_FLAG $mountpoint/sbin/insert-all-my-modules
2691 echo -en "..."
2692 old_pwd=`pwd`
2693 if [ "$YOUR_KERNEL_SUCKS" ] ; then
[956]2694 cd $MINDI_TMP
[588]2695 floppy_modules_path=lib/modules/$FAILSAFE_KVER
[135]2696 else
[588]2697 cd /
[1]2698###
2699### Sq-Modification... Use kernel name in module path if specified.
2700###
[135]2701 #floppy_modules_path=lib/modules/`uname -r`
2702 if [ "${kernelname}" != "" ]
2703 then
[588]2704 floppy_modules_path=lib/modules/${kernelname}
[135]2705 else
[588]2706 floppy_modules_path=lib/modules/`uname -r`
[135]2707 fi
[1]2708###
2709### Sq-Modification end
2710###
[135]2711 fi
2712 floppy_modules=""
2713 if [ "$disksize" -lt "2880" ] ; then
[588]2714 list_of_groovy_mods="$FLOPPY_MODS $IDE_MODS ide-scsi sr_mod cdrom isocd isofs `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
[135]2715 else
[292]2716 list_of_groovy_mods="$CDROM_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
[135]2717 fi
[956]2718 if [ -e "$MINDI_TMP/NFS-DEV" ] ; then
[135]2719 # For PXE boot
2720 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2721 fi
[979]2722 [ -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]2723 for i in $list_of_groovy_mods ; do
[588]2724 floppy_modules="$floppy_modules `FindSpecificModuleInPath $floppy_modules_path $i`"
[135]2725 done
2726 for i in $floppy_modules ; do
2727 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
[956]2728 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
[588]2729 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
[979]2730 cp -df $i $mountpoint/ 2>/dev/null || LogIt "Unable to copy $i to $mountpoint"
[687]2731 [ "`echo "$i" | grep -F ".gz"`" ] && gunzip -f $mountpoint/`basename $i`
[135]2732 done
[181]2733 if [ ! -e "/sbin/devfsd" ] || [ "$disksize" -lt "2880" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
[135]2734 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE
2735 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE
2736 [ "$disksize" -lt "2880" ] && echo "...because disksize = $disksize" >> $LOGFILE
[181]2737 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE
[135]2738 rm -f $mountpoint/sbin/devfsd
2739 fi
2740 cd $old_pwd
2741 [ "$TAPEDEV" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
2742 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2743 rm -f $mountpoint/zero
[1079]2744 if [ _"$MONDO_SHARE" != _"" ]; then
[135]2745 MakeMondoConfigFile $mountpoint/tmp/mondo-restore.cfg
[956]2746 cp -f $mountpoint/tmp/mondo-restore.cfg $MINDI_TMP &> /dev/null
2747 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
[135]2748 echo -en "$FILES_IN_FILELIST" > $mountpoint/tmp/FILES-IN-FILELIST
2749 echo -en "$LAST_FILELIST_NUMBER" > $mountpoint/tmp/LAST-FILELIST-NUMBER
2750 [ "$USE_LZO" = "yes" ] && echo -en "Pras 4 Pres 2004" >> $mountpoint/tmp/USING-LZO
[1043]2751 [ "$USE_GZIP" = "yes" ] && echo -en "YES" >> $mountpoint/tmp/USING-GZIP
[135]2752 [ "$USE_COMP" = "yes" ] && echo -en "Compression, yep" >> $mountpoint/tmp/USING-COMP
[426]2753 [ "$USE_STAR" = "yes" ] && echo -en "Using star. Hooray." >> $mountpoint/tmp/USING-STAR
[135]2754 fi
2755 mkdir -p $mountpoint/tmp
2756 mkdir -p $mountpoint/proc
2757 echo "$disksize" > $mountpoint/tmp/$disksize.siz
2758 find $mountpoint -name CVS -exec rm -rf '{}' \;
2759 umount $mountpoint || Die "Cannot unmount $tempfile"
2760 dd if=$tempfile bs=1k 2> /dev/null | gzip -v9 > $rdz_fname 2> /dev/null
[1]2761# gzip -9 $tempfile
2762# mv $tempfile.gz $rdz_fname
[135]2763 if [ "$res" -eq "0" ] ; then
2764 echo -en "..."
2765 else
2766 echo -en "\rMade an rdz WITH ERRORS. \n"
2767 fi
2768 return 0
[1]2769}
2770
2771
2772WhichOfTheseModulesAreLoaded() {
[135]2773 local modname loaded_modules
[687]2774 loaded_modules=" `lsmod | tr -s ' ' '\t' | cut -f1 | grep -Fvx "Modules" | tr '\n' ' '` "
[135]2775 for modname in $1 ; do
[932]2776 [ "`echo "$loaded_modules" | grep -F " $modname "`" ] && echo "$modname"
[135]2777 done
[1]2778}
2779
2780
2781ZipMinidirsIntoTarballs() {
[135]2782 local minidir_root tardir noof_disks diskno old_pwd i
2783 minidir_root=$1
2784 tardir=$2
2785 noof_disks=$3
[1]2786
[135]2787 echo -en "Tarring and zipping the group`PluralOrNot $noof_disks`..."
2788 mkdir -p $tardir
2789 mkdir -p $minidir_root/all
2790 old_pwd=`pwd`
2791 diskno=1
2792 while [ "$diskno" -le "$noof_disks" ] ; do
[979]2793 cd $minidir_root/$diskno || LogIt "WARNING - cannot cd to $minidir_root/$diskno"
[588]2794 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]2795 diskno=$(($diskno+1))
2796 echo -n "..."
[979]2797 cp -pRdf * $minidir_root/all 2>> $LOGFILE
[135]2798 done
2799 mkdir -p $minidir_root/all/tmp
2800 cd $minidir_root/all
2801 size_of_all_tools=`du -sk . | cut -f1`
[1079]2802 if [ _"$MONDO_SHARE" != _"" ]; then
[135]2803 for q in filelist.full.gz biggielist.txt ; do
[956]2804 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
[979]2805 cp -pRdf $MINDI_TMP/$q tmp/ 2>> $LOGFILE
[135]2806 done
2807 mkdir -p $minidir_root/all/tmp
2808 echo -en "$FILES_IN_FILELIST" > $minidir_root/all/tmp/FILES-IN-FILELIST 2> /dev/null
2809 echo -en "$LAST_FILELIST_NUMBER" > $minidir_root/all/tmp/LAST-FILELIST-NUMBER 2> /dev/null
2810 fi
2811 tar -b 4096 -cf - * 2> /dev/null | gzip -9 > $tardir/all.tar.gz
2812 dd if=/dev/zero bs=1k count=64 >> $imagesdir/all.tar.gz 2> /dev/null
2813 [ "`du -sm $imagesdir/all.tar.gz | cut -f1`" -ge "30" ] && Die "You have too many tools in your shed"
2814 cd $old_pwd
2815 rm -Rf $minidir_root
2816 echo -e "$DONE"
[1]2817}
2818
2819
2820##############################################################################
[1043]2821#----------------------------------- Main -----------------------------------#
[1]2822##############################################################################
2823
2824
[1079]2825if [ "$1" = "--printvar" ] ; then
[539]2826 shift
2827 if [ _"$1" != _"" ] ; then
2828 set | egrep "^$1" | cut -d= -f2
2829 fi
[1079]2830 MindiExit 0
[539]2831fi
2832
[1]2833> $LOGFILE
2834echo "mindi v$MINDI_VERSION" >> $LOGFILE
2835echo "$ARCH architecture detected" >> $LOGFILE
2836echo "mindi called with the following arguments:" >> $LOGFILE
2837echo "$@" >> $LOGFILE
[808]2838echo "Start date : `date`" >> $LOGFILE
[1]2839
2840if [ -e "/etc/conf.modules" ] && [ ! -e "/etc/modules.conf" ] ; then
[979]2841 LogIt "WARNING - Ancient distro detected." 1
[135]2842 ln -sf /etc/conf.modules /etc/modules.conf
[1]2843fi
2844[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2845
[1043]2846# Log some capital variables
2847[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2848echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE
2849echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE
2850[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2851echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE
2852echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
2853
[1]2854trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
[1043]2855
2856# Sanity checks
2857which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2858which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2859which 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."
2860which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2861if which awk &> /dev/null ; then
2862 if ! which gawk &> /dev/null ; then
2863 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"
2864 fi
2865fi
2866which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2867[ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"
2868
[1]2869[ "`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"
2870# If we have a 2.6 kernel, the system uses module-init-tools which means that we
2871# may have the modprobe configuration spread out across multiple files in
2872# directory /etc/modprobe.d. If this is the case we concatenate these files into
2873# a temporary file for further processing. Otherwise we continue in the standard
2874# way. Note further that in case /etc/modprobe.d exists, we use it and ignore
2875# /etc/modprobe.conf which is exactly what module-init-tools does. The temporary
2876# modprobe.conf file is created in MakeModuleLoadingScript. AL041128.
2877if [ -d "/etc/modprobe.d" ] && [ `uname -r | cut -c1-3` == "2.6" ] ; then
[932]2878 TMPMODPROBE_FLAG="Y"
[1]2879else
[929]2880 TMPMODPROBE_FLAG="N"
2881 [ -e "/etc/modprobe.conf" ] && [ ! -e "/etc/modules.conf" ] && ln -sf /etc/modprobe.conf /etc/modules.conf
2882 [ ! -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]2883fi
[1043]2884
2885# Update the PATH variable if incomplete
2886if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2887 PATH=$PATH:/sbin:/usr/sbin
2888 export PATH
2889 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE
2890 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE
2891 echo " Or you might like to call 'su -' instead of 'su', for example." >> $LOGFILE
2892fi
2893
[1079]2894# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2895if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2896 source $MINDI_LIB/FindDistroFailsafe
2897 # Log kernel image
2898 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2899else
2900 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2901fi
[1043]2902
2903if ! which mkfs.vfat &> /dev/null ; then
2904 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2905fi
2906
[932]2907### BERLIOS
[1]2908### Fix as it's not mandatory on ia64
2909if [ "$ARCH" = "ia64" ] ; then
[1043]2910 if which elilo &> /dev/null ; then
2911 LILO_EXE=elilo
2912 else
2913 LILO_EXE=`which false`
2914 fi
[1]2915else
[135]2916 FindIsolinuxBinary
2917 FindLiloBinary
[1]2918fi
2919trap "Aborted" SIGTERM
2920DONE="\r\t\t\t\t\t\t\t\tDone. "
2921CHOPSIZE=240
2922BIGNO=0
[1079]2923MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
2924kernelpath="$mindi_kernel"
2925if [ "$kernelpath" = "NATIVE" ]; then
2926 kernelpath=""
2927fi
2928if [ "$ARCH" = "ia64" ] ; then
2929 USE_LILO=yes
2930else
2931 USE_LILO=no
2932fi
[1]2933
[764]2934if [ -d "/proc/lvm" ]; then
2935 # LVM v1
2936 LVMCMD=""
2937 LVM="v1"
2938elif [ -d "/dev/mapper" ]; then
2939 # LVM v2
2940 LVMCMD="lvm"
2941 LVM="v2"
2942else
2943 LVM="false"
2944fi
[1043]2945echo "LVM set to $LVM" >> $LOGFILE
2946echo "----------" >> $LOGFILE
2947echo "df result:" >> $LOGFILE
2948echo "----------" >> $LOGFILE
2949df -T >> $LOGFILE
2950echo "-------------" >> $LOGFILE
2951echo "lsmod result:" >> $LOGFILE
2952echo "-------------" >> $LOGFILE
2953lsmod >> $LOGFILE
2954echo "-------------" >> $LOGFILE
[1079]2955echo "Liste of extra modules is:" >> $LOGFILE
2956echo "$EXTRA_MODS" >> $LOGFILE
2957echo "-------------" >> $LOGFILE
[764]2958
[1]2959
2960FLOPPY_WAS_MOUNTED=""
2961for mtpt in /media/floppy /mnt/floppy /floppy ; do
[135]2962 if mount | grep -w $mtpt &> /dev/null ; then
2963 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2964 umount $mtpt
2965 fi
[1]2966done
2967
[1079]2968#
2969# If we have a USB device we need to store info
2970# and remove it from the parameters line
2971#
[1]2972if [ "$#" -ne "0" ] ; then
[1079]2973 if [ "$1" = "--usb" ] ; then
2974 shift
2975 USBDEV=$1
2976 if [ _"$USBDEV" = _"" ]; then
2977 Die "No USB device specified"
2978 fi
2979 shift
2980 fi
2981fi
2982
2983#
2984# Deal with parameters
2985#
2986if [ "$#" -ne "0" ] ; then
[135]2987 if [ "$1" = "--findkernel" ] ; then
2988 res=`TryToFindKernelPath`
2989 if [ "$res" = "" ] ; then
[932]2990 MindiExit -1
[135]2991 else
2992 echo "$res"
[932]2993 MindiExit 0
[135]2994 fi
2995 elif [ "$1" = "--makemountlist" ] ; then
2996 [ ! "$2" ] && Die "Please specify the output file"
2997 MakeMountlist $2
[932]2998 MindiExit $?
2999 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
[539]3000 echo "Mindi v$MINDI_VERSION"
[932]3001 MindiExit 0
[135]3002 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
[1079]3003 if [ _"$MONDO_SHARE" = _"" ]; then
3004 Die "--custom is reserved for mondoarchive calls"
3005 fi
[956]3006 MONDO_TMP=$2
3007 # Change MINDI_TMP for the one provided by mondo
3008 # So that it can get back the built files
[1043]3009 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
3010 rmdir $MINDI_TMP
[956]3011 MINDI_TMP=$MONDO_TMP
3012 mkdir -p $MINDI_TMP
[1043]3013 # This is the scratch dir in mondo
[939]3014 CACHE_LOC=$3
3015 if [ _"$CACHE_LOC" != _"" ]; then
3016 mkdir -p $CACHE_LOC
3017 fi
[539]3018 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
[1]3019###
3020### Attempt to locate kernel specific module path
3021### if module path is found then use it other wise use uname -r to set it...
3022###
[1079]3023 if [ "$kernelpath" = "" ]; then
3024 kernelpath=`TryToFindKernelPath`
3025 fi
[135]3026 kernelname=`echo $kernelpath | cut -d'-' -f2-`
[979]3027 LogIt "kernelname = $kernelname"
3028 LogIt "kernelpath = $kernelpath"
[135]3029 if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
3030 then
[979]3031 LogIt "Module path for ${kernelpath} not found..."
3032 LogIt "using running kernel\'s modules."
[135]3033 kernelname=`uname -r`
3034 else
[979]3035 LogIt "Using modules for kernel: ${kernelname}"
[135]3036 fi
[539]3037 TAPEDEV=$5
3038 TAPESIZE=$6
3039 FILES_IN_FILELIST=$7
3040 USE_LZO=$8
3041 CDRECOVERY=$9
[135]3042 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
3043 IMAGE_DEVS=""
3044 else
3045 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
3046 fi
[539]3047 if [ "${11}" ] ; then
3048 LILO_OPTIONS=""
[932]3049 # LogIt "LILO will use conservative settings, to be compatible with older BIOSes."
[539]3050 fi
3051 LAST_FILELIST_NUMBER=${12}
[135]3052 ESTIMATED_TOTAL_NOOF_SLICES=${13}
3053 EXCLUDE_DEVS="${14}"
3054 USE_COMP="${15}"
3055 USE_LILO="${16}"
[539]3056 USE_STAR="${17}"
3057 INTERNAL_TAPE_BLOCK_SIZE="${18}"
[135]3058 DIFFERENTIAL="${19}"
[1043]3059 USE_GZIP="${20}"
3060 NOT_BOOT="${21}"
[135]3061 [ "$USE_COMP" = "" ] && USE_COMP=yes
[1043]3062 [ "$USE_GZIP" = "" ] && USE_GZIP=no
[135]3063 [ "$NOT_BOOT" = "" ] && NOT_BOOT=no
[979]3064 [ "$TAPEDEV" ] && LogIt "This is a tape-based backup. Fine."
[539]3065 [ "$CDRECOVERY" = "yes" ] && [ "$TAPEDEV" != "" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
[956]3066 MONDO_ROOT=`echo $CACHE_LOC | sed 's/\(.*\)\/.*/\1/'`
[939]3067 if [ _"$MONDO_ROOT" != _"" ]; then
3068 mkdir -p $MONDO_ROOT
3069 else
3070 Die "MONDO_ROOT is undefined"
3071 fi
[135]3072 else
[539]3073 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
[932]3074 MindiExit -1
[135]3075 fi
[1]3076fi
3077#ScanCDandTape
3078[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3079if [ "$CDRECOVERY" = "yes" ] ; then
[181]3080 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg
3081 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg
[1]3082else
[181]3083 iso_cfg_file=$MINDI_LIB/isolinux.cfg
3084 sys_cfg_file=$MINDI_LIB/syslinux.cfg
[1]3085fi
3086
3087[ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"
[1079]3088if [ _"$MONDO_SHARE" = _"" ]; then
[979]3089 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION"
3090 LogIt "Latest Mindi is available from http://www.mondorescue.org"
3091 LogIt "BusyBox sources are available from http://www.busybox.net"
[1]3092else
[135]3093 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> /var/log/mondo-archive.log
[1]3094fi
[1043]3095if [ -f $MINDI_LIB/rootfs/bin/busybox ]; then
3096 LogIt "Mindi-`$MINDI_LIB/rootfs/bin/busybox 2>&1 | head -1`"
3097else
3098 LogIt "Unable to find mindi-busybox, please install it"
3099 MindiExit -1
3100fi
[1]3101
3102# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
3103insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
3104for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
[135]3105 insmod $i >> $LOGFILE 2>> $LOGFILE
[1]3106done
3107
3108KERN_DISK_MADE=""
3109
3110echo "DIFFERENTIAL = $DIFFERENTIAL" >> $LOGFILE
3111echo "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE" >> $LOGFILE
3112echo "NOT_BOOT = '$NOT_BOOT'" >> $LOGFILE
3113if [ "$NOT_BOOT" != "" ] && [ "$NOT_BOOT" != "0" ] && [ "$NOT_BOOT" != "no" ] ; then
[979]3114 LogIt "Just creating mondo-restore.cfg and a small all.tar.gz for Mondo. Nothing else."
[956]3115 MakeMondoConfigFile $MINDI_TMP/mondo-restore.cfg
3116 MakeMountlist $MINDI_TMP/mountlist.txt
3117 mkdir -p $MINDI_TMP/small-all/tmp
3118 cd $MINDI_TMP/small-all
3119 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"
3120 tar -cv tmp | gzip -9 > $MINDI_TMP/all.tar.gz || Die "Cannot make small all.tar.gz"
[135]3121 sleep 2
[979]3122 LogIt "Done. Exiting."
[932]3123 MindiExit 0
[1]3124fi
3125
[1079]3126if [ _"$USBDEV" != _"" ]; then
3127 LogIt "Including the generation of a Bootable USB device on $USBDEV"
3128fi
[1]3129if [ "$kernelpath" = "" ] ; then
[1079]3130 if [ _"$MONDO_SHARE" != _"" ]; then
3131 Die "Please use -k <path> to specify kernel."
[135]3132 fi
[1079]3133 if [ $INTERACTIVE == "yes" ]; then
3134 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
3135 read ch
3136 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
3137 USE_OWN_KERNEL="yes"
3138 fi
3139 fi
[135]3140 if [ "$USE_OWN_KERNEL" = "yes" ]; then
[539]3141 YOUR_KERNEL_SUCKS=""
3142 kernelpath=`TryToFindKernelPath`
3143 if [ "$kernelpath" = "" ] ; then
3144 echo -n "Please enter kernel path : "
3145 read kernelpath
3146 fi
[135]3147 else
[539]3148 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
[135]3149 fi
[1]3150fi
[1079]3151if [ _"$MONDO_SHARE" = _"" ] && [ $INTERACTIVE = "yes" ] && [ "$ARCH" != "ia64" ] ; then
[979]3152 echo -en "Would you like to use LILO (instead of syslinux)\nfor your boot CD/floppies (y/[n]) ?"
[135]3153 read ch
[1079]3154 if [ "$ch" = "y" ] || [ "$ch" = "Y" ] ; then
[135]3155 USE_LILO=yes
3156 fi
[1]3157fi
3158if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
[1079]3159 # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
3160 if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
3161 source $MINDI_LIB/FindDistroFailsafe
3162 # Log kernel image
3163 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
3164 kernelpath="$FAILSAFE_KBIN"
3165 LogIt "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
3166 LogIt "The failsafe kernel is $kernelpath.\n"
3167 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"
3168 LogIt "disks then it may still be a result of a problem with your kernel.\n"
3169 pwd=`pwd`
3170 cd $TMP_ROOT
3171 mkdir -p lib/modules
3172 cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
3173 cd $pwd
3174 else
3175 kernelpath=$MINDI_LIB/vmlinuz
3176 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
3177 LogIt "However, you are still running your kernel. If Mindi fails to create your"
3178 LogIt "disks then it may still be a result of a problem with your kernel."
3179 pwd=`pwd`
3180 cd $MINDI_TMP
3181 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
3182 cd $pwd
3183 fi
[135]3184 YOUR_KERNEL_SUCKS="Your kernel sucks"
[1]3185fi
[956]3186echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$CACHE_LOC" >> $LOGFILE
[979]3187[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
[1]3188
[979]3189[ "$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]3190
[956]3191rm -f $CACHE_LOC/{*img,*gz,*iso}
[1]3192
[956]3193PrepareDataDiskImages $CACHE_LOC
[1]3194noof_disks=$?
[539]3195[ "$noof_disks" -eq "0" ] && Die "Too much stuff!"
3196MakeMountlist $TMP_ROOT/mountlist.txt
3197mkdir -p $minidir_root/$noof_disks/tmp
3198cp -f $TMP_ROOT/mountlist.txt $minidir_root/$noof_disks/tmp/mountlist.txt || Die "Cannot copy mountlist.txt from $TMP_ROOT to data disk"
[956]3199cp -f $TMP_ROOT/mountlist.txt $CACHE_LOC
[539]3200[ "`DidMondoCallMe`" ] && cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MONDO_TMP/.
3201[ -d "/proc/lvm" ] && $MINDI_SBIN/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm
3202[ -d "/dev/mapper" ] && $MINDI_SBIN/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm
3203cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE
3204ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks
[956]3205CreateDataDiskImagesFromTarballs $tardir $CACHE_LOC $noof_disks
[539]3206FRIENDLY_OUTSTRING="Boot and data disk images were created."
3207# One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images
3208rmdir $tardir $bigdir
3209rm -f $needlist
3210#return $noof_disks
3211
[1]3212ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
3213rds=$(($ramdisk_size-$((ramdisk_size%4096))))
3214ramdisk_size=$rds
3215
3216echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE
3217if [ "$USE_LILO" = "yes" ] ; then
[135]3218 if [ "$ARCH" = "ia64" ] ; then
[932]3219 PrepareBootDiskImage_LILO $CACHE_LOC $IA64_BOOT_SIZE $kernelpath $ramdisk_size || Die "Failed to create ia64 floppy disk image."
[135]3220 else
[932]3221 if ! PrepareBootDiskImage_LILO $CACHE_LOC 1722 $kernelpath $ramdisk_size ; then
[979]3222 LogIt "WARNING - failed to create 1.72MB boot image."
3223 LogIt "Please reduce your kernel's size if you want to make a 1.72MB floppy disk."
[135]3224 fi
[932]3225 if ! PrepareBootDiskImage_LILO $CACHE_LOC 2880 $kernelpath $ramdisk_size ; then
[979]3226 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3227 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
[932]3228 PrepareBootDiskImage_LILO $CACHE_LOC 5760 $kernelpath $ramdisk_size || Die "Failed to create 2.88MB floppy disk image."
[489]3229 fi
[135]3230 fi
[1]3231else
[932]3232 if ! PrepareBootDiskImage_SYSLINUX $CACHE_LOC 1722 $kernelpath $ramdisk_size ; then
[979]3233 LogIt "WARNING - failed to create 1.72MB boot image."
3234 LogIt "Please reduce your kernel's size if you want to make a 1.72MB floppy disk."
[932]3235 if ! PrepareBootDiskImage_SYSLINUX $CACHE_LOC 2880 $kernelpath $ramdisk_size ; then
[979]3236 LogIt "WARNING - failed to create 2.88MB floppy disk image."
3237 LogIt "Please reduce your kernel's size if you want to make a 2.88MB floppy disk."
[932]3238 PrepareBootDiskImage_SYSLINUX $CACHE_LOC 5760 $kernelpath $ramdisk_size || Die "Failed to create 5.76MB floppy disk image."
[292]3239 fi
[135]3240 fi
[1]3241fi
3242
[181]3243[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
[1]3244...Or type 'memtest' to test your PC's RAM thoroughly.\n"
3245
[1079]3246if [ _"$MONDO_SHARE" = _"" ]; then
[932]3247 ListImagesForUser $CACHE_LOC
[135]3248 boot_dev=/dev/fd0u1722
3249 [ ! -e "$boot_dev" ] && mknod $boot_dev b 2 60
3250 [ ! -e "$boot_dev" ] && boot_dev=/dev/fd0H1722
[539]3251 [ ! -e "$boot_dev" ] && Die "Will you PLEASE tell your distribution maker to create the 1.72MB devices in /dev?"
[135]3252 if [ "$PROMPT_WRITE_BOOT_FLOPPIES" = "yes" ]; then
[956]3253 OfferToCopyImagesToDisks $CACHE_LOC $boot_dev $FDDEVICE
[135]3254 fi
[932]3255 OfferToMakeBootableISO $CACHE_LOC
[1079]3256 if [ _"$USBDEV" != _"" ] ; then
3257 OfferToMakeBootableUSB $CACHE_LOC
3258 fi
[979]3259 LogIt "Finished."
[1]3260elif [ "$TAPEDEV" ] ; then
[956]3261 rm -f $CACHE_LOC/{*img,*gz,*iso}
[932]3262 OfferToMakeBootableISO $CACHE_LOC
3263 if [ -e "$CACHE_LOC/all.tar.gz" ] ; then
[979]3264 cp -f $CACHE_LOC/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
[135]3265 else
[932]3266 Die "Cannot find all.tar.gz, to be written to tape"
[135]3267 fi
[1079]3268elif [ _"$USBDEV" != _"" ] ; then
3269 OfferToMakeBootableUSB $CACHE_LOC
[1]3270else
[932]3271 OfferToMakeBootableISO $CACHE_LOC
[1]3272fi
[135]3273# cleanup
[979]3274LogIt "$FRIENDLY_OUTSTRING"
[1]3275for mtpt in $FLOPPY_WAS_MOUNTED ; do
[135]3276 mount $mtpt
[1]3277done
[932]3278MindiExit 0
Note: See TracBrowser for help on using the repository browser.