source: MondoRescue/trunk/mindi/mindi@ 794

Last change on this file since 794 was 794, checked in by Bruno Cornec, 18 years ago

merge -r781:793 $SVN_M/branches/stable

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