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

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