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

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

merge -r 1842:1889 2.2.5

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