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

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

Add the possibility for mindi to support via configuration file
a set of modules to necessary load (good for cloning capacities)

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