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

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

ReadAllLink rewritten again to try to fix bug reports on ML. Needs more tests.

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