source: MondoRescue/branches/3.2/mindi/mindi@ 3499

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