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

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 16 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

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