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

Last change on this file since 1842 was 1842, checked in by Bruno Cornec, 16 years ago
  • Fix lack of /etc/raidtab at restore rime in the right place
  • Adds support for nls_utf8 and pata_serverworks Patches from Dirk Husung (husung_at_tu-harburg.de)
  • Add efibootmgr to deplist.txt in order to be able to modify EFI menu at restore time on ia64
  • Usage of the new testver param of pb 0.8.12 to deliver 2.2.5 packages in a test dir.
  • Update pbcl files for upcoming delivery of 2.2.5
  • Fix an issue on parted output (K instead of KB) in parted2fdisk at restore time
  • Adds support for alb/aft types of bonding on Intel cards (Mark Pinkerton <Mark.Pinkerton_at_emageon.com>)
  • Escape variables in a perl script like mindi-bkphw
  • Better Proliant support at restore time now.
  • Fix a label bug where the variable label should also be re-initialized at each loop
  • start-nfs should NOT do exit => kernel panix as init exits
  • some other fixes for init on denymods
  • Adds boot options denymods (for udev) and forcemods (if not udev)
  • kqemu is denied. Probably should also be done for kvm stuff
  • Fix again the bug on modules link at root of the initrd. Hopefully for good.
  • Wait more around the USB CD emulated by iLO as it takes up to 5 seconds to come up
  • Attempt to fix udev support for RHEL 5.1
  • Better support for automatic iLO Virtual Media with udev
  • Some VMWare support improvements (however, it seems that VMWare support won't be possible anytime soon)
  • during init at restore time, copy all static evices availble for udev, as some distro implementation are no

t yet supported correctly for udev. Not very elegant, but should solve our current issues

  • Fedora 8 now supported as a build target for pb
  • svn.log removed.
  • dependencies reviewd for rhel_3
  • Attempt to fix the lack of modules loaded at restore time - especially fs device drivers
  • removes bkphw dir before potential creation
  • render mount command more vebose at restore time
  • Should fix #217
  • Increase BOOT_SIZE and EXTRA_SIZE to support features such as HW recovery
  • Handles udev.files files which could be symlinks
  • Improve udev support for distro with compressed modules (mdv e.g.)
  • Fix modules.dep copy
  • /sbin/pam_console_apply is needed by mdv udev conf
  • Adds support for nohw boot option to avoid re-setuping the HW conf
  • Improved support for Proliant on cpqacuxe
  • RstHW should be called after driver initialization
  • For debian/ubuntu mindi dpends on mindi-busybox
  • Update mindi-busybox pbcl for correct debian changelog generation, and up2date infos
  • Should fix #215
  • Fix #214 (Thanks to xdelaruelle)
  • Fix again svn.log not used anymore with new pb version
  • Adaptation of build process to upcoming 0.8.12 version of pb
  • Remove MONOTONIC clock to continue to support 2.4 kernels (RHEL 3 e.g. or ESX)
  • Attempt to solve ia64 BMC access through the serial port
  • parted2fdisk binary no more generated
  • do not require perl modules (strict.pm) at restore time
  • try to avoid modprobe messages at restore time
  • on ia64 now use the perl script parted2fdisk at retore time also
  • Also modprobe modules for udev after decompressing the additional ones
  • replace gzip -v9 by gzip -c9. Fix a bug at least on ia64
  • For all modules supported, create symlinks under the mountpoint and extract dev files as some are not automat ically created at the moment
  • Support /vmfs/volumes for ESX
  • Finally do not use vdf for ESX. Only creates issues.
  • Avoids continuing hw support if no product name found
  • Improves ia64 support for bootable image build
  • Fix a potential problem with ramdisk_blocksize param
  • MAKEDEV should also be included in deplist.txt
  • More fixes for udev support for Debian
  • Do not mount /boot if it's already mounted - avoids ESX hang
  • Fix NICs renumbering on Debian at least
  • Udev startup improvement to support iLO + NFS so modprobing all modules seems required as of now
  • Update to version 1.7.3 of busybox for pb
  • Load USB earlier in order to support KBD such as with iLO
  • Do busybox ldd first in order to create a potential /lib64 link correctly and then use it later in the image
  • Use variable DF in mindi to be able to support the ESX vdf
  • Fix mindi for Debian x86_64 where /lib64 is a link
  • Fix issue at restore time for ext2fs params not reused (Fix from Klaus Ade Johnstad <klaus_at_skolelinux.no>)
  • Do not copy udev files if they do not exist In udev case do not insert modules at all (udev should do it alone) May avoid the issue with rhel4.5 kernel ? To be tested
  • Update dependencies for rpm base build as well
  • And also perl is a debian/ubuntu dep
  • Better debian/ubuntu dependecies requirements (mtools)
  • Fix modes on mindi-bkphw (Thanks Phil Walker phil.walker_at_hp.com)
  • Complete rev [1771] for upper case RESTORE cli with syslinux as well
  • Update mindi-busybox to 1.7.3
  • Use RESTORE consistently across mondo to restore without interaction (report from Takeshi Shoji t.shoji_at_tripodw.jp)

(merge -r1769:1841 $SVN_M/branches/2.2.5)

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