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

Last change on this file since 1904 was 1904, checked in by Bruno Cornec, 16 years ago

merge -r 1889:1902 svn+ssh://bruno@svn.mondorescue.org/mondo/svn/mondorescue/branches/2.2.6

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