Ticket #418: mindi-2.0.7.3-1.rhel5.x86_64.modified_for_xen

File mindi-2.0.7.3-1.rhel5.x86_64.modified_for_xen, 112.1 KB (added by Michael Shapiro, 14 years ago)

mindi-2.0.7.3-1.rhel5.x86_64 modified for xen

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