source: MondoRescue/branches/3.3/mindi/mindi

Last change on this file was 3889, checked in by Bruno Cornec, 6 weeks ago

Remove EFI references for ia64

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