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
RevLine 
[747]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#
[1573]8# Mindi can create a multi-image boot/root kit. The first image is the boot
[747]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)
[1570]16ARCH=`/bin/uname -m`
[747]17
[925]18#RUN_AFTER_INITIAL_BOOT_PHASE="echo \"Who lives in a pineapple under the sea?\" > /tmp/spongebob.squarepants.txt"
[1886]19 # after booting from image/CD but before
[747]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
[1693]28MINDI_REV=PBREV
29MINDI_VER=PBVER
[747]30
31MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
32MINDI_PREFIX=XXX
33MINDI_CONF=YYY
34MINDI_SBIN=${MINDI_PREFIX}/sbin
[934]35MINDI_LIB=LLL
[747]36
[1047]37MINDI_CONFIG_DIST="$MINDI_CONF/mindi.conf.dist"
[1060]38if [ ! -f $MINDI_CONFIG_DIST ]; then
39 echo "Unable to find $MINDI_CONFIG_DIST. Please reinstall mindi"
[1063]40 exit -1
[1047]41fi
[1060]42md5sum --status -c "$MINDI_CONF/mindi.conf.dist.md5"
43if [ $? -ne 0 ]; then
44 echo "$MINDI_CONF/mindi.conf.dist md5 checksum incorrect. Please reinstall mindi"
[1063]45 exit -1
[1060]46fi
[1047]47. $MINDI_CONFIG_DIST
[925]48
[1047]49MINDI_CONFIG="$MINDI_CONF/mindi.conf"
[1097]50if [ ! -f $MINDI_CONFIG ] && [ "_$1" = "_" ]; then
[1060]51 echo "No $MINDI_CONFIG file found using sensible values from $MINDI_CONFIG_DIST"
[1047]52else
[1097]53 if [ "_$1" = "_" ]; then
[1087]54 echo "Using $MINDI_CONFIG as additional config file to $MINDI_CONFIG_DIST"
55 fi
[1047]56 . $MINDI_CONFIG
57fi
58
59#
60# Manages defaults coming from conf files
61#
62INTERACTIVE="$mindi_interactive"
63
[1347]64if [ "$INTERACTIVE" = "yes" ]; then
[747]65 # 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
[1047]67 PROMPT_MAKE_CD_IMAGE="yes"
[747]68
[1063]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
[747]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.
[1047]76 USE_OWN_KERNEL="no"
77fi
[925]78
[1063]79EXTRA_SPACE=$mindi_extra_space
[1600]80MAX_DISKS=$mindi_max_disks
[1281]81BOOT_SIZE=$mindi_boot_size
[1063]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"
[1087]86PROMPT_MAKE_TAPE_IMAGE="$mindi_write_tape"
[1063]87USE_OWN_KERNEL="$mindi_use_own_kernel"
[1087]88MINDI_CACHE="$mindi_cache_dir"
[1063]89TMPDIR="$mindi_tmp_dir"
[1087]90USBDEVICE="$mindi_usb_device"
91TAPEDEV="$mindi_tape_device"
[1063]92ADDITIONAL_BOOT_PARAMS="$mindi_boot_params"
93MY_FSTAB="$mindi_etc_fstab"
94LOGFILE="$mindi_log_file"
[1060]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"
[1573]100CDROM_MODS="$TAPE_MODS $IDE_MODS $mindi_cdrom_mods $USB_MODS $PCMCIA_MODS"
[1060]101NET_MODS="$mindi_net_mods"
[1671]102# BERLIOS: Handle the case where all is passed (cloning mode)
[1060]103EXTRA_MODS="$CDROM_MODS $mindi_extra_mods $mindi_additional_mods"
[1535]104DENY_MODS="$mindi_deny_mods"
105FORCE_MODS="$mindi_force_mods"
106ISO_CMD="$mr_iso_creation_cmd"
107ISO_OPT="$mr_iso_creation_opt"
[925]108
[1047]109BOOT_MEDIA_MESSAGE="$mindi_boot_msg"
[925]110FDISK=$MINDI_SBIN/parted2fdisk
[940]111
[1489]112# Now we can create what we need
113export MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
114
[747]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
[1087]143 [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
[747]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
[1075]163 mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
[747]164 if [ ! -e "$mappath" ] ; then
[963]165 LogIt "Cannot add $mappath: kbd map file not found"
[747]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
[1924]173 tar cf - $mappath 2>> /dev/null | (cd $bigdir ; tar xf -) || LogIt "AKMF -- Could not copy $mappath to $bigdir"
[747]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
[925]180 if [ ! -e "$included_item" ] ; then
[1075]181 sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
182 [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
[925]183 for ii in $sss ; do
[747]184 [ -e "$ii" ] && AddKeyboardMappingFile $ii
[925]185 done
186 else
187 AddKeyboardMappingFile $included_item
188 fi
[747]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
[1060]200 [ -d "$filename" ] && Die "Cannot chop up $filename: it's a directory. Please amend $DEPLIST_FILE accordingly."
[747]201 mkdir -p $outdir
202
203 sliceno=0
[940]204 scratchfile=$MINDI_TMP/blah.$$.dat
[963]205 cp -f $filename $scratchfile 2>> $LOGFILE || Die "CUACF -- cannot copy $filename to $scratchfile - did you run out of disk space?"
[747]206 [ "`head $scratchfile -n1 | grep -F "bin/sh"`" != "" ] && StripComments $scratchfile "-$filename-"
207 [ "`echo "$filename" | grep -F "etc/termcap"`" != "" ] && StripComments $scratchfile "-$filename-"
[1924]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
[925]211 mv $scratchfile $scratchfile.gz
[963]212 gunzip -f $scratchfile || LogIt "Cannot gunzip $scratchfile.gz"
[925]213 filename=`echo "$filename" | tr '.' '#' | sed s/#o#gz/#o/ | sed s/#ko#gz/#ko/ | tr '#' '.'`
[747]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
[963]221 dd if=$scratchfile skip=$(($sliceno*$slicesize)) of=$outdir/slice-$biggienumber.`printf "%03d" $sliceno` bs=1k count=$slicesize &> /dev/null
[747]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
[963]236 LogIt "boot.b files built into lilo; I'll create a dummy."
[747]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
[963]245 LogIt "Nor can I find it from your /etc/lilo.conf file. This is very odd."
[747]246 copy_from=`FindSensibleBootBFile`
[963]247 LogIt "I'm going to use '$copy_from'"
[747]248 fi
249 fi
[963]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)"
[747]251}
252
253
254CopyDependenciesToDirectory() {
[1529]255 local outdir incoming fname filesize counter d found
[747]256 outdir=$1
257 mkdir -p $outdir
258 incoming=`ReadLine`
259 counter=0
260 while [ "$incoming" != "" ] ; do
[1529]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
[747]275 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir
[1529]276 elif [ -e "$incoming" ] && [ $found = "false" ]; then
[747]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
[1924]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
[963]286 gunzip -f $outdir/$incoming || LogIt "Cannot gunzip $outdir/$incoming"
[925]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
[747]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
[925]311# Last function called before exiting
312# Parameter is exit code value
[931]313MindiExit() {
[925]314 local my_partitions
[747]315
[925]316 echo "Mindi $MINDI_VERSION is exiting" >> $LOGFILE
317 echo "End date : `date`" >> $LOGFILE
[1337]318 if [ _"$MONDO_SHARE" != _"" ] ; then
[1350]319 echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
[1326]320 cat $LOGFILE >> /var/log/mondoarchive.log
[1350]321 echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
[1326]322 fi
[747]323
[925]324 cd /
[1663]325 sync&
[747]326
[1663]327 # Unmount what could remain mounted
[925]328 my_partitions=`mount | grep -F $$ | cut -f1 -d' '`
329 [ "$my_partitions" != "" ] && umount $my_partitions
[940]330 # Clean temporary files only when standalone mindi
[948]331 if [ _"$MINDI_TMP" != _"$MONDO_TMP" ]; then
[940]332 rm -Rf $MINDI_TMP
333 fi
[925]334 exit $1
335}
336
[747]337Die() {
[925]338 local i
[747]339 if [ "$1" = "" ] ; then
[963]340 LogIt "FATAL ERROR"
[747]341 else
[963]342 LogIt "FATAL ERROR. $1"
[747]343 fi
344
[1326]345 LogIt "Please e-mail a copy of $LOGFILE to the mailing list."
[963]346 LogIt "See http://www.mondorescue.org for more information."
[747]347 LogIt "WE CANNOT HELP unless you enclose that file.\n"
[925]348 MindiExit -1
[747]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
[859]359 return 0
[747]360 fi
361 echo -en "Dropping i686-optimized libraries if appropriate"
362 for optimized_lib_name in $list_of_optimized_libraries ; do
[859]363 echo -en "."
364 reason=""
[1489]365 vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
[859]366 echo "$vanilla_lib_name" >> $filelist
367 resolved=$vanilla_lib_name
[747]368 echo "Adding $resolved to filelist" >> $LOGFILE
[861]369 resolved=`ReadAllLink $resolved`
370 echo "Adding $resolved to filelist" >> $LOGFILE
[859]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
[935]375 grep -Fvx "$optimized_lib_name" "$filelist" > $filelist.tmp
[859]376 echo "Replacing it with $vanilla_lib_name" >> $LOGFILE
377 echo "$vanilla_lib_name" >> $filelist.tmp
378 mv -f $filelist.tmp $filelist
[747]379 done
[925]380 $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
[747]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
[963]388 LogIt "Analyzing your keyboard's configuration."
[747]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
[1770]393 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
394 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole-setup
[747]395 if [ ! -e "$KEYDIR" ] ; then
[963]396 LogIt "Keyboard mapping directory not found. I shall use default map at boot-time."
[747]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
[1158]412 echo "keymap-lives-here=/etc/console/boottime.kmap.gz" >> $MINDI_TMP/mondo-restore.cfg
[747]413 KBDEPTH=0
414 mkdir -p $bigdir/etc/console
[963]415 cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
[747]416 echo -e "$DONE"
417 return 0
[1770]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
[1468]428 elif [ -e "/etc/conf.d/keymaps" ] ; then
429 echo "Gentoo-style config detected." >> $LOGFILE
430 keyfile=/etc/conf.d/keymaps
[747]431 else
432 echo -en "Searching for rc.config ..."
433 keyfile=`find /etc -name rc.config | head -n1`
434 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
[963]435 LogIt "Unknown config detected. Default keyboard map will be used."
[747]436 return
437 else
438 echo "Found $keyfile" >> $LOGFILE
439 fi
440 fi
441 if [ ! -e "$KEYDIR/keymaps" ] ; then
[963]442 LogIt "Keyboard mapping directory not found. Default keyboard map will be used."
[747]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
[1468]448 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | tr -d '"' |cut -d'=' -f2` # Gentoo
[747]449 echo "locale=$locale" >> $LOGFILE
[1075]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 " *#.*"`
[747]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
[1886]468 mappath=$(find / -name "*/kbd/keymaps/*/$locale")
[747]469 fi
470 echo "mappath = $mappath" >> $LOGFILE
471 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
[963]472 LogIt "Keyboard mapping file not found. Default keyboard map will be used."
[747]473 return
474 fi
475 echo -en "Adding the following keyboard mapping tables: "
476 mkdir -p $bigdir/tmp
[1158]477 echo "keymap-lives-here=$mappath" >> $MINDI_TMP/mondo-restore.cfg
[747]478 KBDEPTH=0
479 AddKeyboardMappingFile $mappath
480 echo -e "$DONE"
[1082]481 rm -f $MINDI_TMP/keymaps.find
[747]482 return 0
483}
484
485
486FindIsolinuxBinary() {
487 ISOLINUX=/usr/lib/isolinux.bin
488 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
[1500]489 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
[747]490 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
491 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
[1500]492 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
[1886]493 [ ! -e "$ISOLINUX" ] && ISOLINUX=`find / -name isolinux.bin | grep -x "/.*/isolinux.bin"`
[747]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
[925]501 if which lilo.real > /dev/null 2> /dev/null ; then
502 LILO_EXE=lilo.real
[963]503 LogIt "lilo.real found; will be used instead of lilo (*grumble* *mutter*)"
[925]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. :)"
[747]508 else
[925]509 LILO_EXE=`which false`
[747]510 fi
511}
512
[925]513
[747]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"
[925]521 last="$i"
[747]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
[940]532 cd $MINDI_TMP
[747]533 else
534 cd /
535 fi
536 if [ ! -e "$1" ] ; then
[963]537 LogIt "WARNING - cannot search specific path '$1'"
[747]538 return 1
539 fi
540 modpaths=`find $1 -name $2.*o -type f`
[1842]541 #[ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"
[747]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
[940]555 tempfile=$MINDI_TMP/$$.txt
[747]556 incoming=`ReadLine`
557
558 > $tempfile
559 progress=0
560 res=0
561 noof_lines=$2
562 while [ "$incoming" != "" ] ; do
[861]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
[747]570 filelist=`GenerateListForFile "$incoming"`
571 r=$?
[963]572 [ "$r" -ne "0" ] && LogIt "$incoming not found"
[747]573 res=$(($res+$r))
[861]574# echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE
[747]575 for fname in $filelist ; do
[861]576 [ "$fname" != "" ] && echo "$fname" >> $tempfile
[747]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
[861]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`
[1347]602 if [ "$tool" = "$lvmresolved" ]; then
[861]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;}'`
[1347]610 if [ "$lvmversion" = "200" ]; then
[861]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
[747]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`
[1886]659 echo "---------------------------------" >> $LOGFILE
660 echo "List of dependencies: " >> $LOGFILE
661 echo "---------------------------------" >> $LOGFILE
[747]662 for fname in `cat $tempfile` ; do
[1886]663 echo "$fname" | tee -a $LOGFILE >> $outfile.pre
664 LocateDeps $fname | tee -a $LOGFILE >> $outfile.pre
[925]665 progress=$(($progress+1))
[747]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 "%"
[925]671 modres=$(($progress%4))
[747]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
[1063]677 if [ _"$MONDO_SHARE" != _"" ]; then
[925]678 mkdir -p $bigdir/tmp
679 mkdir -p $bigdir/sbin
680 mkdir -p $bigdir/bin
[940]681 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
[963]682 LogIt "\nIncorporating post-nuke tarball"
[925]683 old_pwd=`pwd`
684 cd $bigdir
[963]685 tar -zxf $MINDI_TMP/post-nuke.tgz || LogIt "Error occurred when untarring post-nuke tarball"
[925]686 cd $old_pwd
[747]687 fi
[963]688 if cp -f $MINDI_TMP/mondo*restore $bigdir/usr/bin 2>> $LOGFILE ; then
[925]689 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre
690 else
[963]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."
[925]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
[1886]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
[747]704 fi
[925]705 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
[747]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
[1099]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."
[1770]765 local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs..."
[1099]766
767 # local variables
768 local lvOffset
769 local lvScanRes
770 local lvUseFilesystem
771
772 # say where we are.
[1167]773 echo " GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n" >> $LOGFILE
[1099]774
775 # verify that file exists
776 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
777
[1570]778 # Kernel may be gzip compressed
[1770]779 file $lvKernelImage 2>&1 | grep -q gzip
[1570]780 if [ $? -eq 0 ]; then
[1770]781 lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicInitfs"`
[1570]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
[1099]788
[1570]789 # scan kernel image for initrd filessystem support
[1770]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"`
[1570]791 fi
[1099]792
793 # determine which filesystem to use for initrd image: ext2fs, gzip'ed cpio (initramfs ) or cramfs
[1770]794 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then
[1099]795 lvUseFilesystem="ext2fs"
[1770]796 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then
[1099]797 lvUseFilesystem="initramfs"
[1770]798 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then
[1099]799 lvUseFilesystem="cramfs"
800 else
801 lvUseFilesystem="UNSUPPORTED"
802 fi
803
804 # say what we are using
[1167]805 echo " GetInitrdFilesystemToUse(): Filesytem to use for initrd is $lvUseFilesystem.\n" >> $LOGFILE
[1099]806
807 # return file system to use
808 echo "$lvUseFilesystem"
809
810}
811
[747]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`
[940]831 cd $MINDI_TMP
[747]832 while [ "$incoming" != "" ] ; do
[925]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
[747]839 done
840 cd $pwd
841}
842
843
844ListAllPartitions() {
845 local res currline partition all_partitions ap_orig remaining i j
846
[1770]847 grep -vx " *#.*" $MY_FSTAB | grep -vx " *none.*" | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/fdd|cdr|zip|floppy/ {print $1}'
[747]848 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
[1842]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
[747]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"
[1408]871 module_list="$MODULES"
[1177]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' ' '`
[1770]875 EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1177]876 done
[747]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
[1842]900#
901# Critical function which computes all dependencies (dyn. lib.)
902# for a list of binaries
903#
[747]904LocateDeps() {
905 local incoming fname deps
[1770]906 incoming="$*"
[747]907 for fname in $incoming ; do
908 if [ ! -e "$fname" ] ; then
[963]909 echo "WARNING - $fname does not exist; cannot be LDD'd." >> $LOGFILE
[747]910 if echo $fname | grep lvm &> /dev/null ; then
911 echo "This warning only affects you if you are using LVM." >> $LOGFILE
[1408]912 if echo "$MODULES" | grep lvm &> /dev/null ; then
[747]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
[1529]921 ldd $fname 2> /dev/null | ProcessLDD
[747]922 fi
923 done
924}
925
[925]926
[860]927# Give all symlinks recursively of a full path name
928ReadAllLink() {
929 file="$1"
[747]930
[1886]931 echo "$file"
[860]932 if [ ! -h $file ]; then
933 return 0
934 fi
[747]935
[1886]936 link=`readlink $file`
[862]937 d=`dirname $file`
[1886]938 fchar=`echo $link | cut -c1`
939 # If mother dir is a link print it
[1059]940 if [ -h "$d" ]; then
[1842]941 echo "$d"
[1886]942 d=`readlink $d`
943 fi
944 if [ "$fchar" != "/" ]; then
945 # Relative or local link
946 ReadAllLink "$d/$link"
[860]947 else
[1886]948 # Absolute path
949 ReadAllLink $link
[1058]950 fi
[860]951}
952
[925]953
[747]954LocateFile() {
955 local i path fname_to_find location output resolved tmp stub cache_id loclist
956 fname_to_find="$1"
[1529]957 # It's an absolute path
[747]958 if echo "$fname_to_find" | grep -x "/.*" ; then
[859]959 output="$fname_to_find"
[860]960 if [ -h "$output" ] ; then
961 output="`ReadAllLink $output` $output"
962 fi
[859]963 echo "$output"
964 return 0
[747]965 fi
[1529]966 # It's not an absolute path
[747]967 output=""
[1529]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
[747]976 done
977 if [ "$output" = "" ] ; then
[860]978 return 1
[747]979 fi
980 echo "$output"
981 return 0
982}
983
984
985LogIt() {
986 if [ -e /dev/stderr ] ; then
[925]987 echo -e "$1" >> /dev/stderr
[747]988 elif [ -e /usr/bin/logger ] ; then
[925]989 /usr/bin/logger -s $1
[747]990 fi
[965]991 echo -e "$1" >> $LOGFILE
[747]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
[967]1001 echo "Your raw fstab file looks like this:" >> $LOGFILE
1002 echo "------------------------------------" >> $LOGFILE
[747]1003 cat $MY_FSTAB >> $LOGFILE
[967]1004 echo "Your mountlist will look like this:" | tee -a $LOGFILE
1005 echo "-----------------------------------" >> $LOGFILE
[747]1006
1007# scratchdir, mountlist(OUT)
[940]1008 scratchdir=$MINDI_TMP
[747]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
[1087]1016 [ "$mountlist" != "" ] && rm -Rf $mountlist
[747]1017 > $mountlist
1018 all_partitions=""
1019
1020 if [ $LVM != "false" ]; then
[1193]1021 echo -en "Analyzing LVM...\n"
[968]1022 $MINDI_LIB/analyze-my-lvm > $MINDI_TMP/lvm.res
[971]1023 if [ $? -ne 0 ]; then
[963]1024 LVM="false"
1025 fi
[968]1026 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-32`
[747]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 ' ' '`"
[1770]1034 printf " %-15s %-15s %-15s %-15s %-15s\n" DEVICE MOUNTPOINT FORMAT "SIZE (MB)" LABEL/UUID | tee -a $LOGFILE
[747]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
[861]1040 current_partition=`readlink -f $c_p`
[747]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=""
[1842]1048 label=""
[957]1049 uuid=""
[861]1050 absolute_partition=`readlink -f $c_p`
[747]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
[980]1063 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
[747]1064 actual_dev=""
[853]1065
1066 # 1st try, findfs - the RHEL way of finding labels and their partitions
1067 if [ -x "/sbin/findfs" ]; then
[855]1068 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
[853]1069 fi
[747]1070
[853]1071 # 2nd try : blkid, the good way for all LABEL except swap
1072 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1073 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
[747]1074 # For LVM FS it will give a /dev/dm-# which should then be converted
[748]1075 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1076 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1077 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[747]1078 for dev in `ls /dev/mapper/*`; do
[963]1079 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1080 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[747]1081 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1082 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[747]1083 break
1084 fi
1085 done
1086 fi
1087 fi
1088
[853]1089 # 3rd try, which works on a standard partition (ext2/3), but not on swap
[747]1090 # For LVM gives a /dev/mapper entry
1091 if [ "x$actual_dev" = "x" ]; then
[980]1092 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
[747]1093 fi
1094
[853]1095 # 4th try, with vol_id
[747]1096 # SWAP only
1097 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1098 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
[747]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
[853]1108 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
[789]1109 # LABEL=SW-cciss/c0d0p3 (RDP)
[853]1110 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
[747]1111 # SWAP only
[789]1112 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
[853]1113 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1114 do
1115 # Location of the swap label for kernel 2.6
[1009]1116 try_dev_label=`dd bs=1 count=16 skip=1052 if=$try_dev 2> /dev/null`
[853]1117 if [ "x$try_dev_label" = "x$redhat_label" ]; then
[855]1118 actual_dev=$try_dev
[853]1119 fi
1120 done
[747]1121 fi
[1008]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
[1060]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"
[1008]1128 fi
[957]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
[1009]1131 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
[957]1132 str_to_find_fmt_with=$current_partition
[980]1133 uuid=`echo "$current_partition" | cut -d'=' -f2`
[957]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
[1530]1141 # 2nd try : blkid, the good way for all UUID except swap
[957]1142 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1143 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
[957]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
[963]1146 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1147 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[957]1148 for dev in `ls /dev/mapper/*`; do
[963]1149 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1150 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[957]1151 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1152 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[957]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
[963]1161 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
[957]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
[1530]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
[747]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
[1060]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"
[747]1188 fi
1189 else
[1886]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
[747]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
[755]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
[747]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"
[763]1219 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
[755]1220 # .static dir are a Debian specificity
[763]1221 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
[755]1222 echo $current_lvolume | grep -q ' '
[784]1223 if [ $? -eq 0 ]; then
[755]1224 echo "WARNING: Multiple Logical Volumes found. Report to dev team" >> $LOGFILE
1225 fi
[747]1226 fi
1227 #
1228 # End of LVM device style variation code (other than $current_lvolume).
1229
[745]1230 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1231 # Size computed via LVM not directly
[747]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
[965]1286 echo "------- $FDISK -l $qq log ------------" >> $LOGFILE
[1886]1287 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
[747]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
[965]1291 echo "------- $FDISK log end ------------" >> $LOGFILE
[747]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
[963]1295 LogIt "Unable to find mountpoint of $current_partition - ignoring"
[747]1296 continue
1297 fi
1298 fi
[1770]1299 if [ "$redhat_label" ]; then
1300 label="$redhat_label"
1301 elif [ "$uuid" ]; then
1302 label="$uuid"
1303 fi
[747]1304 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
[963]1305 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
[1770]1306 unofficial_outstring=`printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
[747]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
[1770]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
[747]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
[1770]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
[747]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
[1087]1357 if [ "$NFS_DEV" != "" ] ; then
[747]1358 echo -en "Press <enter> to continue.\n" >> $1
[940]1359 elif [ ! "$MINDI_TMP" ] ; then
[747]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
[1063]1377 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[966]1378 echo -en "Shall I make a bootable CD image? (y/[n]) "
[747]1379 read i
1380 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1381 fi
[1087]1382 if [ _"$MINDI_TMP" = _"" ]; then
1383 Die "MINDI_TMP undefined"
[747]1384 fi
[940]1385 rm -Rf $MINDI_TMP/iso
1386 mkdir -p $MINDI_TMP/iso/{images,archives,isolinux}
[1977]1387 cp -f $1/*.gz $MINDI_TMP/iso/images 2>> $LOGFILE || LogIt "OfferToMakeBootableISO: Cannot copy $1/*.gz to $MINDI_TMP/iso/images"
[747]1388 old_pwd=`pwd`
[940]1389 cd $MINDI_TMP/iso
[747]1390 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1391 for i in memdisk memtest.bin memtest.img ; do
[953]1392 j=$MINDI_LIB/$i
1393 k=$MINDI_TMP/iso/isolinux
1394 if [ -e "$j" ] ; then
[963]1395 LogIt "Copying $j to $k"
[953]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"
[1063]1398 if [ _"$MONDO_SHARE" != _"" ]; then
1399 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1400 fi
[953]1401 fi
[747]1402 done
[940]1403 MakeSyslinuxMessageFile $MINDI_TMP/iso/isolinux/message.txt
[1886]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?"
[1939]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?"
[1063]1406 if [ _"$MONDO_SHARE" != _"" ]; then
[1939]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?"
[1063]1409 fi
[747]1410 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
[940]1411 cd $MINDI_TMP/iso/isolinux
[1075]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?"
[1087]1413 if [ "$NFS_DEV" != "" ] ; then
[1063]1414 perl -pi -e 's/interactive/iso/' isolinux.cfg
[747]1415 fi
1416 if [ "$ARCH" != "ia64" ] ; then
[1075]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?"
[963]1418 cp $ISOLINUX ../ 2>> $LOGFILE
[747]1419 fi
[940]1420 cd $MINDI_TMP/iso
[747]1421 if [ "$ARCH" != "ia64" ] ; then
[1063]1422 if [ _"$MONDO_SHARE" != _"" ]; then
[1075]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
[1063]1425 fi
[1535]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
[747]1427 else
[1535]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
[1977]1429 rm -f images/mindi-bootroot.$BOOT_SIZE.img
[747]1430 fi
1431 if [ "$?" -ne "0" ] ; then
[1535]1432 echo "----------- $ISO_CMD's errors --------------" >> $LOGFILE
[940]1433 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
[1535]1434 echo "$ISO_CMD returned the following errors:-"
[940]1435 cat $MINDI_TMP/mkisofs.log
[963]1436 LogIt "Failed to create ISO image."
[747]1437 else
[1842]1438 echo "Created bootable ISO image at $MINDI_CACHE/mindi.iso" | tee -a $LOGFILE
[747]1439 fi
[940]1440 rm -f $MINDI_TMP/mkisofs.log
[747]1441 cd $old_pwd
1442}
1443
1444
[1063]1445OfferToMakeBootableUSB() {
1446 local i old_pwd
1447 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[1842]1448 echo -n "Shall I make a bootable USB image ? (y/[n]) "
[1063]1449 read i
1450 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
[1770]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]) "
[1063]1458 fi
[1087]1459 if [ _"$MINDI_TMP" = _"" ]; then
1460 Die "MINDI_TMP undefined"
1461 fi
[1063]1462 rm -Rf $MINDI_TMP/usb
1463 mkdir -p $MINDI_TMP/usb
[1087]1464 USBPART="${USBDEVICE}1"
[1063]1465
[1087]1466 echo -en "Transforming $USBDEVICE in a Bootable device "
[1063]1467 echo -en "."
[1087]1468 echo "Transforming $USBDEVICE in a Bootable device" >> $LOGFILE
1469 echo "Checking $USBDEVICE" >> $LOGFILE
[1886]1470 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
[1063]1471 if [ $? -ne 0 ]; then
[1087]1472 echo "Unable to access $USBDEVICE" | tee -a $LOGFILE
[1063]1473 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
[1693]1474 exit -1
[1063]1475 fi
1476 echo -en "."
[1693]1477 echo "Unmounting $USBDEVICE just in case" >> $LOGFILE
[1770]1478 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
[1087]1479 echo "Erasing $USBDEVICE" >> $LOGFILE
[1770]1480 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
[1063]1481d
1482d
1483d
1484d
1485n
1486p
14871
1488
1489
1490t
1491b
1492a
14931
1494w
1495EOF
1496 if [ $? -ne 0 ]; then
[1087]1497 echo "Unable to create a vfat Filesystem on $USBDEVICE" | tee -a $LOGFILE
[1063]1498 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
[1087]1499 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]1500 MindiExit -1
1501 fi
1502 echo -en "."
1503 echo "Creating a vfat filesystem on $USBPART" >> $LOGFILE
[1693]1504 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
[1063]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
[1087]1508 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]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
[1087]1517 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]1518 MindiExit -1
1519 fi
1520 echo -en "."
[1693]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"
[1063]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"
[1075]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?"
[1063]1545 echo -en "."
[1087]1546 if [ "$NFS_DEV" != "" ] ; then
[1063]1547 perl -pi -e 's/interactive/iso/' syslinux.cfg
1548 fi
1549 cd $old_pwd
1550 echo -en "."
[1770]1551 umount $MINDI_TMP/usb
[1063]1552 if [ "$ARCH" != "ia64" ] ; then
1553 syslinux $USBPART 2>> $MINDI_TMP/syslinux.log
[1544]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
[1063]1563 else
1564 echo "No USB boot support for ia64" | tee -a $LOGFILE
1565 MindiExit -1
1566 fi
1567 echo -en "."
1568}
1569
1570
[747]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
[1573]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"
[747]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() {
[1573]1598 local options i ooo
[747]1599 options=""
[925]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
[747]1605 if [ "$CDRECOVERY" = "yes" ] ; then
1606 echo -en "default=RESTORE\n"
[1573]1607 elif [ _"$MONDO_SHARE" != _"" ]; then
[1087]1608 if [ "$NFS_DEV" != "" ] ; then
[747]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
[925]1622 echo -en "timeout=300\n"
[747]1623 fi
1624 echo -en "\n"
1625 if [ "$CDRECOVERY" = "yes" ] ; then
[925]1626 options="RESTORE expert"
[1573]1627 else
[1063]1628 if [ _"$MONDO_SHARE" != _"" ]; then
[1087]1629 if [ "$NFS_DEV" != "" ] ; then
[747]1630 options="iso"
1631 else
1632 options="interactive expert compare iso nuke isonuke"
1633 fi
1634 else
1635 options="expert"
[925]1636 fi
[747]1637 fi
1638 for i in $options ; do
[925]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
[1072]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"
[747]1647
[925]1648 outstr=$outstr" $ooo_mode"
1649 outstr=$outstr"\"\n"
[1573]1650 echo -en "$outstr"
[747]1651 done
1652}
1653
1654
1655PrepareBootDiskImage_LILO() {
[1573]1656 local imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
[747]1657 imagesdir=$1
[1573]1658 kernelpath=$2
1659 ramdisksize=$3
[747]1660
1661 retval=0
1662 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
[1573]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?"
[747]1665 echo -en "..."
[1573]1666 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
[940]1667 mountpoint=$MINDI_TMP/mountpoint.$$
[747]1668 mkdir -p $mountpoint
[1573]1669 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[747]1670 if [ "$ARCH" = "ia64" ] ; then
[964]1671 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1672 t=vfat
[747]1673 else
[1075]1674 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
[1255]1675 mke2fs -N 26 -m 0 -F $imagefile &> /dev/null || Die "Unable to create an ext2 file system on $imagefile"
[964]1676 t=ext2
[747]1677 fi
[963]1678 mount -t $t -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
[964]1679 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]1680 mkdir -p $mountpoint/etc
1681 if [ "$ARCH" != "ia64" ] ; then
1682 liloconf=$mountpoint/etc/lilo.conf
1683 else
[925]1684 liloconf=$mountpoint/elilo.conf
[747]1685 fi
1686 old_pwd=`pwd`
1687 cd $mountpoint
1688 if [ "$ARCH" != "ia64" ] ; then
[963]1689 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
[747]1690 fi
1691 cd $old_pwd
[1312]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."
[747]1695 CopyBootBFile $mountpoint/boot.b
1696
[1573]1697 MakeLiloConfFile > $liloconf
[747]1698
[1072]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
[1770]1711 el=`find /boot/efi -name elilo.efi`
1712 cp $el $mountpoint
[1842]1713 cp $liloconf $mountpoint
[1072]1714 if [ $mountefi -eq 1 ]; then
1715 umount /boot/efi 2>&1 > /dev/null
1716 fi
1717 fi
1718
[940]1719 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint..." >> $LOGFILE
1720 cp -f $MINDI_TMP/mindi.rdz $mountpoint 2>> $LOGFILE
[747]1721 if [ "$?" -ne "0" ] ; then
[963]1722 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[940]1723 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[963]1724 LogIt "Please unload some of your modules and try again."
[940]1725 rm -f $MINDI_TMP/mtpt.$$
[963]1726 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[747]1727 retval=$(($retval+1))
1728 fi
[1573]1729 MakeMessageFile > $mountpoint/message
[747]1730
1731 mkdir -p $mountpoint/tmp
[940]1732 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[747]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
[925]1739 # copy the kernel across
[1087]1740 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]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
[1573]1744 if [ "$?" -ne "0" ] ; then
[925]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\
[1573]1749Sorry, your kernel is too big for your image.\n" >> $LOGFILE
[747]1750 rm -f $mountpoint/vmlinuz
[925]1751 cd $old_pwd
[747]1752 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[963]1753 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[925]1754 # losetup /dev/loop0 -d
1755 rm -f $imagefile
[1573]1756 return 0
[747]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`))
[1573]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
[1842]1762 # make it bootable
[747]1763 rm -f $mountpoint/zero
[963]1764 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[1573]1765 if [ ! "$KERN_DISK_MADE" ] ; then
[747]1766 if [ "$ARCH" != "ia64" ] ; then
[1573]1767 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE
[1842]1768 else
1769 /bin/true
[747]1770 fi
1771 else
[925]1772 echo "Not running LILO. It's not that kind of disk." >> $LOGFILE
[747]1773 fi
[925]1774
1775 # BERLIOS does not test necessarily what it expects
[747]1776 if [ $? -ne "0" ] ; then
[925]1777 if [ "`grep -F "/tmp/dev.0" $LOGFILE`" ] ; then
[963]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."
[925]1781 fi
1782 echo "$LILO_EXE -r $mountpoint ...failed."
1783 echo -en "Press ENTER to continue."; read line
[963]1784 LogIt "Cannot run lilo on $mountpoint\nPlease upgrade/downgrade your version of LILO. It has a bug."
[925]1785 retval=$(($retval+1))
[747]1786 fi
[963]1787 cp -f $liloconf $MINDI_TMP/lilo.conf 2>> $LOGFILE
[747]1788 if [ "$ARCH" = "ia64" ] ; then
[963]1789 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
[747]1790 fi
1791 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1792 echo -en "..."
[963]1793 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]1794 if [ "$retval" -eq "0" ] ; then
[1193]1795 echo -en "...$DONE\n"
[747]1796 if [ "$KERN_DISK_MADE" ] ; then
[1573]1797 LogIt "$BOOT_SIZE KB boot disks were created OK\n"
[747]1798 fi
1799 else
[1193]1800 echo -en "...failed\n"
[1573]1801 LogIt $BOOT_SIZE"KB boot disk was NOT created\n"
[747]1802 rm -f $imagefile
1803 fi
[963]1804 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[747]1805 return $retval
1806}
1807
1808
1809PrepareBootDiskImage_SYSLINUX() {
[1573]1810 local imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
[747]1811 imagesdir=$1
[1573]1812 kernelpath=$2
1813 ramdisksize=$3
[747]1814 do_boot_root_thingy=""
1815 local retval old_pwd
1816 retval=0
[925]1817
[747]1818 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
[1573]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?"
[747]1821 echo -en "..."
[1573]1822 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
[940]1823 mountpoint=$MINDI_TMP/mountpoint.$$
[747]1824 mkdir -p $mountpoint
[1573]1825 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[1121]1826 echo "Creating vfat filesystem on $imagefile" >> $LOGFILE
1827 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
1828 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1829
[963]1830 mount -t vfat -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
[925]1831
1832 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]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"
[1087]1838 if [ "$NFS_DEV" != "" ] ; then
[1063]1839 perl -pi -e 's/interactive/iso/' syslinux.cfg
[747]1840 fi
1841 cd $old_pwd
[940]1842 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint/initrd.img..." >> $LOGFILE
1843 cp -f $MINDI_TMP/mindi.rdz $mountpoint/initrd.img 2>> $LOGFILE
[747]1844 if [ "$?" -ne "0" ] ; then
[963]1845 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[940]1846 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[963]1847 LogIt "Please unload some of your modules and try again."
[940]1848 rm -f $MINDI_TMP/mtpt.$$
[963]1849 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[747]1850 retval=$(($retval+1))
1851 fi
1852
1853 mkdir -p $mountpoint/tmp
[940]1854 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[747]1855
[925]1856 # copy the kernel across
[1087]1857 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]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
[1573]1861 if [ "$?" -ne "0" ] ; then
[747]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\
[1573]1866Sorry, your kernel is too big for your image.\n" >> $LOGFILE
[747]1867 rm -f $mountpoint/vmlinuz
1868 cd $old_pwd
1869 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[963]1870 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]1871
1872 rm -f $imagefile
[1573]1873 return 0
[747]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`))
[1573]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
[925]1879
1880 # make it bootable
[747]1881 rm -f $mountpoint/zero
1882 mkdir -p $mountpoint/etc
[963]1883 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[747]1884 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1885 echo -en "..."
[963]1886 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]1887
1888 if [ "$retval" -eq "0" ] ; then
[1193]1889 echo -en "...$DONE\n"
[747]1890 if [ "$KERN_DISK_MADE" ] ; then
1891 rm -f $imagefile
[1573]1892 LogIt "$BOOT_SIZE KB boot disks were created OK\n"
[747]1893 fi
1894 else
[1193]1895 echo -en "...failed\n"
[1573]1896 LogIt $BOOT_SIZE"KB boot disk was NOT created\n"
[747]1897 rm -f $imagefile
1898 fi
[963]1899 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[747]1900 return $retval
1901}
1902
1903
1904PrepareDataDiskImages() {
[1904]1905 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles
[747]1906
1907 imagesdir=$1
[1904]1908 rm -f $imagesdir/mindi.iso
[940]1909 needlist=$MINDI_TMP/what-we-need.txt
1910 bigdir=$MINDI_TMP/bigdir
[747]1911 mkdir -p $bigdir/usr/bin
1912
[1060]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
[747]1920 res=$?
1921 if [ "$YOUR_KERNEL_SUCKS" ]; then
[925]1922 pwd=`pwd`
[940]1923 cd $MINDI_TMP
[747]1924 for i in `ListKernelModulePaths | HackPathsToFailsafe` ; do
[1924]1925 tar cf - ./$i 2>> $LOGFILE | (cd $bigdir ; tar xf -) || Die "PDDI can't copy $i->$bigdir"
[925]1926 if [ "`du -sk $i | cut -f1`" -lt "$(($CHOPSIZE*2))" ] ; then
[1924]1927 tar cf - $i 2>> $LOGFILE | (cd $bigdir ; tar xf -)
[925]1928 else
1929 ChopUpAndCopyFile $i $bigdir $CHOPSIZE $BIGNO
1930 BIGNO=$(($BIGNO+1))
1931 fi
[747]1932 done
[925]1933 for i in $EXTRA_MODS ; do
[1842]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
[925]1936 for k in $j ; do
1937 if [ "`du -sk $k | cut -f1`" -lt "$CHOPSIZE" ] ; then
[1924]1938 tar cf - $k 2>> $LOGFILE | (cd $bigdir ; tar xf -)
[925]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
[747]1947 else
[925]1948 ListKernelModulePaths >> $needlist
[747]1949 fi
1950 if [ "$res" -ne "0" ] ; then
[1904]1951 Die "You have $res files present in dependency list\nbut absent from filesystem."
[747]1952 fi
1953 FindAndAddUserKeyboardMappingFile
1954 mkdir -p $bigdir/tmp
[1063]1955 if [ _"$MONDO_SHARE" != _"" ]; then
[1163]1956 cp -f $MONDORESTORECFG $bigdir/tmp &> /dev/null
[747]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
[925]1963 # also copy io.sys and msdos.sys, if we can find them
[747]1964 for i in `mount | cut -d' ' -f3` ; do
[925]1965 for j in io.sys msdos.sys ; do
[963]1966 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
[925]1967 done
[747]1968 done
1969
[925]1970 # master boot record, too
[1141]1971 if [ _"$MONDORESTORECFG" != _"" ]; then
[1158]1972 i=`grep bootloader.device $MONDORESTORECFG | cut -d'=' -f2 2> /dev/null`
[1141]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
[747]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'."
[963]1990 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping aux-tools"
[747]1991 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then
[963]1992 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping x11-tools.tgz"
[747]1993 fi
[1063]1994 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
[747]1995 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
[1337]1996 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
[747]1997 fi
[1924]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 -
[747]2000 cd $old_pwd
2001 echo -e "$DONE"
2002 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
[940]2003 MakeMountlist $MINDI_TMP/mountlist.txt
[1904]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"
[1063]2006 if [ _"$MONDO_SHARE" != _"" ]; then
[1904]2007 cp -f $bigdir/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
[1063]2008 fi
[1904]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
[747]2026 FRIENDLY_OUTSTRING="Boot and data disk images were created."
[1904]2027 rm -rf $bigdir
[747]2028 rm -f $needlist
2029}
2030
2031
2032ProcessLDD() {
[1842]2033 local incoming f d nd bd bnd
[747]2034 read incoming
[1842]2035 while [ "$incoming" != "" ]; do
[859]2036 # We take the full path name of the dyn. lib. we want
[1529]2037 incoming=`echo "$incoming" | awk '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
2038 for f in $incoming ; do
[1842]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
[1770]2054 echo "$f"
2055 echo "`ReadAllLink $f`"
[747]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
[925]2073 i=$(($i+1))
2074 read incoming
[747]2075 done
2076 echo "$incoming"
2077}
2078
2079
2080ReplaceIndividualLine() {
2081 local orig_file new_file lino newstring lines_total lines_remaining
[925]2082
[747]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
[925]2089 echo "Can't find string" >> $LOGFILE
2090 return 1
[747]2091 fi
[963]2092 lines_total=`wc -l $orig_file | $AWK '{print $1;}'`
[747]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
[925]2109 res=`SizeOfRaidPartition $device`
2110 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2111 echo "$res"
2112 return 0
[747]2113 fi
[925]2114 # patch from Bill <bill@iwizard.biz> - 2003/08/25
[960]2115 res=`$FDISK -s $device 2>> $LOGFILE`
[925]2116 # end patch
[747]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
[925]2131 tmp=`SizeOfPartition $real_dev`
2132 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
[747]2133 done
2134
2135 if [ "$smallest_size" = "$silly" ] ; then
[925]2136 echo "-1"
2137 return 1
[747]2138 else
[925]2139 echo "$smallest_size"
2140 return 0
[747]2141 fi
2142}
2143
2144
2145StripComments()
2146{
2147 local tempfile
[925]2148
[940]2149 tempfile=$MINDI_TMP/$$.strip.txt
[963]2150 cp -f $1 $tempfile 2>> $LOGFILE
[747]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
[925]2157
[747]2158StripExecutable()
2159{
2160 local tmpfile
[925]2161
[940]2162 tmpfile=$MINDI_TMP/stripped.$$.dat
[747]2163 [ -d "$1" ] || [ -h "$1" ] && return
[963]2164 cp -f $1 $tmpfile 2>> $LOGFILE
[747]2165 strip $tmpfile 2> /dev/null
2166 if [ "$?" -eq "0" ] ; then
[963]2167 cp -f $tmpfile $1 2>> $LOGFILE
[925]2168 echo "Stripped binary $2" >> $LOGFILE
[747]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
[925]2176
[747]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
[1685]2186 for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
[925]2187 [ ! -e "$fname" ] && continue
[747]2188 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
[925]2189 file $fname | grep -q gzip
2190 if [ "$?" -eq "0" ] ; then
2191 # Used by ia64
[747]2192 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[925]2193 else
[747]2194 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[925]2195 fi
[747]2196 [ "$fkern_ver" = "" ] && continue
2197 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
[925]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
[963]2205 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
[925]2206 duff_kernels="$fname $duff_kernels"
2207 else
[747]2208 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2209 possible_kernels="$fname $possible_kernels"
[925]2210 fi
[747]2211 else
[925]2212 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[963]2213 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
[925]2214 duff_kernels="$fname $duff_kernels"
2215 else
[747]2216 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2217 possible_kernels="$fname $possible_kernels"
[925]2218 fi
[747]2219 fi
2220 done
2221 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
[925]2222 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
[747]2223 fi
2224 if [ ! "$possible_kernels" ] ; then
[963]2225 LogIt "No kernel matches exactly. Are there any duff kernels?"
[747]2226 possible_kernels="$duff_kernels"
2227 if [ ! "$possible_kernels" ] ; then
[963]2228 LogIt "Sorry, no duff kernels either"
[747]2229 else
[963]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..."
[747]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
[963]2237 LogIt "Could not find your kernel."
[925]2238 if [ -e "/boot/vmlinuz" ] ; then
[963]2239 LogIt "Using /boot/vmlinuz as a last resort."
[925]2240 output=/boot/vmlinuz
[747]2241 else
[925]2242 output=""
2243 fi
[747]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
[925]2251 LogIt "OK, I used my initiative and found that "
[963]2252 LogIt "$i is probably your kernel. "
[925]2253 output="$i"
2254 return
2255 fi
[747]2256 done
[925]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
[963]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"
[747]2264 echo ""
[925]2265 fi
[747]2266 fi
2267 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2268}
2269
2270
2271TurnTgzIntoRdz() {
[1886]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
[925]2273
[747]2274 tgz_dir_fname=$1
2275 rdz_fname=$2
2276 ramdisksize=$3
[1573]2277 kernelsize=$4
2278 maxsize=$(($BOOT_SIZE-$kernelsize))
[747]2279 maxsize=$(($maxsize*2)); # to allow for compression of 50%
[940]2280 tempfile=$MINDI_TMP/temp.rd
2281 mountpoint=$MINDI_TMP/mnt1
[747]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 "..."
[1075]2286 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
[1770]2287 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
[747]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
[959]2294 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
[747]2295 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
[1924]2296
[747]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
[925]2303 s=`which $w 2> /dev/null`
2304 if [ -e "$s" ] ; then
[1924]2305 tar cf - $s 2> /dev/null | tar xf -
[925]2306 fi
[747]2307 done
2308
2309 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
[1770]2310
[1886]2311 # Handle the case where busybox and mount are dynamically linked
[1842]2312 file $MINDI_LIB/rootfs/bin/busybox 2>&1 | grep -q "dynamically"
2313 if [ $? -eq 0 ]; then
[1939]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 -
[1842]2323 rm -f $MINDI_TMP/busy.lis
2324 fi
2325
[1924]2326 mkdir -p $mountpoint/tmp
[1770]2327 # Management of udev (which includes modprobe in rules)
2328 ps auxww | grep -v grep | grep -qw udevd
2329 if [ $? -eq 0 ]; then
[1924]2330 echo "udev device manager found" > $mountpoint/tmp/USE-UDEV
[1770]2331 LogIt "udev device manager found"
[1924]2332 tar cf - /etc/udev 2> /dev/null | tar xf -
[1842]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
[1924]2335 tar cf - /lib*/udev 2> /dev/null | tar xf -
[1770]2336 if [ -x /sbin/udevd ]; then
[1842]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
[1770]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
[1924]2361 tar cf - $lis `sort -u $MINDI_TMP/udev.lis` 2> /dev/null | tar xf -
[1770]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
[1924]2366 rm -f $mountpoint/tmp/USE-UDEV
[1770]2367 fi
2368 fi
[1842]2369
[1770]2370 # Management of potential HW info (Proliant only at the moment)
[1842]2371 rm -rf $MINDI_CACHE/bkphw
[1770]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 .
[1886]2376 if [ -f $MINDI_CACHE/tools.files ]; then
2377 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2378 LocateDeps $lis > $MINDI_TMP/tools.lis
[1924]2379 tar cf - $lis `sort -u $MINDI_TMP/tools.lis` 2> /dev/null | tar xf -
[1886]2380 fi
[1770]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
[1903]2388 for w in cdrom groovy-stuff ; do
[747]2389 mkdir -p mnt/$w
2390 done
[925]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
[747]2394 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
[925]2395 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
[747]2396 fi
2397
[1924]2398 tar cf - /dev/fd0*[1,2][4,7,8]* 2> /dev/null | tar xf -
[1770]2399
[747]2400 cd $old_pwd
2401 echo -en "..."
2402 old_pwd=`pwd`
2403 if [ "$YOUR_KERNEL_SUCKS" ] ; then
[940]2404 cd $MINDI_TMP
[1573]2405 needed_modules_path=lib/modules/$FAILSAFE_KVER
[747]2406 else
2407 cd /
2408 if [ "${kernelname}" != "" ]
2409 then
[1573]2410 needed_modules_path=lib/modules/${kernelname}
[747]2411 else
[1573]2412 needed_modules_path=lib/modules/`uname -r`
[747]2413 fi
2414 fi
[1573]2415
2416 needed_modules=""
2417 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
[1886]2418
[1087]2419 if [ "$NFS_DEV" != "" ] ; then
[747]2420 # For PXE boot
2421 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2422 fi
[1770]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
[1903]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."
[747]2432 for i in $list_of_groovy_mods ; do
[1573]2433 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
[747]2434 done
[1924]2435
[1573]2436 for i in $needed_modules ; do
[747]2437 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
[940]2438 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
[747]2439 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
[1924]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
[1842]2442 if [ ! -f $mountpoint/tmp/USE-UDEV ]; then
2443 if [ "`echo "$i" | grep -F ".gz"`" ]; then
[1924]2444 echo "Uncompressing $i" >> $LOGFILE
[1770]2445 gunzip -f $mountpoint/$i
[1842]2446 fi
[1770]2447 fi
[1842]2448 done
2449
2450 # Also copy modules.dep in case of udev so that normal modprobe works
[1924]2451 tar cf - /$needed_modules_path/modules.dep 2>/dev/null | (cd $mountpoint ; tar xf -) || LogIt "Unable to copy modules.dep to $mountpoint"
[1842]2452
[1573]2453 if [ ! -e "/sbin/devfsd" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
[747]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
[1087]2460 [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
[747]2461 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2462 rm -f $mountpoint/zero
[1063]2463 if [ _"$MONDO_SHARE" != _"" ]; then
[1087]2464 cp -f $MONDO_CACHE/mondo-restore.cfg $mountpoint/tmp &> /dev/null || Die "Cannot copy mondo-restore.cfg to ramdisk"
[953]2465 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
[747]2466 fi
2467 mkdir -p $mountpoint/proc
[1573]2468 echo "$BOOT_SIZE" > $mountpoint/tmp/$BOOT_SIZE.siz
[1099]2469 # Determine what filesystem to use for initrd image
[1142]2470 echo "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." >> $LOGFILE
[1099]2471 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2472 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2473 case "$gvFileSystem" in
2474 "ext2fs")
2475 # say what will be used
[1842]2476 echo "Creating an ext2 initrd image..." >> $LOGFILE
[1099]2477 # kernel expects linuxrc in ext2 filesystem
[1142]2478 ( cd $mountpoint && ln -sf sbin/init linuxrc )
[1099]2479 # unmount loop filesystem and create image file using the standard approach
2480 umount $mountpoint || Die "Cannot unmount $tempfile"
[1312]2481 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
[1842]2482 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
[1312]2483 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
[1842]2484 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
[1312]2485 rm -f ${rdz_fname}.tmp
[1099]2486 # log that we are done
[1842]2487 echo "...done." >> $LOGFILE
[1099]2488 ;;
2489 "initramfs")
2490 # say what will be used
[1842]2491 echo "Creating a gzip'ed cpio (AKA initramfs) initrd image..." >> $LOGFILE
[1099]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
[1142]2497 ln -sf sbin/init init
[1099]2498 # create cpio image file and unmount loop filesystem
[1939]2499 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
[1099]2500 cd $old_pwd
2501 umount $mountpoint || Die "Cannot unmount $tempfile"
2502 # log that we are done
[1142]2503 echo "...done." >> $LOGFILE
[1099]2504 ;;
2505 *)
2506 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2507 ;;
2508 esac
[747]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
[1408]2520 loaded_modules="$MODULES"
[747]2521 for modname in $1 ; do
[1508]2522 [ "`echo "$loaded_modules" | grep -w "$modname"`" ] && echo "$modname"
[747]2523 done
2524}
2525
2526
2527
2528##############################################################################
[1020]2529#----------------------------------- Main -----------------------------------#
[747]2530##############################################################################
2531
[1886]2532# Now we can create what we need
[1087]2533mkdir -p $MINDI_TMP
[747]2534
[1087]2535# Purge from potential old run
2536if [ _"$MINDI_CACHE" = _"" ]; then
2537 Die "MINDI_CACHE undefined"
2538fi
[1408]2539rm -rf $MINDI_CACHE/* 2> /dev/null
[1087]2540mkdir -p $MINDI_CACHE
2541
[1063]2542if [ "$1" = "--printvar" ] ; then
[1047]2543 shift
2544 if [ _"$1" != _"" ] ; then
[1535]2545 set | grep -Ew "^$1" | cut -d= -f2
[1047]2546 fi
[1063]2547 MindiExit 0
[1047]2548fi
2549
[747]2550> $LOGFILE
2551echo "mindi v$MINDI_VERSION" >> $LOGFILE
2552echo "$ARCH architecture detected" >> $LOGFILE
2553echo "mindi called with the following arguments:" >> $LOGFILE
2554echo "$@" >> $LOGFILE
[800]2555echo "Start date : `date`" >> $LOGFILE
[1087]2556echo "-----------------------------" >> $LOGFILE
[747]2557
2558[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2559
[1010]2560# Log some capital variables
2561[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
[1087]2562echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
[1010]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
[1886]2567if [ -f $MINDI_CONFIG ]; then
[1087]2568 echo "-----------------------------" >> $LOGFILE
2569 echo " Mindi configuration file " >> $LOGFILE
2570 echo "-----------------------------" >> $LOGFILE
[1886]2571 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
[1087]2572 echo "-----------------------------" >> $LOGFILE
2573fi
[1010]2574
[1087]2575
[747]2576trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
[1010]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
[747]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"
[1010]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
[1062]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
[1010]2610
[1770]2611if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
[1010]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
[925]2615### BERLIOS
[747]2616### Fix as it's not mandatory on ia64
2617if [ "$ARCH" = "ia64" ] ; then
[1010]2618 if which elilo &> /dev/null ; then
2619 LILO_EXE=elilo
2620 else
2621 LILO_EXE=`which false`
2622 fi
[747]2623else
2624 FindIsolinuxBinary
2625 FindLiloBinary
2626fi
2627trap "Aborted" SIGTERM
2628DONE="\r\t\t\t\t\t\t\t\tDone. "
2629CHOPSIZE=240
2630BIGNO=0
[1060]2631MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
[1087]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#
[1060]2638kernelpath="$mindi_kernel"
2639if [ "$kernelpath" = "NATIVE" ]; then
2640 kernelpath=""
2641fi
[1087]2642if [ "$kernelpath" = "" ]; then
2643 kernelpath=`TryToFindKernelPath`
2644fi
2645kernelname=`echo $kernelpath | cut -d'-' -f2-`
[1097]2646echo "kernelname = $kernelname" >> $LOGFILE
2647echo "kernelpath = $kernelpath" >> $LOGFILE
[1087]2648if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
2649then
[1097]2650 echo "Module path for ${kernelpath} not found..." >> $LOGFILE
2651 echo "using running kernel\'s modules." >> $LOGFILE
[1087]2652 kernelname=`uname -r`
[1073]2653else
[1097]2654 echo "Using modules for kernel: ${kernelname}" >> $LOGFILE
[1073]2655fi
[747]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
[1020]2668echo "LVM set to $LVM" >> $LOGFILE
2669echo "----------" >> $LOGFILE
[1124]2670echo "mount result:" >> $LOGFILE
2671echo "-------------" >> $LOGFILE
2672mount >> $LOGFILE
2673echo "-------------" >> $LOGFILE
[1326]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
[1420]2681echo "cat /proc/cmdline:" >> $LOGFILE
2682echo "-------------" >> $LOGFILE
2683cat /proc/cmdline >> $LOGFILE
2684echo "-------------" >> $LOGFILE
[1020]2685echo "lsmod result:" >> $LOGFILE
2686echo "-------------" >> $LOGFILE
2687lsmod >> $LOGFILE
[1408]2688MODULES="`cat /proc/modules | awk '{print $1}'`"
[1530]2689if [ -x /usr/sbin/esxcfg-module ]; then
[1842]2690 echo "-------------" >> $LOGFILE
[1500]2691 echo "VMWare ESX server detected - Enabling dedicated support" >> $LOGFILE
2692 echo "-------------" >> $LOGFILE
2693 echo "VMWare modules" >> $LOGFILE
2694 echo "-------------" >> $LOGFILE
[1530]2695 /usr/sbin/esxcfg-module -l >> $LOGFILE
[1770]2696 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | awk '{print $1}'`"
[1500]2697fi
[1886]2698echo "FORCE_MODS:" >> $LOGFILE
[1020]2699echo "-------------" >> $LOGFILE
[1886]2700echo $FORCE_MODS >> $LOGFILE
2701echo "-------------" >> $LOGFILE
2702echo "DENY_MODS:" >> $LOGFILE
2703echo "-------------" >> $LOGFILE
2704echo $DENY_MODS >> $LOGFILE
2705echo "-------------" >> $LOGFILE
[1842]2706echo "df result:" >> $LOGFILE
2707echo "----------" >> $LOGFILE
2708df -T >> $LOGFILE
2709echo "-------------" >> $LOGFILE
[1060]2710echo "Liste of extra modules is:" >> $LOGFILE
2711echo "$EXTRA_MODS" >> $LOGFILE
2712echo "-------------" >> $LOGFILE
[747]2713
[1770]2714# Compute libata version
[1842]2715laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
[1770]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
[747]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
[1075]2733#
2734# If we have a USB device we need to store info
2735# and remove it from the parameters line
2736#
[747]2737if [ "$#" -ne "0" ] ; then
[1075]2738 if [ "$1" = "--usb" ] ; then
2739 shift
[1087]2740 USBDEVICE=$1
2741 if [ _"$USBDEVICE" = _"" ]; then
[1075]2742 Die "No USB device specified"
2743 fi
2744 shift
2745 fi
2746fi
2747
2748#
[1087]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#
[1075]2768# Deal with parameters
2769#
2770if [ "$#" -ne "0" ] ; then
[747]2771 if [ "$1" = "--findkernel" ] ; then
2772 res=`TryToFindKernelPath`
[1337]2773 # Avoids logfile content for mondo
2774 export MONDO_SHARE=""
[747]2775 if [ "$res" = "" ] ; then
[925]2776 MindiExit -1
[747]2777 else
2778 echo "$res"
[925]2779 MindiExit 0
[747]2780 fi
[1770]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 $?
[1842]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 $?
[747]2793 elif [ "$1" = "--makemountlist" ] ; then
2794 [ ! "$2" ] && Die "Please specify the output file"
2795 MakeMountlist $2
[1337]2796 # Avoids logfile content for mondo
2797 export MONDO_SHARE=""
[925]2798 MindiExit $?
2799 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2800 echo "Mindi v$MINDI_VERSION"
[1337]2801 # Avoids logfile content for mondo
2802 export MONDO_SHARE=""
[925]2803 MindiExit 0
[1087]2804 elif [ "$1" = "--custom" ] ; then
[1063]2805 if [ _"$MONDO_SHARE" = _"" ]; then
2806 Die "--custom is reserved for mondoarchive calls"
2807 fi
[940]2808 MONDO_TMP=$2
2809 # Change MINDI_TMP for the one provided by mondo
2810 # So that it can get back the built files
[1010]2811 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
2812 rmdir $MINDI_TMP
[1489]2813 export MINDI_TMP=$MONDO_TMP
[953]2814 mkdir -p $MINDI_TMP
[1770]2815 # This is the scratch dir in mondo - subdir images
[1087]2816 MINDI_CACHE=$3
2817 if [ _"$MINDI_CACHE" != _"" ]; then
2818 mkdir -p $MINDI_CACHE
[938]2819 fi
[1087]2820
2821 if [ ! -e "$MONDORESTORECFG" ]; then
2822 Die "MONDORESTORECFG undefined. Use an uptodate mondoarchive version"
[1075]2823 fi
[1087]2824
2825 if [ ! -e "$MONDO_CACHE" ]; then
2826 Die "MONDO_CACHE undefined. Use an uptodate mondoarchive version"
[747]2827 else
[1087]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
[747]2842 fi
[1087]2843
[1143]2844 echo "Here is your $MONDORESTORECFG file:" >> $LOGFILE
[1087]2845 echo "------------------------------------" >> $LOGFILE
2846 cat $MONDORESTORECFG >> $LOGFILE
2847 echo "-----------------------------------" >> $LOGFILE
2848
[1158]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`
[1087]2855 if [ "$VALUE" = "(null)" ] || [ "$VALUE" = "" ] ; then
[747]2856 IMAGE_DEVS=""
2857 else
[1087]2858 IMAGE_DEVS="`echo "$VALUE" | tr '|' ' '`"
[747]2859 fi
[1087]2860 [ "$CDRECOVERY" = "yes" ] && [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
[1770]2861 # MONDO_ROOT is the real scratchdir
[1087]2862 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
[938]2863 if [ _"$MONDO_ROOT" != _"" ]; then
2864 mkdir -p $MONDO_ROOT
2865 else
2866 Die "MONDO_ROOT is undefined"
2867 fi
[747]2868 else
[925]2869 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
2870 MindiExit -1
[747]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"
[1063]2883if [ _"$MONDO_SHARE" = _"" ]; then
[963]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"
[1685]2887 LogIt "------------------------------------------------------------------------------"
[747]2888else
[1326]2889 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> $LOGFILE
[747]2890fi
[1005]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
[747]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
[1087]2906if [ "$NOT_BOOT" = "yes" ]; then
2907 LogIt "Just creating a small all.tar.gz for Mondo. Nothing else."
[940]2908 mkdir -p $MINDI_TMP/small-all/tmp
[1087]2909 MakeMountlist $MINDI_TMP/small-all/tmp/mountlist.txt
[1924]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"
[940]2911 cd $MINDI_TMP/small-all
[1924]2912 tar -cv ./tmp | gzip -9 > $MINDI_TMP/all.tar.gz || Die "Cannot make small all.tar.gz"
[1087]2913 sync
[1924]2914 sleep 2
[963]2915 LogIt "Done. Exiting."
[925]2916 MindiExit 0
[747]2917fi
2918
[1693]2919if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1087]2920 LogIt "Including the generation of a Bootable USB device on $USBDEVICE"
[1075]2921fi
[1685]2922
[747]2923if [ "$kernelpath" = "" ] ; then
[1063]2924 if [ _"$MONDO_SHARE" != _"" ]; then
2925 Die "Please use -k <path> to specify kernel."
[1842]2926 else
2927 USE_OWN_KERNEL="no"
[747]2928 fi
[1347]2929 if [ "$INTERACTIVE" = "yes" ]; then
[1063]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
[747]2936 if [ "$USE_OWN_KERNEL" = "yes" ]; then
[925]2937 YOUR_KERNEL_SUCKS=""
2938 kernelpath=`TryToFindKernelPath`
2939 if [ "$kernelpath" = "" ] ; then
2940 echo -n "Please enter kernel path : "
2941 read kernelpath
2942 fi
[747]2943 else
[925]2944 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
[747]2945 fi
2946fi
[1347]2947if [ _"$MONDO_SHARE" = _"" ] && [ "$INTERACTIVE" = "yes" ] && [ "$ARCH" != "ia64" ] ; then
[1977]2948 USE_LILO=no
[747]2949fi
2950if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
[1062]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`
[1163]2962 cd $MINDI_TMP
[1062]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
[747]2976 YOUR_KERNEL_SUCKS="Your kernel sucks"
2977fi
[1087]2978echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
[963]2979[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
[747]2980
[965]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."
[747]2982
[1087]2983PrepareDataDiskImages $MINDI_CACHE
[747]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
[1570]2989if [ "$ARCH" = "ia64" ] ; then
[1573]2990 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create ia64 image disk image."
[1570]2991else
2992 if [ "$USE_LILO" = "yes" ] ; then
[1573]2993 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
[747]2994 else
[1573]2995 PrepareBootDiskImage_SYSLINUX $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
[747]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
[1063]3002if [ _"$MONDO_SHARE" = _"" ]; then
[1087]3003 ListImagesForUser $MINDI_CACHE
3004 OfferToMakeBootableISO $MINDI_CACHE
3005 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3006 OfferToMakeBootableUSB $MINDI_CACHE
[1063]3007 fi
[963]3008 LogIt "Finished."
[1087]3009elif [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] ; then
[1904]3010 rm -f $MINDI_CACHE/{*img,*iso}
3011 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3012 OfferToMakeBootableUSB $MINDI_CACHE
3013 fi
[1087]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
[747]3017 else
[925]3018 Die "Cannot find all.tar.gz, to be written to tape"
[747]3019 fi
[1770]3020elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1087]3021 OfferToMakeBootableUSB $MINDI_CACHE
[747]3022else
[1087]3023 OfferToMakeBootableISO $MINDI_CACHE
[747]3024fi
3025# cleanup
[963]3026LogIt "$FRIENDLY_OUTSTRING"
[747]3027for mtpt in $FLOPPY_WAS_MOUNTED ; do
3028 mount $mtpt
3029done
[925]3030MindiExit 0
Note: See TracBrowser for help on using the repository browser.