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

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

mindi simplification, by not managing multiple data disks anymore

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