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

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