source: MondoRescue/branches/2.2.8/mindi/mindi@ 2781

Last change on this file since 2781 was 2781, checked in by Bruno Cornec, 13 years ago

r2151@localhost (orig r2150): bruno | 2009-02-16 18:32:32 +0100

  • Fix a nasty bug where if /tmp was full, mktemp is returning empty, and thus we were doing all type of bad things :-( mktemp return is now checked before usage (as it should !) Thnaks should go to Jean-Marc Andre (jean-marc.andre_at_hp.com) who suffered from the bug (unusable machine after backup :-() and who was willing to find what happened and finally produced the log files which permitted that analysis.


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