source: MondoRescue/branches/2.2.6/mindi/mindi@ 1913

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

Extract of mandatory files is now under ./tmp/.. instead of tmp/.. as we now use ar to create the all.tar.gz

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