source: MondoRescue/branches/2.2.7/mindi/mindi@ 1984

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

Adds amd74xx support

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