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

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