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

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

Better messages for mindi on initramfs/initrd detection

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