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

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

If udev then adds modprobe/insmod to rootfs

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