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

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

svn merge -r 1923:1938 $SVN_M/branches/2.2.6

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