source: MondoRescue/branches/2.2.5/mindi/mindi@ 1882

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

Improvement in some messages

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