source: MondoRescue/branches/2.2.9/mindi/mindi@ 2442

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