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

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

Finally do not use vdf for ESX. Only creates issues.

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