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

Last change on this file since 1468 was 1468, checked in by Bruno Cornec, 17 years ago
  • Try to improve kernel support and detection for gentoo. (kernel named genkernel-* and not *lin*)
  • Adds support for keyboard for Gentoo

merge -r 1463:1465 $SVN_M/branches/2.2.4

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