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

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

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

  • Property svn:keywords set to Rev Id
File size: 104.5 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 1977 2008-06-02 08:49:01Z 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/*.gz $MINDI_TMP/iso/images 2>> $LOGFILE || LogIt "OfferToMakeBootableISO: Cannot copy $1/*.gz 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 rm -f images/mindi-bootroot.$BOOT_SIZE.img
1430 fi
1431 if [ "$?" -ne "0" ] ; then
1432 echo "----------- $ISO_CMD's errors --------------" >> $LOGFILE
1433 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
1434 echo "$ISO_CMD returned the following errors:-"
1435 cat $MINDI_TMP/mkisofs.log
1436 LogIt "Failed to create ISO image."
1437 else
1438 echo "Created bootable ISO image at $MINDI_CACHE/mindi.iso" | tee -a $LOGFILE
1439 fi
1440 rm -f $MINDI_TMP/mkisofs.log
1441 cd $old_pwd
1442}
1443
1444
1445OfferToMakeBootableUSB() {
1446 local i old_pwd
1447 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1448 echo -n "Shall I make a bootable USB image ? (y/[n]) "
1449 read i
1450 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1451 if [ "$USBDEVICE" = "" ]; then
1452 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1453 read dev
1454 USBDEVICE=$dev
1455 fi
1456 echo "WARNING: This will erase all content on $USBDEVICE"
1457 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1458 fi
1459 if [ _"$MINDI_TMP" = _"" ]; then
1460 Die "MINDI_TMP undefined"
1461 fi
1462 rm -Rf $MINDI_TMP/usb
1463 mkdir -p $MINDI_TMP/usb
1464 USBPART="${USBDEVICE}1"
1465
1466 echo -en "Transforming $USBDEVICE in a Bootable device "
1467 echo -en "."
1468 echo "Transforming $USBDEVICE in a Bootable device" >> $LOGFILE
1469 echo "Checking $USBDEVICE" >> $LOGFILE
1470 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
1471 if [ $? -ne 0 ]; then
1472 echo "Unable to access $USBDEVICE" | tee -a $LOGFILE
1473 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1474 exit -1
1475 fi
1476 echo -en "."
1477 echo "Unmounting $USBDEVICE just in case" >> $LOGFILE
1478 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1479 echo "Erasing $USBDEVICE" >> $LOGFILE
1480 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
1481d
1482d
1483d
1484d
1485n
1486p
14871
1488
1489
1490t
1491b
1492a
14931
1494w
1495EOF
1496 if [ $? -ne 0 ]; then
1497 echo "Unable to create a vfat Filesystem on $USBDEVICE" | tee -a $LOGFILE
1498 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
1499 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1500 MindiExit -1
1501 fi
1502 echo -en "."
1503 echo "Creating a vfat filesystem on $USBPART" >> $LOGFILE
1504 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
1505 if [ $? -ne 0 ]; then
1506 echo "Unable to create a vfat filesystem on $USBPART" | tee -a $LOGFILE
1507 echo "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)" | tee -a $LOGFILE
1508 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1509 MindiExit -1
1510 fi
1511 echo -en "."
1512 echo "Mounting $USBPART on $MINDI_TMP/usb" >> $LOGFILE
1513 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1514 if [ $? -ne 0 ]; then
1515 echo "Unable to mount $USBPART on $MINDI_TMP/usb" | tee -a $LOGFILE
1516 echo "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)" | tee -a $LOGFILE
1517 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1518 MindiExit -1
1519 fi
1520 echo -en "."
1521 mkdir -p $MINDI_TMP/usb/images
1522 cp -f $1/*.img $1/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogIt "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
1523 echo -en "."
1524 old_pwd=`pwd`
1525 cd $MINDI_TMP/usb
1526 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1527 for i in memdisk memtest.bin memtest.img ; do
1528 j=$MINDI_LIB/$i
1529 k=$MINDI_TMP/usb
1530 if [ -e "$j" ] ; then
1531 LogIt "Copying $j to $k"
1532 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1533 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
1534 fi
1535 done
1536 echo -en "."
1537 MakeSyslinuxMessageFile $MINDI_TMP/usb/message.txt
1538 echo -en "."
1539 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?"
1540 echo -en "."
1541 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1542 echo -en "."
1543 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
1544 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?"
1545 echo -en "."
1546 if [ "$NFS_DEV" != "" ] ; then
1547 perl -pi -e 's/interactive/iso/' syslinux.cfg
1548 fi
1549 cd $old_pwd
1550 echo -en "."
1551 umount $MINDI_TMP/usb
1552 if [ "$ARCH" != "ia64" ] ; then
1553 syslinux $USBPART 2>> $MINDI_TMP/syslinux.log
1554 if [ "$?" -ne "0" ] ; then
1555 echo "----------- syslinux's errors --------------" |tee -a $LOGFILE
1556 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1557 LogIt "Failed to create USB image."
1558 else
1559 echo -e "$DONE"
1560 echo "Created bootable USB image on $USBDEVICE" >> $LOGFILE
1561 fi
1562 rm -f $MINDI_TMP/syslinux.log
1563 else
1564 echo "No USB boot support for ia64" | tee -a $LOGFILE
1565 MindiExit -1
1566 fi
1567 echo -en "."
1568}
1569
1570
1571MakeMessageFile() {
1572 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
1573 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`"/
1574 else
1575 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`/
1576 fi
1577 if [ _"$MONDO_SHARE" != _"" ]; then
1578 if [ "$CDRECOVERY" != "yes" ] ; then
1579 if [ "$NFS_DEV" != "" ] ; then
1580 echo -en "Press <enter> to continue.\n"
1581 elif [ ! "$MINDI_TMP" ] ; then
1582 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1583 else
1584 echo -en "$BOOT_MEDIA_MESSAGE"
1585 fi
1586 fi
1587 fi
1588 if [ "$CDRECOVERY" = "yes" ] ; then
1589 echo -en "\
1590To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1591CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1592 fi
1593 echo -en "\n\n\n"
1594}
1595
1596
1597MakeLiloConfFile() {
1598 local options i ooo
1599 options=""
1600
1601 if [ "$ARCH" != "ia64" ] ; then
1602 echo -en "boot=/dev/loop0\ndisk=/dev/loop0\n"
1603 echo -en "install=/boot.b\nmap=/boot.map\n"
1604 fi
1605 if [ "$CDRECOVERY" = "yes" ] ; then
1606 echo -en "default=RESTORE\n"
1607 elif [ _"$MONDO_SHARE" != _"" ]; then
1608 if [ "$NFS_DEV" != "" ] ; then
1609 echo -en "default=iso\n"
1610 else
1611 echo -en "default=interactive\n"
1612 fi
1613 else
1614 echo -en "default=expert\n"
1615 fi
1616
1617 echo -en "prompt\n"
1618 if [ "$ARCH" != "ia64" ] ; then
1619 echo -en "vga=normal\nbackup=/dev/null\nmessage=/message\n"
1620 fi
1621 if [ "$CDRECOVERY" != "yes" ] ; then
1622 echo -en "timeout=300\n"
1623 fi
1624 echo -en "\n"
1625 if [ "$CDRECOVERY" = "yes" ] ; then
1626 options="RESTORE expert"
1627 else
1628 if [ _"$MONDO_SHARE" != _"" ]; then
1629 if [ "$NFS_DEV" != "" ] ; then
1630 options="iso"
1631 else
1632 options="interactive expert compare iso nuke isonuke"
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
2105SizeOfPartition() {
2106 local devpath drive res stub
2107 device=$1
2108 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2109 res=`SizeOfRaidPartition $device`
2110 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2111 echo "$res"
2112 return 0
2113 fi
2114 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2115 res=`$FDISK -s $device 2>> $LOGFILE`
2116 # end patch
2117 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`
2118 [ "$res" = "" ] && res="-1"
2119 echo $res
2120 return 0
2121}
2122
2123
2124SizeOfRaidPartition() {
2125 local real_dev smallest_size silly tmp
2126
2127 silly=999999999
2128 smallest_size=$silly
2129
2130 for real_dev in `GetRaidDevMembers $1` ; do
2131 tmp=`SizeOfPartition $real_dev`
2132 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2133 done
2134
2135 if [ "$smallest_size" = "$silly" ] ; then
2136 echo "-1"
2137 return 1
2138 else
2139 echo "$smallest_size"
2140 return 0
2141 fi
2142}
2143
2144
2145StripComments()
2146{
2147 local tempfile
2148
2149 tempfile=$MINDI_TMP/$$.strip.txt
2150 cp -f $1 $tempfile 2>> $LOGFILE
2151 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2152 rm -f $tempfile
2153 echo "Stripped comments from $2" >> $LOGFILE
2154}
2155
2156
2157
2158StripExecutable()
2159{
2160 local tmpfile
2161
2162 tmpfile=$MINDI_TMP/stripped.$$.dat
2163 [ -d "$1" ] || [ -h "$1" ] && return
2164 cp -f $1 $tmpfile 2>> $LOGFILE
2165 strip $tmpfile 2> /dev/null
2166 if [ "$?" -eq "0" ] ; then
2167 cp -f $tmpfile $1 2>> $LOGFILE
2168 echo "Stripped binary $2" >> $LOGFILE
2169 fi
2170 rm -f $tmpfile
2171}
2172
2173
2174TryToFindKernelPath() {
2175 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2176
2177 we_want_version=`uname -r`
2178 possible_kernels=""
2179 duff_kernels=""
2180
2181 if [ "$ARCH" = "ia64" ] ; then
2182 root="/boot/efi/efi"
2183 else
2184 root="/"
2185 fi
2186 for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
2187 [ ! -e "$fname" ] && continue
2188 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2189 file $fname | grep -q gzip
2190 if [ "$?" -eq "0" ] ; then
2191 # Used by ia64
2192 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2193 else
2194 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2195 fi
2196 [ "$fkern_ver" = "" ] && continue
2197 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2198 [ -f "$fname" ] || continue
2199 [ -h "$fname" ] && continue
2200 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2201 file $fname | grep -q gzip
2202 if [ "$?" -eq "0" ] ; then
2203 # Used by ia64
2204 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2205 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2206 duff_kernels="$fname $duff_kernels"
2207 else
2208 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2209 possible_kernels="$fname $possible_kernels"
2210 fi
2211 else
2212 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2213 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2214 duff_kernels="$fname $duff_kernels"
2215 else
2216 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2217 possible_kernels="$fname $possible_kernels"
2218 fi
2219 fi
2220 done
2221 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2222 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2223 fi
2224 if [ ! "$possible_kernels" ] ; then
2225 LogIt "No kernel matches exactly. Are there any duff kernels?"
2226 possible_kernels="$duff_kernels"
2227 if [ ! "$possible_kernels" ] ; then
2228 LogIt "Sorry, no duff kernels either"
2229 else
2230 LogIt "I bet you're running Debian or Gentoo, aren't you?"
2231 LogIt "Your kernel doesn't have a sane builddate. Oh well..."
2232 fi
2233 fi
2234 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2235 noof_kernels=`CountItemsIn "$possible_kernels"`
2236 if [ "$noof_kernels" -eq "0" ] ; then
2237 LogIt "Could not find your kernel."
2238 if [ -e "/boot/vmlinuz" ] ; then
2239 LogIt "Using /boot/vmlinuz as a last resort."
2240 output=/boot/vmlinuz
2241 else
2242 output=""
2243 fi
2244 elif [ "$noof_kernels" -eq "1" ] ; then
2245 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2246 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE
2247 output="$kernelpath"
2248 else
2249 for i in $possible_kernels ; do
2250 if echo $i | grep "`uname -r`" ; then
2251 LogIt "OK, I used my initiative and found that "
2252 LogIt "$i is probably your kernel. "
2253 output="$i"
2254 return
2255 fi
2256 done
2257 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2258 output=/boot/vmlinuz
2259 echo "Schlomo, this one's for you." >> $LOGFILE
2260 else
2261 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2262 LogIt "boot disks will still work, probably. If one does not work, try another."
2263 LogIt "$possible_kernels"
2264 echo ""
2265 fi
2266 fi
2267 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2268}
2269
2270
2271TurnTgzIntoRdz() {
2272 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
2273
2274 tgz_dir_fname=$1
2275 rdz_fname=$2
2276 ramdisksize=$3
2277 kernelsize=$4
2278 maxsize=$(($BOOT_SIZE-$kernelsize))
2279 maxsize=$(($maxsize*2)); # to allow for compression of 50%
2280 tempfile=$MINDI_TMP/temp.rd
2281 mountpoint=$MINDI_TMP/mnt1
2282 res=0
2283 echo -en "..."
2284 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"
2285 echo -en "..."
2286 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
2287 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2288 echo -en "..."
2289 mkdir -p $mountpoint
2290 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."
2291 echo -en "..."
2292 old_pwd=`pwd`
2293 cd $mountpoint
2294 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
2295 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
2296
2297 cd dev || Die "Can't cd to dev"
2298 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2299 rm -f dev-entries.tgz
2300 cd ..
2301
2302 for w in insmod.static insmod.static.old ; do
2303 s=`which $w 2> /dev/null`
2304 if [ -e "$s" ] ; then
2305 tar cf - $s 2> /dev/null | tar xf -
2306 fi
2307 done
2308
2309 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2310
2311 # Handle the case where busybox and mount are dynamically linked
2312 file $MINDI_LIB/rootfs/bin/busybox 2>&1 | grep -q "dynamically"
2313 if [ $? -eq 0 ]; then
2314 # We want to use the real mount and all the supported variants (nfs, cifs, ...)
2315 rm -f bin/mount $MINDI_TMP/busy.lis
2316 mountlis=`grep mount $DEPLIST_FILE`
2317 for f in $MINDI_LIB/rootfs/bin/busybox $mountlis ; do
2318 if [ -f $f ]; then
2319 LocateDeps $f >> $MINDI_TMP/busy.lis
2320 fi
2321 done
2322 tar cf - $mountlis `sort -u $MINDI_TMP/busy.lis` 2> /dev/null | tar xf -
2323 rm -f $MINDI_TMP/busy.lis
2324 fi
2325
2326 mkdir -p $mountpoint/tmp
2327 # Management of udev (which includes modprobe in rules)
2328 ps auxww | grep -v grep | grep -qw udevd
2329 if [ $? -eq 0 ]; then
2330 echo "udev device manager found" > $mountpoint/tmp/USE-UDEV
2331 LogIt "udev device manager found"
2332 tar cf - /etc/udev 2> /dev/null | tar xf -
2333 # This avoids NIC remapping if on another machine at restore time on Debian at least
2334 rm -f ./etc/udev/rules.d/z25_persistent-net.rules
2335 tar cf - /lib*/udev 2> /dev/null | tar xf -
2336 if [ -x /sbin/udevd ]; then
2337 lis2=`grep -Ev '^#' $MINDI_CONF/udev.files`
2338 lis=""
2339 # Get only the files which exist in that list
2340 # and potentially their symlink structure
2341 for i in $lis2; do
2342 if [ -h $i ]; then
2343 j=$i
2344 while [ -h $j ]; do
2345 lis="$lis $j"
2346 j=`readlink $j`
2347 done
2348 lis="$lis $j"
2349 elif [ -f $i ]; then
2350 lis="$lis $i"
2351 fi
2352 done
2353 # And their deps
2354 LocateDeps $lis > $MINDI_TMP/udev.lis
2355 for i in $lis; do
2356 if [ "`echo $i | cut -c1`" = "/" ]; then
2357 j=`echo $i | cut -c2-`
2358 rm -f $j
2359 fi
2360 done
2361 tar cf - $lis `sort -u $MINDI_TMP/udev.lis` 2> /dev/null | tar xf -
2362 rm -f $MINDI_TMP/udev.lis
2363 else
2364 echo "udevd daemon not in standard place (/sbin)" 2>&1 | tee -a $LOGFILE
2365 echo "mindi will use static devices which may cause problems" 2>&1 | tee -a $LOGFILE
2366 rm -f $mountpoint/tmp/USE-UDEV
2367 fi
2368 fi
2369
2370 # Management of potential HW info (Proliant only at the moment)
2371 rm -rf $MINDI_CACHE/bkphw
2372 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2373 if [ -d $MINDI_CACHE/bkphw ]; then
2374 LogIt "Hardware Information found and saved ..."
2375 cp -rp $MINDI_CACHE/bkphw .
2376 if [ -f $MINDI_CACHE/tools.files ]; then
2377 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2378 LocateDeps $lis > $MINDI_TMP/tools.lis
2379 tar cf - $lis `sort -u $MINDI_TMP/tools.lis` 2> /dev/null | tar xf -
2380 fi
2381 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2382 mv -f $MINDI_CACHE/mindi-rsthw .
2383 chmod 755 ./mindi-rsthw
2384 fi
2385 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2386 fi
2387
2388 for w in cdrom groovy-stuff ; do
2389 mkdir -p mnt/$w
2390 done
2391 #if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then
2392 #ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"
2393 #fi
2394 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
2395 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
2396 fi
2397
2398 tar cf - /dev/fd0*[1,2][4,7,8]* 2> /dev/null | tar xf -
2399
2400 cd $old_pwd
2401 echo -en "..."
2402 old_pwd=`pwd`
2403 if [ "$YOUR_KERNEL_SUCKS" ] ; then
2404 cd $MINDI_TMP
2405 needed_modules_path=lib/modules/$FAILSAFE_KVER
2406 else
2407 cd /
2408 if [ "${kernelname}" != "" ]
2409 then
2410 needed_modules_path=lib/modules/${kernelname}
2411 else
2412 needed_modules_path=lib/modules/`uname -r`
2413 fi
2414 fi
2415
2416 needed_modules=""
2417 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
2418
2419 if [ "$NFS_DEV" != "" ] ; then
2420 # For PXE boot
2421 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2422 fi
2423 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2424 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2425 fi
2426 for i in $DENY_MODS; do
2427 echo "Removing $i from the list of modules to load" >> $LOGFILE
2428 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2429 done
2430
2431 [ -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."
2432 for i in $list_of_groovy_mods ; do
2433 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
2434 done
2435
2436 for i in $needed_modules ; do
2437 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2438 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
2439 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
2440 tar cf - $i 2>/dev/null | (cd $mountpoint ; tar xf -) || LogIt "Unable to copy $i to $mountpoint"
2441 # Uncompress modules if not using udev and native modprobe
2442 if [ ! -f $mountpoint/tmp/USE-UDEV ]; then
2443 if [ "`echo "$i" | grep -F ".gz"`" ]; then
2444 echo "Uncompressing $i" >> $LOGFILE
2445 gunzip -f $mountpoint/$i
2446 fi
2447 fi
2448 done
2449
2450 # Also copy modules.dep in case of udev so that normal modprobe works
2451 tar cf - /$needed_modules_path/modules.dep 2>/dev/null | (cd $mountpoint ; tar xf -) || LogIt "Unable to copy modules.dep to $mountpoint"
2452
2453 if [ ! -e "/sbin/devfsd" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
2454 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE
2455 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE
2456 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE
2457 rm -f $mountpoint/sbin/devfsd
2458 fi
2459 cd $old_pwd
2460 [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
2461 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2462 rm -f $mountpoint/zero
2463 if [ _"$MONDO_SHARE" != _"" ]; then
2464 cp -f $MONDO_CACHE/mondo-restore.cfg $mountpoint/tmp &> /dev/null || Die "Cannot copy mondo-restore.cfg to ramdisk"
2465 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
2466 fi
2467 mkdir -p $mountpoint/proc
2468 echo "$BOOT_SIZE" > $mountpoint/tmp/$BOOT_SIZE.siz
2469 # Determine what filesystem to use for initrd image
2470 echo "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." >> $LOGFILE
2471 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2472 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2473 case "$gvFileSystem" in
2474 "ext2fs")
2475 # say what will be used
2476 echo "Creating an ext2 initrd image..." >> $LOGFILE
2477 # kernel expects linuxrc in ext2 filesystem
2478 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2479 # unmount loop filesystem and create image file using the standard approach
2480 umount $mountpoint || Die "Cannot unmount $tempfile"
2481 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
2482 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
2483 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2484 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
2485 rm -f ${rdz_fname}.tmp
2486 # log that we are done
2487 echo "...done." >> $LOGFILE
2488 ;;
2489 "initramfs")
2490 # say what will be used
2491 echo "Creating a gzip'ed cpio (AKA initramfs) initrd image..." >> $LOGFILE
2492 # make sure that cpio is there
2493 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2494 # go into filesystem
2495 cd $mountpoint
2496 # kernel expects init in cpio filesystem
2497 ln -sf sbin/init init
2498 # create cpio image file and unmount loop filesystem
2499 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
2500 cd $old_pwd
2501 umount $mountpoint || Die "Cannot unmount $tempfile"
2502 # log that we are done
2503 echo "...done." >> $LOGFILE
2504 ;;
2505 *)
2506 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2507 ;;
2508 esac
2509 if [ "$res" -eq "0" ] ; then
2510 echo -en "..."
2511 else
2512 echo -en "\rMade an rdz WITH ERRORS. \n"
2513 fi
2514 return 0
2515}
2516
2517
2518WhichOfTheseModulesAreLoaded() {
2519 local modname loaded_modules
2520 loaded_modules="$MODULES"
2521 for modname in $1 ; do
2522 [ "`echo "$loaded_modules" | grep -w "$modname"`" ] && echo "$modname"
2523 done
2524}
2525
2526
2527
2528##############################################################################
2529#----------------------------------- Main -----------------------------------#
2530##############################################################################
2531
2532# Now we can create what we need
2533mkdir -p $MINDI_TMP
2534
2535# Purge from potential old run
2536if [ _"$MINDI_CACHE" = _"" ]; then
2537 Die "MINDI_CACHE undefined"
2538fi
2539rm -rf $MINDI_CACHE/* 2> /dev/null
2540mkdir -p $MINDI_CACHE
2541
2542if [ "$1" = "--printvar" ] ; then
2543 shift
2544 if [ _"$1" != _"" ] ; then
2545 set | grep -Ew "^$1" | cut -d= -f2
2546 fi
2547 MindiExit 0
2548fi
2549
2550> $LOGFILE
2551echo "mindi v$MINDI_VERSION" >> $LOGFILE
2552echo "$ARCH architecture detected" >> $LOGFILE
2553echo "mindi called with the following arguments:" >> $LOGFILE
2554echo "$@" >> $LOGFILE
2555echo "Start date : `date`" >> $LOGFILE
2556echo "-----------------------------" >> $LOGFILE
2557
2558[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2559
2560# Log some capital variables
2561[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2562echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
2563echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE
2564echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE
2565[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2566echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE
2567if [ -f $MINDI_CONFIG ]; then
2568 echo "-----------------------------" >> $LOGFILE
2569 echo " Mindi configuration file " >> $LOGFILE
2570 echo "-----------------------------" >> $LOGFILE
2571 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
2572 echo "-----------------------------" >> $LOGFILE
2573fi
2574
2575
2576trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2577
2578# Sanity checks
2579which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2580which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2581which 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."
2582which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2583if which awk &> /dev/null ; then
2584 if ! which gawk &> /dev/null ; then
2585 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"
2586 fi
2587fi
2588which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2589[ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"
2590
2591[ "`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"
2592
2593# Update the PATH variable if incomplete
2594if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2595 PATH=$PATH:/sbin:/usr/sbin
2596 export PATH
2597 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE
2598 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE
2599 echo " Or you might like to call 'su -' instead of 'su', for example." >> $LOGFILE
2600fi
2601
2602# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2603if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2604 source $MINDI_LIB/FindDistroFailsafe
2605 # Log kernel image
2606 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2607else
2608 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2609fi
2610
2611if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
2612 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2613fi
2614
2615### BERLIOS
2616### Fix as it's not mandatory on ia64
2617if [ "$ARCH" = "ia64" ] ; then
2618 if which elilo &> /dev/null ; then
2619 LILO_EXE=elilo
2620 else
2621 LILO_EXE=`which false`
2622 fi
2623else
2624 FindIsolinuxBinary
2625 FindLiloBinary
2626fi
2627trap "Aborted" SIGTERM
2628DONE="\r\t\t\t\t\t\t\t\tDone. "
2629CHOPSIZE=240
2630BIGNO=0
2631MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
2632
2633#
2634# Kernel management: Attempt to locate kernel specific module path
2635# if module path is found then use it other wise use uname -r to set it...
2636#
2637#
2638kernelpath="$mindi_kernel"
2639if [ "$kernelpath" = "NATIVE" ]; then
2640 kernelpath=""
2641fi
2642if [ "$kernelpath" = "" ]; then
2643 kernelpath=`TryToFindKernelPath`
2644fi
2645kernelname=`echo $kernelpath | cut -d'-' -f2-`
2646echo "kernelname = $kernelname" >> $LOGFILE
2647echo "kernelpath = $kernelpath" >> $LOGFILE
2648if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
2649then
2650 echo "Module path for ${kernelpath} not found..." >> $LOGFILE
2651 echo "using running kernel\'s modules." >> $LOGFILE
2652 kernelname=`uname -r`
2653else
2654 echo "Using modules for kernel: ${kernelname}" >> $LOGFILE
2655fi
2656
2657if [ -d "/proc/lvm" ]; then
2658 # LVM v1
2659 LVMCMD=""
2660 LVM="v1"
2661elif [ -d "/dev/mapper" ]; then
2662 # LVM v2
2663 LVMCMD="lvm"
2664 LVM="v2"
2665else
2666 LVM="false"
2667fi
2668echo "LVM set to $LVM" >> $LOGFILE
2669echo "----------" >> $LOGFILE
2670echo "mount result:" >> $LOGFILE
2671echo "-------------" >> $LOGFILE
2672mount >> $LOGFILE
2673echo "-------------" >> $LOGFILE
2674if [ -e /etc/raidtab ]; then
2675 echo "-------------" >> $LOGFILE
2676 echo "/etc/raidtab content:" >> $LOGFILE
2677 echo "-------------" >> $LOGFILE
2678 cat /etc/raidtab >> $LOGFILE
2679fi
2680echo "-------------" >> $LOGFILE
2681echo "cat /proc/cmdline:" >> $LOGFILE
2682echo "-------------" >> $LOGFILE
2683cat /proc/cmdline >> $LOGFILE
2684echo "-------------" >> $LOGFILE
2685echo "lsmod result:" >> $LOGFILE
2686echo "-------------" >> $LOGFILE
2687lsmod >> $LOGFILE
2688MODULES="`cat /proc/modules | awk '{print $1}'`"
2689if [ -x /usr/sbin/esxcfg-module ]; then
2690 echo "-------------" >> $LOGFILE
2691 echo "VMWare ESX server detected - Enabling dedicated support" >> $LOGFILE
2692 echo "-------------" >> $LOGFILE
2693 echo "VMWare modules" >> $LOGFILE
2694 echo "-------------" >> $LOGFILE
2695 /usr/sbin/esxcfg-module -l >> $LOGFILE
2696 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | awk '{print $1}'`"
2697fi
2698echo "FORCE_MODS:" >> $LOGFILE
2699echo "-------------" >> $LOGFILE
2700echo $FORCE_MODS >> $LOGFILE
2701echo "-------------" >> $LOGFILE
2702echo "DENY_MODS:" >> $LOGFILE
2703echo "-------------" >> $LOGFILE
2704echo $DENY_MODS >> $LOGFILE
2705echo "-------------" >> $LOGFILE
2706echo "df result:" >> $LOGFILE
2707echo "----------" >> $LOGFILE
2708df -T >> $LOGFILE
2709echo "-------------" >> $LOGFILE
2710echo "Liste of extra modules is:" >> $LOGFILE
2711echo "$EXTRA_MODS" >> $LOGFILE
2712echo "-------------" >> $LOGFILE
2713
2714# Compute libata version
2715laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
2716# If libata v2 is used then remove ide-generic as it will perturbate boot
2717if [ "`echo $MODULES | grep libata`" ]; then
2718 if [ "$laver" = "2" ]; then
2719 DENY_MODS="$DENY_MODS ide-generic"
2720 echo "ide-generic removed from module list as your system uses libata v2+" >> $LOGFILE
2721 echo "-------------" >> $LOGFILE
2722 fi
2723fi
2724
2725FLOPPY_WAS_MOUNTED=""
2726for mtpt in /media/floppy /mnt/floppy /floppy ; do
2727 if mount | grep -w $mtpt &> /dev/null ; then
2728 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2729 umount $mtpt
2730 fi
2731done
2732
2733#
2734# If we have a USB device we need to store info
2735# and remove it from the parameters line
2736#
2737if [ "$#" -ne "0" ] ; then
2738 if [ "$1" = "--usb" ] ; then
2739 shift
2740 USBDEVICE=$1
2741 if [ _"$USBDEVICE" = _"" ]; then
2742 Die "No USB device specified"
2743 fi
2744 shift
2745 fi
2746fi
2747
2748#
2749# Default value for parameters coming from mondo potentially
2750#
2751if [ "$ARCH" = "ia64" ] ; then
2752 USE_LILO=yes
2753else
2754 USE_LILO=no
2755fi
2756
2757#
2758# These variables are normaly only significant in a mondo environment
2759# Not enforced yet
2760#
2761CDRECOVERY="no"
2762NOT_BOOT="no"
2763EXCLUDE_DEVS=""
2764IMAGE_DEVS=""
2765NFS_DEV=""
2766
2767#
2768# Deal with parameters
2769#
2770if [ "$#" -ne "0" ] ; then
2771 if [ "$1" = "--findkernel" ] ; then
2772 res=`TryToFindKernelPath`
2773 # Avoids logfile content for mondo
2774 export MONDO_SHARE=""
2775 if [ "$res" = "" ] ; then
2776 MindiExit -1
2777 else
2778 echo "$res"
2779 MindiExit 0
2780 fi
2781 elif [ "$1" = "--locatedeps" ] ; then
2782 [ ! "$2" ] && Die "Please specify the binary to look at"
2783 LocateDeps $2
2784 # Avoids logfile content for mondo
2785 export MONDO_SHARE=""
2786 MindiExit $?
2787 elif [ "$1" = "--readalllink" ] ; then
2788 [ ! "$2" ] && Die "Please specify the binary to look at"
2789 ReadAllLink $2
2790 # Avoids logfile content for mondo
2791 export MONDO_SHARE=""
2792 MindiExit $?
2793 elif [ "$1" = "--makemountlist" ] ; then
2794 [ ! "$2" ] && Die "Please specify the output file"
2795 MakeMountlist $2
2796 # Avoids logfile content for mondo
2797 export MONDO_SHARE=""
2798 MindiExit $?
2799 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2800 echo "Mindi v$MINDI_VERSION"
2801 # Avoids logfile content for mondo
2802 export MONDO_SHARE=""
2803 MindiExit 0
2804 elif [ "$1" = "--custom" ] ; then
2805 if [ _"$MONDO_SHARE" = _"" ]; then
2806 Die "--custom is reserved for mondoarchive calls"
2807 fi
2808 MONDO_TMP=$2
2809 # Change MINDI_TMP for the one provided by mondo
2810 # So that it can get back the built files
2811 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
2812 rmdir $MINDI_TMP
2813 export MINDI_TMP=$MONDO_TMP
2814 mkdir -p $MINDI_TMP
2815 # This is the scratch dir in mondo - subdir images
2816 MINDI_CACHE=$3
2817 if [ _"$MINDI_CACHE" != _"" ]; then
2818 mkdir -p $MINDI_CACHE
2819 fi
2820
2821 if [ ! -e "$MONDORESTORECFG" ]; then
2822 Die "MONDORESTORECFG undefined. Use an uptodate mondoarchive version"
2823 fi
2824
2825 if [ ! -e "$MONDO_CACHE" ]; then
2826 Die "MONDO_CACHE undefined. Use an uptodate mondoarchive version"
2827 else
2828 #
2829 # Get from mondo our additional configuration
2830 #
2831 echo "Using $MONDO_CACHE/mindi.conf as additional config file"
2832 if [ -f $MONDO_CACHE/mindi.conf ]; then
2833 . $MONDO_CACHE/mindi.conf
2834 echo "-----------------------------" >> $LOGFILE
2835 echo " Mondo configuration file " >> $LOGFILE
2836 echo "-----------------------------" >> $LOGFILE
2837 cat $MONDO_CACHE/mindi.conf >> $LOGFILE
2838 echo "-----------------------------" >> $LOGFILE
2839 else
2840 Die "No mindi.conf file created by mondo. Aborting"
2841 fi
2842 fi
2843
2844 echo "Here is your $MONDORESTORECFG file:" >> $LOGFILE
2845 echo "------------------------------------" >> $LOGFILE
2846 cat $MONDORESTORECFG >> $LOGFILE
2847 echo "-----------------------------------" >> $LOGFILE
2848
2849 CDRECOVERY=`grep use-cdrecovery $MONDORESTORECFG | cut -d'=' -f2`
2850 NOT_BOOT=`grep non-bootable $MONDORESTORECFG | cut -d'=' -f2`
2851 USE_LILO=`grep use-lilo $MONDORESTORECFG | cut -d'=' -f2`
2852 EXCLUDE_DEVS=`grep excluded-devs $MONDORESTORECFG | cut -d'=' -f2`
2853 NFS_DEV=`grep nfs-dev $MONDORESTORECFG | cut -d'=' -f2`
2854 VALUE=`grep image-devs $MONDORESTORECFG | cut -d'=' -f2`
2855 if [ "$VALUE" = "(null)" ] || [ "$VALUE" = "" ] ; then
2856 IMAGE_DEVS=""
2857 else
2858 IMAGE_DEVS="`echo "$VALUE" | tr '|' ' '`"
2859 fi
2860 [ "$CDRECOVERY" = "yes" ] && [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
2861 # MONDO_ROOT is the real scratchdir
2862 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
2863 if [ _"$MONDO_ROOT" != _"" ]; then
2864 mkdir -p $MONDO_ROOT
2865 else
2866 Die "MONDO_ROOT is undefined"
2867 fi
2868 else
2869 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
2870 MindiExit -1
2871 fi
2872fi
2873[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2874if [ "$CDRECOVERY" = "yes" ] ; then
2875 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg
2876 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg
2877else
2878 iso_cfg_file=$MINDI_LIB/isolinux.cfg
2879 sys_cfg_file=$MINDI_LIB/syslinux.cfg
2880fi
2881
2882[ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"
2883if [ _"$MONDO_SHARE" = _"" ]; then
2884 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION"
2885 LogIt "Latest Mindi is available from http://www.mondorescue.org"
2886 LogIt "BusyBox sources are available from http://www.busybox.net"
2887 LogIt "------------------------------------------------------------------------------"
2888else
2889 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> $LOGFILE
2890fi
2891if [ -f $MINDI_LIB/rootfs/bin/busybox ]; then
2892 LogIt "Mindi-`$MINDI_LIB/rootfs/bin/busybox 2>&1 | head -1`"
2893else
2894 LogIt "Unable to find mindi-busybox, please install it"
2895 MindiExit -1
2896fi
2897
2898# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
2899insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
2900for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
2901 insmod $i >> $LOGFILE 2>> $LOGFILE
2902done
2903
2904KERN_DISK_MADE=""
2905
2906if [ "$NOT_BOOT" = "yes" ]; then
2907 LogIt "Just creating a small all.tar.gz for Mondo. Nothing else."
2908 mkdir -p $MINDI_TMP/small-all/tmp
2909 MakeMountlist $MINDI_TMP/small-all/tmp/mountlist.txt
2910 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"
2911 cd $MINDI_TMP/small-all
2912 tar -cv ./tmp | gzip -9 > $MINDI_TMP/all.tar.gz || Die "Cannot make small all.tar.gz"
2913 sync
2914 sleep 2
2915 LogIt "Done. Exiting."
2916 MindiExit 0
2917fi
2918
2919if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2920 LogIt "Including the generation of a Bootable USB device on $USBDEVICE"
2921fi
2922
2923if [ "$kernelpath" = "" ] ; then
2924 if [ _"$MONDO_SHARE" != _"" ]; then
2925 Die "Please use -k <path> to specify kernel."
2926 else
2927 USE_OWN_KERNEL="no"
2928 fi
2929 if [ "$INTERACTIVE" = "yes" ]; then
2930 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2931 read ch
2932 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2933 USE_OWN_KERNEL="yes"
2934 fi
2935 fi
2936 if [ "$USE_OWN_KERNEL" = "yes" ]; then
2937 YOUR_KERNEL_SUCKS=""
2938 kernelpath=`TryToFindKernelPath`
2939 if [ "$kernelpath" = "" ] ; then
2940 echo -n "Please enter kernel path : "
2941 read kernelpath
2942 fi
2943 else
2944 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
2945 fi
2946fi
2947if [ _"$MONDO_SHARE" = _"" ] && [ "$INTERACTIVE" = "yes" ] && [ "$ARCH" != "ia64" ] ; then
2948 USE_LILO=no
2949fi
2950if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
2951 # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2952 if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
2953 source $MINDI_LIB/FindDistroFailsafe
2954 # Log kernel image
2955 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2956 kernelpath="$FAILSAFE_KBIN"
2957 LogIt "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
2958 LogIt "The failsafe kernel is $kernelpath.\n"
2959 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"
2960 LogIt "disks then it may still be a result of a problem with your kernel.\n"
2961 pwd=`pwd`
2962 cd $MINDI_TMP
2963 mkdir -p lib/modules
2964 cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
2965 cd $pwd
2966 else
2967 kernelpath=$MINDI_LIB/vmlinuz
2968 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
2969 LogIt "However, you are still running your kernel. If Mindi fails to create your"
2970 LogIt "disks then it may still be a result of a problem with your kernel."
2971 pwd=`pwd`
2972 cd $MINDI_TMP
2973 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
2974 cd $pwd
2975 fi
2976 YOUR_KERNEL_SUCKS="Your kernel sucks"
2977fi
2978echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
2979[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
2980
2981[ "$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."
2982
2983PrepareDataDiskImages $MINDI_CACHE
2984ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
2985rds=$(($ramdisk_size-$((ramdisk_size%4096))))
2986ramdisk_size=$rds
2987
2988echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE
2989if [ "$ARCH" = "ia64" ] ; then
2990 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create ia64 image disk image."
2991else
2992 if [ "$USE_LILO" = "yes" ] ; then
2993 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
2994 else
2995 PrepareBootDiskImage_SYSLINUX $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
2996 fi
2997fi
2998
2999[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
3000...Or type 'memtest' to test your PC's RAM thoroughly.\n"
3001
3002if [ _"$MONDO_SHARE" = _"" ]; then
3003 ListImagesForUser $MINDI_CACHE
3004 OfferToMakeBootableISO $MINDI_CACHE
3005 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3006 OfferToMakeBootableUSB $MINDI_CACHE
3007 fi
3008 LogIt "Finished."
3009elif [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] ; then
3010 rm -f $MINDI_CACHE/{*img,*iso}
3011 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3012 OfferToMakeBootableUSB $MINDI_CACHE
3013 fi
3014 OfferToMakeBootableISO $MINDI_CACHE
3015 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3016 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
3017 else
3018 Die "Cannot find all.tar.gz, to be written to tape"
3019 fi
3020elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3021 OfferToMakeBootableUSB $MINDI_CACHE
3022else
3023 OfferToMakeBootableISO $MINDI_CACHE
3024fi
3025# cleanup
3026LogIt "$FRIENDLY_OUTSTRING"
3027for mtpt in $FLOPPY_WAS_MOUNTED ; do
3028 mount $mtpt
3029done
3030MindiExit 0
Note: See TracBrowser for help on using the repository browser.