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

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

Continue to remove floppy support

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