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

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

Fix a bug in USB part for syslinux error code

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