source: MondoRescue/branches/3.3/mindi/mindi@ 3784

Last change on this file since 3784 was 3784, checked in by Bruno Cornec, 3 years ago

Improve comment

  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 132.7 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 3784 2021-02-02 01:30:23Z bruno $
4#
5#-----------------------------------------------------------------------------
6# mindi - mini-Linux distro based on the user's filesystem & distribution
7#
8# Mindi can create a multi-image boot/root kit. The first image is the boot
9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
16ARCH=`/bin/uname -m`
17KERVERRUN=`/bin/uname -r`
18# By default we use the running kernel as a reference
19KERVER=$KERVERRUN
20
21# In case of problem with udev you can try to add udevdebug
22MINDI_ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off udevtimeout=10"
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/lib/kbd
406 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware
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/sysconfig/keyboard" ] ; then
417 LogFile "INFO: Red Hat-style config detected."
418 keyfile=/etc/sysconfig/keyboard
419 elif [ -e "/etc/vconsole.conf" ] ; then
420 LogFile "INFO: New Fedora style config detected."
421 keyfile=/etc/vconsole.conf
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 [ "$ARCH" != "ia64" ] ; then
1650 if [ $KERNEL_IS_XEN = "yes" ]; then
1651 FindMboot32Binary
1652 cp $xenkernelpath $MINDI_TMP/target/xen.gz 2>> $LOGFILE
1653 if [ $? -ne 0 ] ; then
1654 LogAll "ERROR: Failed to copy $xenkernelpath to $MINDI_TMP/target/"
1655 retval=$(($retval+1))
1656 fi
1657 cp $MBOOTC32 $MINDI_TMP/target/$tbc/mboot.c32 2>> $LOGFILE
1658 if [ $? -ne 0 ] ; then
1659 LogAll "ERROR: Failed to copy $MBOOTC32 to $MINDI_TMP/target/$tbc"
1660 retval=$(($retval+1))
1661 fi
1662 fi
1663fi
1664
1665MakeMessageFile $MINDI_TMP/target/$tbc | cut -c1-80 > $MINDI_TMP/target/$tbc/message.txt
1666
1667if [ _"$MONDO_SHARE" != _"" ]; then
1668 cp -rf $MINDI_TMP/target/$tbc $MONDO_ROOT 2>> $LOGFILE
1669 if [ $? -ne 0 ] ; then
1670 LogAll "ERROR: Failed to copy $MINDI_TMP/target/$tbc to $MONDO_ROOT"
1671 LogAll " Please check the target directory."
1672 retval=$(($retval+1))
1673 fi
1674 if [ $KERNEL_IS_XEN = "yes" ]; then
1675 cp -f $MINDI_TMP/target/xen.gz $MONDO_ROOT 2>> $LOGFILE
1676 if [ $? -ne 0 ] ; then
1677 LogAll "ERROR: Failed to copy $MINDI_TMP/target/xen.gz to $MONDO_ROOT"
1678 LogAll " Please check the target directory."
1679 retval=$(($retval+1))
1680 fi
1681 fi
1682 cp -f $MONDO_SHARE/autorun $MINDI_TMP/target 2>> $LOGFILE
1683 cp -f $MINDI_TMP/target/vmlinuz $MONDO_ROOT 2>> $LOGFILE
1684 if [ $? -ne 0 ] ; then
1685 LogAll "ERROR: Failed to copy $MINDI_TMP/vmlinuz to $MONDO_ROOT"
1686 LogAll " Please check the target directory."
1687 retval=$(($retval+1))
1688 fi
1689 cp -f $MINDI_TMP/target/initrd.img $MONDO_ROOT 2>> $LOGFILE
1690 if [ $? -ne 0 ] ; then
1691 LogAll "ERROR: Failed to copy $MINDI_TMP/initrd.img to $MONDO_ROOT"
1692 LogAll " Please check the target directory."
1693 retval=$(($retval+1))
1694 fi
1695fi
1696
1697if [ -f "$MINDI_TMP/$MRCFG" ]; then
1698 cp -f $MINDI_TMP/$MRCFG $MINDI_TMP/target/tmp
1699fi
1700
1701LogFile "----------- target dir content -----------"
1702LogFile "------------------------------------------"
1703ls -lR $MINDI_TMP/target >> $LOGFILE
1704LogFile "------------------------------------------"
1705LogFile "----------- target dir sizes -------------"
1706du -sk $MINDI_TMP/target/* >> $LOGFILE
1707LogFile "------------------------------------------"
1708
1709if [ "$retval" -ne "0" ] ; then
1710 sync
1711 umount $MINDI_TMP/target
1712 LogAll "ERROR: Problems while creating boot media."
1713 LogAll " Please unload some of your modules and try again."
1714 Die " Try using another temporary directory instead of $MINDI_TMP"
1715fi
1716
1717mkdir -p $MINDI_TMP/mpt
1718
1719if [ "$target" = "USB" ]; then
1720 LogAll "INFO: Transforming $USBDEVICE in a Bootable device"
1721 LogAll "INFO: Checking $USBDEVICE"
1722 $FDISK -l $USBDEVICE 2>&1 >> $LOGFILE
1723 if [ $? -ne 0 ]; then
1724 LogAll "ERROR: Unable to access $USBDEVICE"
1725 LogAll " Make sure your USB device is plugged in"
1726 MindiExit -1
1727 fi
1728 # Some distro do auto mount at that point (Ubuntu)
1729 LogAll "INFO: Unmounting $USBPART just in case"
1730 sync
1731 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1732 if [ "$BOOT_TYPE" = "BIOS" ]; then
1733 # If your key has no MBR it may cause an issue
1734 # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
1735 if [ -r $MBRFILE ]; then
1736 LogAll "INFO: Installing an MBR ($MBRFILE) on $USBDEVICE"
1737 dd if=$MBRFILE of=$USBDEVICE >> $LOGFILE 2>> $LOGFILE
1738 else
1739 LogAll "WARNING: You may need to install an MBR (usually in $MBRFILE, but not found on your system)"
1740 LogAll " on $USBDEVICE with dd if=$MBRFILE of=$USBDEVICE"
1741 fi
1742 fi
1743 LogAll "INFO: Preparing $USBDEVICE"
1744 cat > $MINDI_TMP/fdisk.txt << EOF
1745d
1746d
1747d
1748d
1749n
1750p
17511
1752
1753
1754t
1755b
1756a
17571
1758w
1759EOF
1760 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE < $MINDI_TMP/fdisk.txt
1761 if [ $? -ne 0 ]; then
1762 LogAll "ERROR: Unable to create a vfat Filesystem on $USBDEVICE"
1763 LogAll " Make sure your USB device is plugged in"
1764 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1765 MindiExit -1
1766 fi
1767 LogFile "fdisk build file"
1768 LogFile "----------------"
1769 cat $MINDI_TMP/fdisk.txt >> $LOGFILE
1770 LogFile "----------------"
1771 rm -f $MINDI_TMP/fdisk.txt
1772 LogAll "INFO: The USB device $USBDEVICE now looks like this:"
1773 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1774 # Calling kpartx in case devices were not created
1775 if [ -x "/sbin/kpartx" ]; then
1776 /sbin/kpartx -a $USBDEVICE
1777 fi
1778 # Some distro do auto mount at that point (Ubuntu)
1779 LogAll "INFO: Unmounting $USBPART just in case again"
1780 sync
1781 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1782 # Some distro have a dmsetup conf at that point so removing it Cf: http://trac.mondorescue.org/ticket/651
1783 if [ "`which dmsetup`" != "" ]; then
1784 block_id="`echo $USBPART | sed 's/\/dev\///g'`"
1785 if [[ "`dmsetup ls | awk '{print $1}' | grep $block_id`" != "" ]]; then
1786 LogAll "INFO: Removing $block_id from device mapper."
1787 sleep 1
1788 dmsetup remove $block_id
1789 fi
1790 fi
1791 part=$USBPART
1792 mount_opt=""
1793else
1794 # ISO image
1795 part=$MINDI_TMP/mindi-bootroot.img
1796 size=`du -sk $MINDI_TMP/target 2> /dev/null | cut -f1`
1797 # Adds 10 MB to allow for additional space
1798 size=$(($size+10000))
1799 LogAll "INFO: Creating a $size KB empty file for boot device of the ISO image"
1800 dd if=/dev/zero of=$part bs=1k count=$size &> /dev/null || Die "Cannot dd blank $part"
1801 mount_opt="-o loop"
1802fi
1803
1804LogAll "INFO: Creating a vfat filesystem on $part"
1805
1806mkfs.vfat $part 2>&1 >> $LOGFILE
1807if [ $? -ne 0 ]; then
1808 LogAll "ERROR: Unable to create a vfat filesystem on $part"
1809 if [ "$target" = "USB" ]; then
1810 LogAll " Make sure your USB device is plugged in and partitioned ($part must exist on it)"
1811 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1812 fi
1813 MindiExit -1
1814fi
1815if [ "$target" = "ISO" ]; then
1816 if [ "$BOOT_TYPE" = "BIOS" ]; then
1817 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1818 # and run after the formating for versions > 6 it seems
1819 syslinux $part >> $LOGFILE 2>> $LOGFILE
1820 fi
1821fi
1822LogAll "INFO: Mounting $part on $MINDI_TMP/mpt"
1823mount -t vfat $mount_opt $part $MINDI_TMP/mpt 2>> $LOGFILE
1824if [ $? -ne 0 ]; then
1825 LogAll "ERROR: Unable to mount $part on $MINDI_TMP/mpt"
1826 if [ "$target" = "USB" ]; then
1827 LogAll " Make sure your USB device is plugged in, partitioned and formated ($part must exist on it)"
1828 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1829 fi
1830 MindiExit -1
1831fi
1832
1833LogAll "INFO: Moving boot info on $MINDI_TMP/mpt"
1834mv $MINDI_TMP/target/* $MINDI_TMP/mpt
1835if [ $? -ne 0 ] ; then
1836 LogFile "--------------------------------"
1837 LogFile "INFO: Size of $MINDI_TMP/mpt:"
1838 du -sk $MINDI_TMP/mpt/* >> $LOGFILE
1839 LogFile "--------------------------------"
1840 sync
1841 umount $MINDI_TMP/mpt
1842 LogAll "ERROR: Problems while creating boot media."
1843 LogAll " Please unload some of your modules and try again."
1844 Die " Try using another temporary directory instead of $MINDI_TMP"
1845fi
1846
1847if [ "$target" = "ISO" ]; then
1848 if [ "$ARCH" != "ia64" ]; then
1849 ISO_OPT="$ISO_OPT -b $tbc/isolinux.bin -c $tbc/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
1850 fi
1851 # ISO
1852 if [ "$ARCH" != "ia64" ] && [ "$BOOT_TYPE" = "BIOS" ]; then
1853 CMD="$ISO_CMD $ISO_OPT"
1854 MakeISO
1855 else
1856 if [ "$ARCH" = "ia64" ]; then
1857 CMD="$ISO_CMD $ISO_OPT -b images/mindi-bootroot.img -c images/boot.cat"
1858 else
1859 # UEFI
1860 echo "$CMD" | grep -q "xorriso"
1861 if [ $? -eq 0 ]; then
1862 XOV=`xorriso --version 2>&1 | head -1 | awk '{print $3}'`
1863 XOVMAJ=`echo $XOV | cut -d. -f1`
1864 XOVMIN=`echo $XOV | cut -d. -f2`
1865 if [ $XOVMAJ -ge 1 && $XOVMIN -ge 3 ]; then
1866 CMD="$ISO_CMD $ISO_OPT -eltorito-alt-boot -e images/mindi-bootroot.img -no-emul-boot"
1867 else
1868 CMD="$ISO_CMD $ISO_OPT -eltorito-alt-boot --efi-boot images/mindi-bootroot.img"
1869 fi
1870 else
1871 CMD="$ISO_CMD $ISO_OPT -eltorito-alt-boot -efi-boot images/mindi-bootroot.img -no-emul-boot"
1872 fi
1873 fi
1874 fi
1875fi
1876
1877# Avoids graphical tool to keep the FS mounted
1878sync
1879umount $MINDI_TMP/mpt || Die "Unable to unmount $MINDI_TMP/mpt"
1880
1881if [ "$target" = "ISO" ]; then
1882 cp $part $MINDI_CACHE
1883 if [ "$ARCH" = "ia64" ] || [ "$BOOT_TYPE" = "UEFI" ]; then
1884 # Mount again !
1885 LogAll "INFO: Re-Mounting $part on $MINDI_TMP/mpt"
1886 mount -t vfat $mount_opt $part $MINDI_TMP/mpt 2>> $LOGFILE
1887 # We just need the EFI dir and the boot image for this case
1888 mkdir -p $MINDI_TMP/mpt2 $MINDI_TMP/mpt/images $MINDI_TMP/mpt/archives
1889 mount -o loop $MINDI_CACHE/mindi-bootroot.img $MINDI_TMP/mpt2 2>> $LOGFILE
1890 # We need again the kernel+initrd at the root for UEFI boot at least
1891 cp -a $MINDI_TMP/mpt2/EFI $MINDI_TMP/mpt2/vmlinuz $MINDI_TMP/mpt2/initrd.img $MINDI_TMP/mpt
1892 # We need the boot image now and what mindi needs at restore time as well
1893 cp -a $MINDI_TMP/mpt2/images/all.tar.gz $MINDI_CACHE/mindi-bootroot.img $MINDI_TMP/mpt/images
1894 # Avoids graphical tool to keep the FS mounted
1895 sync
1896 umount $MINDI_TMP/mpt2
1897 LogFile "----------- target dir content -----------"
1898 LogFile "------------------------------------------"
1899 ls -lR $MINDI_TMP/mpt >> $LOGFILE
1900 LogFile "------------------------------------------"
1901 MakeISO
1902 fi
1903else
1904 # USB
1905 if [ "$ARCH" != "ia64" ] ; then
1906 syslinux -v 2>&1 | grep -q 4.02
1907 if [ $? -eq 0 ]; then
1908 # This buggy version of syslinux requires a call to --stupid and not -s
1909 syslinux --stupid $USBPART 2>> $MINDI_TMP/syslinux.log
1910 res=$?
1911 else
1912 syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
1913 res=$?
1914 fi
1915 if [ $res -ne 0 ] ; then
1916 LogAll "----------- syslinux's errors --------------"
1917 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1918 LogAll "------------------------------------------"
1919 LogAll "ERROR: Failed to create USB image."
1920 else
1921 LogFile "INFO: Created bootable USB image on $USBDEVICE"
1922 fi
1923 rm -f $MINDI_TMP/syslinux.log
1924 else
1925 LogAll "ERROR: No USB boot support for ia64"
1926 MindiExit -1
1927 fi
1928fi
1929}
1930
1931
1932OfferToMakeBootableUSB() {
1933
1934local i files
1935
1936if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1937 echo -en "\nShall I make a bootable USB device ? (y/[n]) "
1938 read i
1939 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1940 if [ "$USBDEVICE" = "" ]; then
1941 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1942 read dev
1943 USBDEVICE=$dev
1944 fi
1945 echo "WARNING: This will erase all content on $USBDEVICE"
1946 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1947 read i
1948 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1949else
1950 if [ "$PROMPT_MAKE_USB_IMAGE" = "no" ] && [ _"$MONDO_SHARE" = _"" ] && [ "$USBDEVICE" = "" ]; then
1951 Die "No USBDEVICE environment variable declared, aborting"
1952 fi
1953fi
1954USBPART="${USBDEVICE}1"
1955
1956MakeBootableDevice USB
1957}
1958
1959
1960OfferToMakeBootableISO() {
1961
1962local i files
1963
1964if [ -z "$ISO_CMD" ]; then
1965 LogAll "ERROR: Neither mkisofs nor genisoimage nor xorriso found, unable to make CD image"
1966 return
1967fi
1968
1969if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1970 echo -en "\nShall I make a bootable CD image? (y/[n]) "
1971 read i
1972 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1973fi
1974
1975MakeBootableDevice ISO
1976}
1977
1978
1979MakeMessageFile() {
1980
1981 if [ -x "/bin/lsb_release" ]; then
1982 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1983 elif [ -r /etc/arch-release ]; then # this code must be written before /etc/issue test to avoid errors
1984 DESC="Arch Linux"
1985 if [ -r /var/log/pacman.log ]; then
1986 # there are no releases but we can get the last system upgrade
1987 # Output example: Arch Linux [2011-03-03 01:39]
1988 DESC="$DESC $(tac /var/log/pacman.log | grep -m1 'full system upgrade' | cut -d']' -f1)]"
1989 fi
1990 elif [ -x "/etc/os-release" ]; then
1991 DESC=`grep PRETTY_NAME /etc/os-release | cut -d= -f2`
1992 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1993 # For pb >= 0.9.8
1994 DESC=`/usr/bin/pbdistrocheck -s | cut -d, -f1-4 | sed 's/,/-/g'`
1995 elif [ -r /etc/issue.net ]; then
1996 DESC=`head -1 /etc/issue.net`
1997 elif [ -r /etc/issue ]; then
1998 DESC=`head -1 /etc/issue`
1999 else
2000 DESC="Unknown desc"
2001 fi
2002 # Avoids issues in the following sed
2003 DESC=`echo ${DESC} | tr '/' ' '`
2004 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/"
2005 if [ _"$MONDO_SHARE" != _"" ]; then
2006 if [ "$CDRECOVERY" != "yes" ] ; then
2007 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
2008 echo -en "Press <0eenter07> for 0cnetwork restore07\n"
2009 echo -en "$BOOT_MEDIA_MESSAGE"
2010 elif [ ! "$MINDI_TMP" ] ; then
2011 echo -en "FYI, this is _not_ a MondoRescue CD.\n"
2012 if [ -e "$MINDI_LIB/memtest.img" ] ; then
2013 echo -en "Type 'memtest' <Enter> to test your machine's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
2014 fi
2015 else
2016 echo -en "$BOOT_MEDIA_MESSAGE"
2017 fi
2018 else
2019 echo -en "\
2020To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
2021CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
2022 fi
2023 fi
2024
2025 # Also create the other help screens
2026 head -24 $MINDI_CONF/README.bootparam | cut -c1-80 > $1/boot1.txt
2027 head -48 $MINDI_CONF/README.bootparam | tail -24 | cut -c1-80 > $1/boot2.txt
2028 head -24 $MINDI_CONF/README.pxe | cut -c1-80 > $1/pxe.txt
2029}
2030
2031
2032MakeBootConfFile() {
2033 local options i ooo
2034 options=""
2035 # Type of boot file (elilo or syslinux/isolinux)
2036 type=$1
2037 if [ "$type" = "elilo" ] || [ "$type" = "grub2" ]; then
2038 sep="="
2039 sepdef="="
2040 else
2041 sep=" "
2042 sepdef=" "
2043 fi
2044
2045 # Generic header for conf file
2046 if [ "$type" = "elilo" ]; then
2047 echo -en "prompt\n"
2048 elif [ "$type" = "grub" ]; then
2049 echo -en "pause Press a key when ready to restore\n"
2050 elif [ "$type" = "grub2" ]; then
2051 echo -en "set "
2052 else
2053 # syslinux family
2054 echo -en "prompt 1\ndisplay message.txt\nF1 message.txt\nF2 boot1.txt\nF3 boot2.txt\nF4 pxe.txt\n"
2055 fi
2056
2057 # Compute which default option to boot from
2058 echo -en "default${sepdef}"
2059 if [ "$CDRECOVERY" = "yes" ] ; then
2060 if [ "$type" = "grub" ]; then
2061 # TODO: Which num ???
2062 echo -en "0\n"
2063 else
2064 echo -en "RESTORE\n"
2065 fi
2066 # In case it's mondoarchive
2067 elif [ _"$MONDO_SHARE" != _"" ]; then
2068 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
2069 if [ "$type" = "grub" ]; then
2070 echo -en "3\n"
2071 else
2072 echo -en "iso\n"
2073 fi
2074 else
2075 if [ "$type" = "grub" ]; then
2076 echo -en "1\n"
2077 else
2078 echo -en "${MINDI_DEFAULT_BOOT_OPTION}\n"
2079 fi
2080 fi
2081 else
2082 if [ "$type" = "grub" ]; then
2083 echo -en "0\n"
2084 else
2085 echo -en "expert\n"
2086 fi
2087 fi
2088
2089 # Handle timeout
2090 if [ "$type" = "grub2" ]; then
2091 seppref="set "
2092 else
2093 seppref=""
2094 fi
2095 if [ "$CDRECOVERY" = "yes" ] ; then
2096 echo -en "${seppref}timeout${sep}10000\n"
2097 else
2098 echo -en "${seppref}timeout${sep}${MINDI_BOOT_TIMEOUT}\n"
2099 fi
2100 echo -en "\n"
2101
2102 # prepare which labels will be generated
2103 if [ "$CDRECOVERY" = "yes" ] ; then
2104 options="RESTORE expert"
2105 else
2106 if [ _"$MONDO_SHARE" != _"" ]; then
2107 options="interactive expert compare iso nuke isonuke"
2108 else
2109 options="expert"
2110 fi
2111 fi
2112
2113 # Generate rest of conf file
2114 for i in $options ; do
2115 ooo=$i
2116 [ "$ooo" = "RESTORE" ] && ooo="RESTORE nuke"
2117 if [ "$type" = "elilo" ]; then
2118 outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/initrd.img\n\troot=/dev/ram0 append=\" rw ramdisk_size=RAMDISK_SIZE $ooo $MINDI_ADDITIONAL_BOOT_PARAMS \"\n"
2119 elif [ "$type" = "grub" ]; then
2120 outstr="title $i\n\tkernel /vmlinuz root=/dev/ram0 rw ramdisk_size=RAMDISK_SIZE ${ooo} $MINDI_ADDITIONAL_BOOT_PARAMS\n\tinitrd=/initrd.img\n"
2121 elif [ "$type" = "grub2" ]; then
2122 if [ "$BOOT_TYPE" = "UEFI" ]; then
2123 lorder="linuxefi"
2124 iorder="initrdefi"
2125 else
2126 lorder="linux"
2127 iorder="initrd"
2128 fi
2129 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"
2130 else
2131 ps="/"
2132 if [ $KERNEL_IS_XEN = "no" ]; then
2133 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"
2134 else
2135 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"
2136 fi
2137 fi
2138 echo -en "$outstr"
2139 done
2140 if [ -e "$MINDI_LIB/memtest.img" ] ; then
2141 if [ "$type" = "elilo" ]; then
2142 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
2143 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
2144 elif [ "$type" = "grub" ]; then
2145 echo -en "title memtest\n\tkernel /memtest.efi\n\tinitrd=/memtest.img\n"
2146 elif [ "$type" = "grub2" ]; then
2147 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"
2148 else
2149 ps="/"
2150 if [ "$type" = "syslinux" ]; then
2151 ps=""
2152 fi
2153 echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
2154 echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
2155 fi
2156 fi
2157}
2158
2159ParseModprobeForIncludes() {
2160local MODPROBE_CONF mpincfile includes include
2161
2162MODPROBE_CONF=/etc/modprobe.conf
2163mpincfile=$1
2164touch $mpincfile
2165if [ -a $MODPROBE_CONF ]; then
2166 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
2167 if [ -n "$includes" ]; then
2168 for include in $includes
2169 do
2170 if [ -a "$include" ]; then
2171 echo $include >> $mpincfile
2172 fi
2173 done
2174 fi
2175fi
2176}
2177
2178PrepareBootDir() {
2179
2180 local detect
2181 # Needs a bigdir variable setup before calling it
2182
2183 # copy (e)lilo/isolinux/grub/whatever stuff into it as well
2184 # to get it on the media (in addition to the boot part
2185 # and also to support UEFI boot mechanism
2186 if [ "$boottype" != "" ]; then
2187 detect="no"
2188 else
2189 detect="yes"
2190 boottype=syslinux
2191 fi
2192 bootdir=$bigdir/$boottype
2193 bootconf="$bootdir/$boottype.cfg"
2194 mkdir -p $bootdir
2195 FindLdlinux32Binary
2196
2197 dname=`pbdistrocheck | grep -E '^Name:' | cut -d':' -f2`
2198 dver=`pbdistrocheck | grep -E '^Ver:' | cut -d':' -f2 | cut -d'.' -f1`
2199
2200 if [ "$BOOT_TYPE" != "BIOS" ]; then
2201 if [ "$BOOT_TYPE" = "UNKNOWN" ]; then
2202 LogAll "ERROR: UNKNOWN BOOT_TYPE. Please report upstream"
2203 MindiExit -1
2204 fi
2205
2206 mountefi=0
2207 # EFI or UEFI
2208 # TODO: names are hard-coded for now
2209 if [ "$BOOT_TYPE" = "UEFI" ]; then
2210 # UEFI
2211 efidir=$bigdir/EFI/BOOT
2212 # Auto-detection if needed
2213 if [ $detect = "yes" ]; then
2214
2215 # mount /boot/efi if needed
2216 df -T | grep /boot/efi | grep -qE 'vfat'
2217 if [ $? -ne 0 ]; then
2218 mount /boot/efi
2219 if [ $? -ne 0 ]; then
2220 echo "ERROR: You have to mount your (U)EFI partition when using mindi"
2221 MindiExit -1
2222 fi
2223 mountefi=1
2224 fi
2225
2226 # On RHEL6 grub works
2227 if [ $dname = "rhel" -o $dname = "centos" -o $dname = "oel" ] && [ $dver = "6" ]; then
2228 boottype=grub
2229 elif [ $dname = "rhel" -o $dname = "centos" -o $dname = "oel" ] && [ $dver -ge 7 ]; then
2230 boottype=grub2
2231 elif [ $dname = "fedora" ] && [ $dver -ge 20 ]; then
2232 boottype=grub2
2233 elif [ $dname = "sles" ] && [ $dver -ge 12 ]; then
2234 boottype=grub2
2235 elif [ $dname = "debian" ] && [ $dver -ge 8 ]; then
2236 boottype=grub2
2237 elif [ $dname = "ubuntu" ] && [ $dver -ge 16 ]; then
2238 boottype=grub2
2239 else
2240 # Use syslinux.efi as the default boot loader ... but it doesn't work for now :-(
2241 boottype=syslinux
2242 fi
2243 fi
2244 if [ "$boottype" = "syslinux" ]; then
2245 if [ ! "$bootbin" ]; then
2246 FindSyslinux64EFI
2247 bootbin=$SYSLINUX64EFI
2248 fi
2249 bootconf="$efidir/syslinux.cfg"
2250 elif [ "$boottype" = "grub" ]; then
2251 if [ ! "$bootbin" ]; then
2252 bootbin=`find /boot/efi -iname "grub*.efi" | head -1`
2253 fi
2254 bootconf="$efidir/BOOTX64.conf"
2255 elif [ "$boottype" = "grub2" ]; then
2256 if [ ! "$bootbin" ]; then
2257 bootbin=`find /boot/efi -iname "grub*.efi" | head -1`
2258 fi
2259 bootconf="$efidir/grub.cfg"
2260 fi
2261
2262 # Depending on the arch, the target boot file is different
2263 if [ "$ARCH" = "x86_64" ] ; then
2264 tgbin="BOOTX64.efi"
2265 elif [ "$ARCH" = "armv8" ]; then
2266 tgbin="BOOTAA64.efi"
2267 else
2268 # i?386
2269 tgbin="BOOTIA32"
2270 fi
2271 else
2272 # EFI
2273 efidir=$bootdir
2274 bootbin=`find /boot/efi -iname "elilo.efi" | head -1`
2275 tgbin=$bootbin
2276 boottype=elilo
2277 bootconf="$efidir/elilo.conf"
2278 fi
2279 LogAll "INFO: Found $boottype boot type"
2280 mkdir -p $efidir
2281 cp $bootbin $efidir/$tgbin
2282
2283 if [ $mountefi -eq 1 ]; then
2284 umount /boot/efi 2>&1 > /dev/null
2285 fi
2286
2287 if [ $boottype = "syslinux" ]; then
2288 FindLdlinuxe64Binary
2289 if [ -e "$LDLINUXE64" ]; then
2290 LogFile "INFO: Copying $LDLINUXE64 to $efidir"
2291 cp $LDLINUXE64 $efidir 2>> $LOGFILE || Die "Cannot copy $LDLINUXE64 to $efidir). Did you run out of disk space?"
2292 cp $(dirname $LDLINUXE64)/libutil.c32 $efidir 2>> $LOGFILE || Die "Cannot copy libutil.c32 to $efidir). Did you run out of disk space?"
2293 if [ -e $(dirname $LDLINUXE64)/isolinux.c32 ]; then
2294 cp $(dirname $LDLINUXE64)/isolinux.c32 $efidir 2>> $LOGFILE || Die "Cannot copy isolinux.c32 to $efidir). Did you run out of disk space?"
2295 fi
2296 fi
2297 fi
2298 # tgdir for syslinux
2299 tgdir=$bigdir/EFI
2300 else
2301 # tgdir for syslinux
2302 tgdir=$bootdir
2303 fi
2304 # In all cases prepare syslinux content for BIOS mode
2305 # so that we can have multi boot mode media BIOS+UEFI
2306 # Useful for syslinux 5.x
2307 if [ -e "$LDLINUXC32" ]; then
2308 LogFile "INFO: Copying $LDLINUXC32 to $tgdir"
2309 cp $LDLINUXC32 "$tgdir" 2>> $LOGFILE || Die "Cannot copy $LDLINUXC32 to $tgdir. Did you run out of disk space?"
2310 fi
2311 if [ -e $(dirname $LDLINUXC32)/isolinux.c32 ]; then
2312 LogFile "INFO: Copying isolinux.c32 to $tgdir"
2313 cp $(dirname $LDLINUXC32)/isolinux.c32 $tgdir 2>> $LOGFILE || Die "Cannot copy isolinux.c32 to $tgdir). Did you run out of disk space?"
2314 fi
2315
2316 MakeBootConfFile $boottype > $bootconf
2317 LogFile "Boot Conf file $bootconf content is:"
2318 LogFile "------------------------------------"
2319 cat $bootconf >> $LOGFILE
2320 LogFile "------------------------------------"
2321 if [ "$BOOT_TYPE" = "UEFI" ]; then
2322 # Also generate the syslinux conf
2323 MakeBootConfFile syslinux > "$bigdir/EFI/syslinux.cfg"
2324 LogFile "Boot Conf file $bigdir/EFI/syslinux.cfg content is:"
2325 LogFile "---------------------------------------------------"
2326 cat $bigdir/EFI/syslinux.cfg >> $LOGFILE
2327 LogFile "---------------------------------------------------"
2328 if [ $dname = "debian" ] && [ $dver -ge 8 ]; then
2329 # In that case it seems we need conf file at the root of the media
2330 cp -a $bigdir/EFI/* $bigdir
2331 fi
2332 fi
2333
2334}
2335
2336PrepareBigDirTar() {
2337 echo -en "INFO: Tarring and zipping the data content..."
2338 (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)
2339 LogFile "Size of the data content"
2340 LogFile "------------------------"
2341 du -sk $MINDI_CACHE/*gz >> $LOGFILE
2342 LogFile "------------------------"
2343 echo -e "$DONE"
2344
2345}
2346
2347CleanBigDir() {
2348 [ "$bigdir" != "/" ] && echo $bigdir | grep -vq $MINDI_TMP && rm -rf $bigdir
2349}
2350
2351PrepareBigDir() {
2352 local needlist diskdir res i j k lines lfiles includefile ti
2353
2354 rm -f $MINDI_CACHE/mindi.iso
2355 needlist=$MINDI_TMP/what-we-need.txt
2356 mkdir -p $bigdir/usr/bin
2357 mkdir -p $bigdir/usr/sbin
2358 includefile=$MINDI_TMP/$$.includefile.txt
2359
2360 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
2361 if [ -e "$DEPLIST_FILE" ]; then
2362 lfiles="$DEPLIST_FILE $lfiles"
2363 fi
2364 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
2365 ParseModprobeForIncludes $includefile
2366 lines=$(($lines+`cat $includefile | wc -l`))
2367 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
2368 res=$?
2369 rm -f $includefile
2370 ListKernelModulePaths >> $needlist
2371 if [ "$res" -ne "0" ] ; then
2372 Die "You have $res files present in dependency list\nbut absent from filesystem."
2373 fi
2374 mkdir -p $bigdir/tmp
2375 if [ _"$MONDO_SHARE" != _"" ]; then
2376 # TODO: no reason to have the cfg file stored twice
2377 MakeMondoConfigFile $MINDI_TMP/$MRCFG
2378 cp -f $MINDI_TMP/$MRCFG $bigdir/tmp &> /dev/null
2379 fi
2380
2381 # Needs to be done after the MRCFG creation
2382 FindAndAddUserKeyboardMappingFile
2383
2384 [ -d "/mnt/.boot.d" ] && echo "GENTOO" > $bigdir/tmp/DUMBASS-GENTOO
2385 DropOptimizedLibraries $needlist $bigdir
2386 echo -en "INFO: Assembling dependency files"
2387
2388 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist` 1
2389 rm -f $needlist
2390 echo -e "$DONE"
2391
2392 # also copy io.sys and msdos.sys, if we can find them
2393 for i in `mount | cut -d' ' -f3` ; do
2394 for j in io.sys msdos.sys ; do
2395 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
2396 done
2397 done
2398
2399 # master boot record, too
2400 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
2401 if [ "$i" ] && [ "$BOOT_TYPE" = "BIOS" ]; then
2402 LogAll "INFO: Backing up $i's MBR"
2403 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
2404 sleep 1
2405 sync
2406 j=$i
2407 [ -h "$j" ] && j=`readlink -f $j`
2408 LogAll "INFO: Creating /dev/boot_device ($j)"
2409 mkdir -p $bigdir/dev
2410 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
2411 fi
2412
2413 # Get terminfo content
2414 for ti in usr/share/terminfo/l usr/share/terminfo/x lib/terminfo/l lib/terminfo/x ; do
2415 if [ -d /$ti ]; then
2416 mkdir -p $bigdir/$ti
2417 cp -Rdf /$ti/* $bigdir/$ti 2>> $LOGFILE || LogAll "ERROR: issue copying terminfo"
2418 fi
2419 done
2420 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
2421 cp -Rdf $MONDO_SHARE/restore-scripts/mondo/* $bigdir/usr/bin 2>> $LOGFILE
2422 [ $? -ne 0 ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
2423 cp -Rdf $MONDO_SHARE/restore-scripts/etc/* $bigdir/etc 2>> $LOGFILE
2424 fi
2425 if [ -d "/lib/dev-state" ]; then
2426 cp -a /lib/dev-state $bigdir/lib/ 2>> $MINDI_TMP/$$.log || LogAll "ERROR: Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
2427 fi
2428 MakeMountlist $MINDI_TMP/mountlist.txt
2429 CheckMountlist $MINDI_TMP/mountlist.txt
2430 mkdir -p $bigdir/tmp
2431 cp -f $MINDI_TMP/mountlist.txt $bigdir/tmp/mountlist.txt 2>> $LOGFILE || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk"
2432 for i in create-btrfs-subvol mount-btrfs-subvol umount-btrfs-subvol; do
2433 if [ -r $MINDI_TMP/$i ]; then
2434 cp -f $MINDI_TMP/$i $bigdir/tmp/ 2>> $LOGFILE || Die "Cannot copy subvol script $MINDI_TMP/$i to data disk"
2435 fi
2436 done
2437 if [ _"$MONDO_SHARE" != _"" ]; then
2438 cp -f $bigdir/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2439 fi
2440 if [ $LVM != "false" ]; then
2441 $MINDI_LIB/analyze-my-lvm > $bigdir/tmp/i-want-my-lvm
2442 if [ $? -ne 0 ]; then
2443 LVM="false"
2444 rm -f $bigdir/tmp/i-want-my-lvm
2445 else
2446 LogFile "Your i-want-my-lvm file content is:"
2447 LogFile "-----------------------------------"
2448 cat $bigdir/tmp/i-want-my-lvm >> $LOGFILE
2449 LogFile "-----------------------------------"
2450 fi
2451 fi
2452 LogFile "INFO: Your mountlist.txt file content is:"
2453 LogFile "-----------------------------------"
2454 cat $bigdir/tmp/mountlist.txt >> $LOGFILE
2455 LogFile "-----------------------------------"
2456
2457 echo -en "$FILES_IN_FILELIST" > $bigdir/FILES-IN-FILELIST 2>> $LOGFILE
2458 echo -en "$LAST_FILELIST_NUMBER" > $bigdir/LAST-FILELIST-NUMBER 2>> $LOGFILE
2459 if [ _"$MONDO_SHARE" != _"" ]; then
2460 for q in filelist.full.gz biggielist.txt ; do
2461 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
2462 cp -pRdf $MINDI_TMP/$q $bigdir/tmp 2>> $LOGFILE
2463 done
2464 for q in $MBRFILE $GPTMBRFILE; do
2465 if [ -r $q ]; then
2466 cp -a $q $bigdir/tmp 2>> $LOGFILE
2467 else
2468 LogFile "Unable to copy $q to bigdir. May be unable to restore MBR"
2469 fi
2470 done
2471 fi
2472
2473 PrepareBootDir
2474
2475}
2476
2477
2478Prompt() {
2479 echo -en "$1"
2480 read line
2481}
2482
2483
2484ReadLine() {
2485 local i incoming
2486 read incoming
2487 i=0
2488 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
2489 i=$(($i+1))
2490 read incoming
2491 done
2492 echo "$incoming"
2493}
2494
2495
2496SizeOfPartition() {
2497 local devpath drive res stub
2498 device=$1
2499 if [ "`echo "$device" | grep -E "^/dev/"`" = "" ] ; then
2500 Die "Cannot find $device's size - is your /etc/fstab sane?"
2501 fi
2502 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2503 res=`SizeOfRaidPartition $device`
2504 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2505 echo "$res"
2506 return 0
2507 fi
2508 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2509 res=`$FDISK -s $device 2>> $LOGFILE`
2510 # end patch
2511 # take only the first in case of multiple mount (cifs, nfs, ...)
2512 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
2513 [ "$res" = "" ] && res="-1"
2514 echo $res
2515 return 0
2516}
2517
2518
2519SizeOfRaidPartition() {
2520 local real_dev smallest_size silly tmp
2521
2522 silly=999999999
2523 smallest_size=$silly
2524
2525 for real_dev in `GetRaidDevMembers $1` ; do
2526 tmp=`SizeOfPartition $real_dev`
2527 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2528 done
2529
2530 if [ "$smallest_size" = "$silly" ] ; then
2531 echo "-1"
2532 return 1
2533 else
2534 echo "$smallest_size"
2535 return 0
2536 fi
2537}
2538
2539
2540StripExecutable()
2541{
2542 local tmpfile
2543
2544 tmpfile=$MINDI_TMP/stripped.$$.dat
2545 [ -d "$1" ] || [ -h "$1" ] && return
2546 cp -f $1 $tmpfile 2>> $LOGFILE
2547 strip $tmpfile 2> /dev/null
2548 if [ $? -eq 0 ] ; then
2549 cp -f $tmpfile $1 2>> $LOGFILE
2550 LogFile "INFO: Stripped binary $2"
2551 fi
2552 rm -f $tmpfile
2553}
2554
2555KernelVer() {
2556 local fkern_ver fname
2557
2558 fname=$1
2559 file $fname | grep -q gzip
2560 if [ $? -eq 0 ] ; then
2561 # Used by ia64
2562 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep -E "[2-9]+\.[0-9]+\.[0-9]+[^\@]*@"`
2563 else
2564 fkern_ver=`strings $fname 2> /dev/null | grep -E "[2-9]+\.[0-9]+\.[0-9]+[^\@]*@"`
2565 fi
2566 echo "$fkern_ver"
2567}
2568
2569
2570# WARNING: This function should just echo the final result !!!
2571#
2572TryToFindKernelPath() {
2573 local fname fkern_ver we_want_version possible_kernels noof_kernels possible_xenkernels noof_xenkernels kp kdate duff_kernels output root
2574
2575 we_want_version=$KERVERRUN
2576 possible_kernels=""
2577 duff_kernels=""
2578 output=""
2579
2580 if [ "$ARCH" = "ia64" ] ; then
2581 root="/boot/efi/efi"
2582 else
2583 root="/"
2584 fi
2585 # See if we're booted from a Xen kernel
2586 # From http://wiki.xensource.com/xenwiki/XenCommonProblems#head-26434581604cc8357d9762aaaf040e8d87b37752
2587 if [ -f /proc/xen/capabilities ]; then
2588 # It's a Xen kernel
2589 KERNEL_IS_XEN="yes"
2590 LogFile "INFO: It's a Xen kernel..."
2591 fi
2592
2593 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
2594 [ ! -e "$fname" ] && continue
2595 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2596 fkern_ver=`KernelVer $fname`
2597 [ "$fkern_ver" = "" ] && continue
2598 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2599 [ -f "$fname" ] || continue
2600 [ -h "$fname" ] && continue
2601 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2602 file $fname | grep -q gzip
2603 if [ $? -eq 0 ] ; then
2604 # Used by ia64
2605 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2606 LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2607 duff_kernels="$fname $duff_kernels"
2608 else
2609 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2610 possible_kernels="$fname $possible_kernels"
2611 fi
2612 else
2613 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2614 LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2615 duff_kernels="$fname $duff_kernels"
2616 else
2617 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2618 possible_kernels="$fname $possible_kernels"
2619 fi
2620 fi
2621 done
2622 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2623 possible_kernels=`find /boot/vmlinuz-[2-9].* | tail -n1`
2624 fi
2625 if [ ! "$possible_kernels" ] ; then
2626 LogAll "INFO: No kernel matches exactly. Are there any duff kernels?"
2627 possible_kernels="$duff_kernels"
2628 if [ ! "$possible_kernels" ] ; then
2629 LogAll "INFO: Sorry, no duff kernels either"
2630 else
2631 LogAll "INFO: I bet you're running Debian or Gentoo, aren't you?"
2632 LogAll "INFO: Your kernel doesn't have a sane builddate. Oh well..."
2633 fi
2634 fi
2635 if [ $KERNEL_IS_XEN = "yes" ]; then
2636 possible_xenkernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -i "xen" | sort -u | tr '\n' ' '`
2637 noof_xenkernels=`CountItemsIn "$possible_xenkernels"`
2638 fi
2639 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -vi "xen" | sort -u | tr '\n' ' '`
2640 noof_kernels=`CountItemsIn "$possible_kernels"`
2641 if [ "$noof_kernels" -eq "0" ] ; then
2642 LogAll "Could not find your kernel."
2643 if [ -e "/boot/vmlinuz" ] ; then
2644 LogAll "INFO: Using /boot/vmlinuz as a last resort."
2645 output=/boot/vmlinuz
2646 else
2647 output=""
2648 fi
2649 elif [ "$noof_kernels" -eq "1" ] ; then
2650 kp=`echo "$possible_kernels" | sed s/' '//`
2651 LogFile "INFO: Your kernel is $kp (v$KERVERRUN)"
2652 output="$kp"
2653 else
2654 for i in $possible_kernels ; do
2655 if [ "`echo $i | grep "$KERVERRUN"`" ]; then
2656 LogAll "INFO: OK, I used my initiative and found that "
2657 LogAll "INFO: $i is probably your kernel. "
2658 output="$i"
2659 break
2660 fi
2661 done
2662 if [ ! -n "$output" ]; then
2663 if [ "`echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null`" ]; then
2664 output=/boot/vmlinuz
2665 LogFile "INFO: Schlomo, this one's for you."
2666 else
2667 LogFile "INFO: Two or more possible kernels found. You may specify any one of them and the "
2668 LogFile "INFO: boot disks will still work, probably. If one does not work, try another."
2669 LogFile "INFO: $possible_kernels"
2670 output=""
2671 fi
2672 fi
2673 fi
2674 if [ $KERNEL_IS_XEN = "yes" ]; then
2675 if [ "$noof_xenkernels" -eq "0" ]; then
2676 xenkernelpath=""
2677 elif [ "$noof_xenkernels" -eq "1" ]; then
2678 xenkernelpath=`echo "$possible_xenkernels" | sed s/' '//`
2679 LogFile "INFO: Your Xen kernel is $xenkernelpath (v$KERVERRUN)"
2680 else
2681 for i in $possible_xenkernels ; do
2682 if [ "`echo $i | grep "$KERVERRUN"`" ]; then
2683 LogFile "INFO: OK, I used my initiative and found that "
2684 LogFile "INFO: $i is probably your Xen kernel. "
2685 xenkernelpath="$i"
2686 break
2687 fi
2688 done
2689 if [ ! -n "$xenkernelpath" ]; then
2690 new_possible_xenkernels=`echo "$possible_xenkernels" | tr -s ' ' '\n' | grep -E "^/boot" | sort -u | tr '\n' ' '`
2691 if [ ! -n "$new_possible_xenkernels" ]; then
2692 xenkernelpath=`echo $new_possible_xenkernels | tr -s ' ' '\n' | head -1`
2693 LogFile "INFO: Using $xenkernelpath"
2694 else
2695 LogFile "INFO: Two or more possible Xen kernels found. You may specify any one of them and the "
2696 LogFile "INFO: boot disks will still work, probably. If one does not work, try another."
2697 LogFile "INFO: $possible_xenkernels"
2698 output=""
2699 xenkernelpath=`echo $possible_xenkernels | tr -s ' ' '\n' | head -1`
2700 LogFile "INFO: Using $xenkernelpath"
2701 fi
2702 fi
2703 fi
2704 if [[ -z "$xenkernelpath" || ! -f "$xenkernelpath" ]]; then
2705 Die "Cannot find Xen kernel $xenkernelpath, aborting"
2706 fi
2707 fi
2708 #LogAll "TryToFindKernelPath found $output"
2709 echo "$output"
2710}
2711
2712CopyFromConf() {
2713
2714 conf=$1
2715 mp=$2
2716 echo -en "INFO: Gathering dependencies of $conf.conf..."
2717 LogFile "INFO: Gathering dependencies of $conf.conf..."
2718 lis2=`grep -Ev '^#' $DEPLIST_DIR/$conf.conf | sort -u`
2719 noof_lines=`echo $lis2 | wc -w`
2720 progress=0
2721 # Get only the files which exist in that list
2722 # and potentially their symlink structure
2723 # put apart directories for later handling
2724 for f in $lis2; do
2725 if [ -d $f ]; then
2726 for g in `find $f`; do
2727 echo $g >> $MINDI_TMP/$conf.lis
2728 LocateDeps $g >> $MINDI_TMP/$conf.lis2
2729 done
2730 lis3="$lis3 $f"
2731 else
2732 if [ -r $f ]; then
2733 echo $f >> $MINDI_TMP/$conf.lis
2734 LocateDeps $f >> $MINDI_TMP/$conf.lis2
2735 fi
2736 fi
2737 progress=$(($progress+1))
2738 LogProgress $progress $noof_lines
2739 done
2740 echo -e "$DONE"
2741 LogAll "INFO: Processing all dependencies links for $conf.conf..."
2742 # And their deps except dirs
2743 lines=`sort -u $MINDI_TMP/$conf.lis $MINDI_TMP/$conf.lis2`
2744 rm -f $MINDI_TMP/$conf.lis2
2745 finallist=""
2746 # Remove directories from the list, as cp will create them anyway
2747 # and it may hurt if /lib is in it as on Debian/Ubuntu
2748 # recent bash says that -d is true for a link to a dir !
2749 for f in $lines; do
2750 if [ -e "$f" -a ! -d "$f" ] || [ -h "$f" ]; then
2751 # Do not overwrite files already in destination (avoid using option -n of cp not portable)
2752 if [ ! -e "$mp/$f" ]; then
2753 finallist="$finallist $f"
2754 fi
2755 fi
2756 done
2757 # But adds the directory useful in $lis3
2758 fnllist=`echo $finallist $lis3 | tr ' ' '\n' | sort -u | tr '\n' ' '`
2759 LogFile "INFO: Copying $conf related files with cp -a --parents $fnllist -t $mp/"
2760 cp -a --parents $fnllist -t $mp/ 2> $templog || LogAll "WARNING: Problem in $conf analysis" $templog
2761 rm -f $MINDI_TMP/$conf.lis
2762}
2763
2764PrepareTargetDir() {
2765 local tgz_dir_fname nodes kernelsize res currsize not_copied j k s w needed_modules_path d thelink templog
2766
2767 tgz_dir_fname=$MINDI_LIB/rootfs
2768 rdz_fname=$MINDI_TMP/initrd.img
2769 kernelsize=`du -sk $kernelpath | cut -f1`
2770 res=0
2771 templog=$MINDI_TMP/$$.log
2772 > $templog
2773
2774 mkdir -p $targetdir
2775 # Check whether /lib64 or /lib or /sbin or /bin is a link and if so explicitly create one in rootfs (Fedora 17 crazyness)
2776 for d in bin sbin lib lib64; do
2777 if [ -h "/$d" ]; then
2778 thelink=`readlink /$d`
2779 mkdir -p $targetdir/$thelink || LogAll "ERROR: Unable to create $thelink in $targetdir"
2780 mv $targetdir/$d/* $targetdir/$d/.??* $targetdir/$thelink 2> /dev/null
2781 if [ -d "$targetdir/$d" -a ! -h "$targetdir/$d" ]; then
2782 rmdir $targetdir/$d
2783 fi
2784 if [ ! -h $targetdir/$d ]; then
2785 rm -f $targetdir/$d 2> /dev/null
2786 (cd $targetdir ; ln -s $thelink $d) || LogAll "ERROR: /$d is a symbolic link, but I couldn't create it in $targetdir"
2787 fi
2788 fi
2789 done
2790
2791 LogFile "INFO: what is now in $targetdir"
2792 ls -al $targetdir >> $LOGFILE
2793
2794 # Check files before copying to discover configuration issues or McAfee preventing mindi reading these files
2795 # copy from rootfs into targetdir
2796 LogAll "INFO: Copying Mindi files to $targetdir"
2797 for f in $tgz_dir_fname/*; do
2798 if [ ! -r $f ]; then
2799 Die "ERROR: Unable to copy $f to the target dir. Check your installation or McAfee presence"
2800 else
2801 cp -af $f $targetdir 2>&1 >> $LOGFILE
2802 fi
2803 done
2804 (cd $targetdir/etc ; ln -sf bashrc profile ; ln -sf bashrc shrc ; ln -sf ../proc/mounts mtab ; ln -sf ../usr/sbin/init linuxrc)
2805 # kernel expects linuxrc in ext2 filesystem
2806 (cd $targetdir ; ln -sf usr/sbin/init linuxrc)
2807 # kernel expects init in cpio filesystem
2808 (cd $targetdir ; ln -sf usr/sbin/init init)
2809
2810 (cd $targetdir/dev ; tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz" ; rm -f dev-entries.tgz)
2811
2812 for w in insmod.static insmod.static.old ; do
2813 s=`which $w 2> /dev/null`
2814 if [ -e "$s" ] ; then
2815 tar cf - -C / $s 2> /dev/null | (cd $targetdir ; tar xf -)
2816 fi
2817 done
2818
2819 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2820
2821 # Copy of files mandatory for ssh to automate mount if sshfs is used
2822 mkdir -p $targetdir/.ssh $targetdir/tmp
2823 cp -a ~root/.ssh/* $targetdir/.ssh 2> /dev/null
2824 cat > $targetdir/tmp/myssh << EOF
2825ssh -o StrictHostKeyChecking=no \$*
2826EOF
2827 chmod 755 $targetdir/tmp/myssh
2828
2829 # Copy of files mandatory for ld.so
2830 cp -a /etc/ld.so.c* $targetdir/etc
2831
2832 # Handle the case where busybox and mount are dynamically linked
2833 file $MINDI_LIB/rootfs/usr/bin/busybox 2>&1 | grep -q "dynamically"
2834 if [ $? -eq 0 ]; then
2835 # We want to use the real mount and all the supported variants (nfs, cifs, ...)
2836 rm -f $targetdir/bin/mount
2837 fi
2838
2839 # Copy of files from the minimal env needed as per the deplist.d/minimal.conf (which includes all busybox deps)
2840 CopyFromConf minimal $targetdir
2841
2842 # For older distributions expecting /sbin/init provides it
2843 if [ ! -e "$targetdir/sbin/init" ]; then
2844 (cd $targetdir/sbin ; ln -sf ../usr/sbin/init .)
2845 fi
2846
2847 # To improve support for distribution scripts, we now prefer to use bash as the std shell. Also fixes #600
2848 (cd $targetdir ; ln -sf /bin/bash bin/sh)
2849 LogFile "INFO: Using bash as default shell"
2850
2851 # Avoids an issue on some distro (RHEL5)
2852 rm -f $targetdir/etc/ld.so.conf.d/kernelcap*
2853
2854 # Management of DRBD
2855 which drbdadm &> /dev/null
2856 if [ $? -eq 0 ]; then
2857 # Do we find DRBD devices setup
2858 drbdadm sh-dev all | grep -E '^/dev' &> /dev/null
2859 if [ $? -eq 0 ]; then
2860 CopyFromConf drbd $targetdir
2861 fi
2862 # DRBD requires net activation
2863 MINDI_ADDITIONAL_BOOT_PARAMS="$MINDI_ADDITIONAL_BOOT_PARAMS drbd"
2864 fi
2865
2866 # Management of udev (which includes modprobe in rules)
2867 ps auxww | grep -v grep | grep -qw udevd
2868 if [ $? -eq 0 ]; then
2869 echo "udev device manager found" > $targetdir/tmp/USE-UDEV
2870 LogFile "INFO: udev device manager found"
2871 tar cf - -C / /etc/udev 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in /etc/udev analysis" $templog
2872 # This avoids NIC remapping if on another machine at restore time on Debian/Ubuntu at least
2873 rm -f $targetdir/etc/udev/rules.d/[z]*[0-9][0-9][-_]persistent-net.rules
2874 # Do not do it if it's a link (Ubuntu 64 bits #503)
2875 if [ -e "/lib64/udev" ] && [ ! -h "/lib64" ] && [ ! -h "/lib64/udev" ]; then
2876 tar cf - -C / /lib64/udev 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in /lib64/udev analysis" $templog
2877 fi
2878 if [ -e "/lib32/udev" ] && [ ! -h "/lib32" ] && [ ! -h "/lib32/udev" ]; then
2879 tar cf - -C / /lib32/udev 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in /lib32/udev analysis" $templog
2880 fi
2881 if [ -e "/lib/udev" ] && [ ! -h "/lib" ] && [ ! -h "/lib/udev" ]; then
2882 tar cf - -C / /lib/udev 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in /lib/udev analysis" $templog
2883 fi
2884 if [ -e "/usr/lib/udev" ] && [ ! -h "/usr/lib" ] && [ ! -h "/usr/lib/udev" ]; then
2885 tar cf - -C / /usr/lib/udev 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in /usr/lib/udev analysis" $templog
2886 fi
2887 if [ -x /sbin/udevd ] || [ -x /usr/bin/udevd ] || [ -x /usr/lib/systemd/systemd-udevd ] || [ -x /lib/systemd/systemd-udevd ]; then
2888 CopyFromConf udev $targetdir
2889 else
2890 LogAll "WARNING: udevd daemon not in standard place (/sbin or /usr/bin)"
2891 LogAll " mindi will use static devices which may cause problems"
2892 rm -f $targetdir/tmp/USE-UDEV
2893 fi
2894 fi
2895
2896 # Management of potential HW info (ProLiant only at the moment)
2897 rm -rf $MINDI_CACHE/bkphw
2898 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2899 if [ -d $MINDI_CACHE/bkphw ]; then
2900 LogAll "INFO: Hardware Information found and saved ..."
2901 cp -rp $MINDI_CACHE/bkphw $targetdir
2902 if [ -f $MINDI_CACHE/tools.files ]; then
2903 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2904 LocateDeps $lis > $MINDI_TMP/tools.lis
2905 tar cf - $lis `sort -u $MINDI_TMP/tools.lis` 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in tools.lis analysis" $templog
2906 fi
2907 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2908 mv -f $MINDI_CACHE/mindi-rsthw $targetdir
2909 chmod 755 $targetdir/mindi-rsthw
2910 fi
2911 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2912 fi
2913
2914 # Management of perl scripts delivered needed at restore time
2915 LogAll "INFO: Analyzing perl modules dependencies..."
2916 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
2917 LogFile "DBG4: Perl Modules found:"
2918 LogFile "-------------------------"
2919 cat $MINDI_TMP/perl.lis >> $LOGFILE
2920 LogFile "-------------------------"
2921 tar cf - `cat $MINDI_TMP/perl.lis` 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in perl scripts analysis" $templog
2922
2923 tar cf - -C / /dev/fd0*[1,2][4,7,8]* 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in fd dev analysis" $templog
2924
2925 needed_modules=""
2926 list_of_mods="$CDROM_MODS $FORCE_MODS"
2927
2928 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
2929 # For PXE boot
2930 list_of_mods="$list_of_mods $NET_MODS"
2931 fi
2932 for i in $DENY_MODS; do
2933 LogFile "INFO: Removing $i from the list of modules to load"
2934 list_of_mods=`echo ${list_of_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2935 done
2936
2937 if [ "${kernelname}" != "" ]; then
2938 needed_modules_path=lib/modules/${kernelname}
2939 mkgmopt="-k ${kernelname}"
2940 else
2941 needed_modules_path=lib/modules/$KERVERRUN
2942 mkgmopt="-k $KERVERRUN"
2943 fi
2944
2945 [ -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."
2946 LogAll "INFO: Analyzing kernel modules dependencies..."
2947 needed_modules=`mr-kernel-get-modules $mkgmopt $list_of_mods`
2948
2949 LogFile "INFO: Adding $needed_modules to the rootfs with $mkgmopt"
2950 cp --parents -aL $needed_modules $targetdir/ 2> $templog || LogAll "ERROR: Unable to copy modules to $targetdir" $templog
2951
2952 # Uncompress modules if not using udev and native modprobe
2953 if [ ! -f $targetdir/tmp/USE-UDEV ]; then
2954 for i in $needed_modules; do
2955 if [ "`echo "$i" | grep -E ".gz$"`" ]; then
2956 gunzip -f $targetdir/$i
2957 fi
2958 if [ "`echo "$i" | grep -E ".bz$"`" ]; then
2959 bunzip2 -f $targetdir/$i
2960 fi
2961 if [ "`echo "$i" | grep -E ".xz$"`" ]; then
2962 unxz -f $targetdir/$i
2963 fi
2964 LogFile "INFO: Uncompressing $i"
2965 done
2966 fi
2967
2968 # Also copy modules.* in case of udev so that normal modprobe works
2969 tar cf - -C / /$needed_modules_path/modules.* 2> $templog | (cd "$targetdir" ; tar xf -) || LogAll "ERROR: Unable to copy modules.* to $targetdir" $templog
2970
2971 # Copy FW in case some drivers needs it
2972 for d in "/lib" "/usr/lib"; do
2973 if [ -d "$d/firmware" -a ! -h $d ]; then
2974 cp -a "$d/firmware" "$targetdir$d"
2975 fi
2976 done
2977
2978 # Copy multipath dynamic libraries in case multipath is used (RHEL 6.4 and later)
2979 for d in "/lib" "/usr/lib" "/lib64" "/usr/lib64"; do
2980 if [ -d "$d/multipath" -a ! -h $d ]; then
2981 cp -a "$d/multipath" "$targetdir$d"
2982 fi
2983 done
2984
2985 # Ensure that with mindi-busybox 1.21, the links also exists under /bin for older distro which need it for their scripts
2986 (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)
2987
2988 # Copy an additional ProLiant tool for OBDR support
2989 if [ -f $MINDI_TMP/OBDR ]; then
2990 found=0
2991 if [ -x /usr/bin/hpsa_obdr_mode ]; then
2992 mkdir -p $targetdir/usr/bin
2993 cp -a /usr/bin/hpsa_obdr_mode $targetdir/usr/bin
2994 LogAll "INFO: Copying /usr/bin/hpsa_obdr_mode to ramdisk for improved Smart Array OBDR support"
2995 found=1
2996 fi
2997 if [ -x /usr/bin/sg_wr_mode ]; then
2998 mkdir -p $targetdir/usr/bin
2999 lis="/usr/bin/sg_map /usr/bin/sg_inq /usr/bin/sg_reset /usr/bin/rev"
3000 LocateDeps $lis > $MINDI_TMP/obdr.lis
3001 tar cf - $lis -C / `sort -u $MINDI_TMP/obdr.lis` 2> $templog | (cd $targetdir ; tar xf -) || LogAll "ERROR: Problem in obdr.lis analysis" $templog
3002 LogAll "INFO: Copying /usr/bin/sg_reset to ramdisk for improved SCSI OBDR support"
3003 found=1
3004 fi
3005 if [ $found -eq 0 ]; then
3006 LogAll "WARNING: You're using OBDR mode without having the /usr/bin/hpsa_obdr_mode nor the /usr/bin/sg_wr_mode tool"
3007 LogAll " This may lead to a tape not going back to sequential mode after OBDR boot"
3008 fi
3009 fi
3010
3011 if [ ! -e "/sbin/devfsd" ]; then
3012 LogFile "INFO: Deleting devfsd daemon from ramdisk"
3013 [ ! -e "/sbin/devfsd" ] && LogFile " ...because /sbin/devfsd not found"
3014 rm -f $targetdir/sbin/devfsd
3015 fi
3016 [ "$TAPEDEV" ] && echo -en "$TAPEDEV" > $targetdir/tmp/TAPEDEV-LIVES-HERE
3017 if [ _"$MONDO_SHARE" != _"" ]; then
3018 MakeMondoConfigFile $targetdir/tmp/$MRCFG
3019 cp -f $targetdir/tmp/$MRCFG $MINDI_TMP 2>> $LOGFILE || Die "Cannot copy $MRCFG to ramdisk"
3020 cp -f $MINDI_TMP/mountlist.txt $targetdir/tmp/ 2>> $LOGFILE || Die "Cannot copy mountlist to ramdisk"
3021 echo -en "$FILES_IN_FILELIST" > $targetdir/tmp/FILES-IN-FILELIST
3022 echo -en "$LAST_FILELIST_NUMBER" > $targetdir/tmp/LAST-FILELIST-NUMBER
3023 fi
3024
3025 # Create module list to load at restore time
3026 rm -f $targetdir/tmp/modules
3027 for m in $CDROM_MODS; do
3028 echo $m >> $targetdir/tmp/modules
3029 done
3030
3031 mkdir -p $targetdir/proc
3032 LogFile "---------------------------"
3033 LogFile "Content of initial targetdir:"
3034 LogFile "---------------------------- "
3035 (cd "$targetdir" ; ls -Rla ) >> $LOGFILE
3036 LogFile "---------------------------"
3037}
3038
3039CleanTargetDir() {
3040 [ "$targetdir" != "/" ] && rm -rf $targetdir
3041}
3042
3043PatchBootFiles() {
3044
3045 # Patch the real value of RAMDISK_SIZE now we have it
3046 if [ -d "$bigdir/syslinux" ]; then
3047 find $bigdir/syslinux -type f 1> $MINDI_TMP/bootf.lis 2> /dev/null
3048 fi
3049 if [ -d "$bigdir/EFI" ]; then
3050 find $bigdir/EFI -type f 1>> $MINDI_TMP/bootf.lis 2> /dev/null
3051 fi
3052 for i in `cat $MINDI_TMP/bootf.lis`; do
3053 perl -pi -e "s/RAMDISK_SIZE/$ramdisk_size/" $i
3054 done
3055 rm -f $MINDI_TMP/bootf.lis
3056
3057}
3058
3059MakeBootInitFile() {
3060
3061 local mountpoint tempfile res
3062 tempfile=$MINDI_TMP/temp.rd
3063 res=0
3064
3065 LogAll "INFO: Making Boot RAM Disk ($ramdisk_size KB)"
3066 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (MakeBootInitFile)"
3067
3068 LogAll "INFO: Creating ext2 filesystem on $tempfile"
3069 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
3070 res=$(($res+$?))
3071
3072 mountpoint=$MINDI_TMP/mountpoint.$$
3073 mkdir -p $mountpoint
3074 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."
3075 [ "$targetdir" = "/" ] && echo $targetdir | grep -qv $MINDI_TMP && Die "Wrong targetdir $targetdir"
3076 mv $targetdir/* $targetdir/.??* $mountpoint || Die "Unable to move files from $targetdir to $mountpoint! Please increase EXTRA_SPACE"
3077 res=$(($res+$?))
3078 rmdir $targetdir
3079
3080 LogFile "INFO: initrd image is $rdz_fname"
3081 # Determine what filesystem to use for initrd image
3082 LogFile "INFO: Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
3083 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
3084 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
3085 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ] || [ "$gvFileSystem" = "ext4fs" ]; then
3086 # say what will be used
3087 LogFile "INFO: Creating an $gvFileSystem initrd image..."
3088 # unmount loop filesystem and create image file using the standard approach
3089 sync
3090 umount $mountpoint || Die "Cannot unmount $tempfile"
3091 dd if=$tempfile bs=1k of=${rdz_fname}.tmp > /dev/null 2> /dev/null
3092 res=$(($res+$?))
3093 if [ "$gvFileSystem" = "ext4fs" ] && [ -x "/sbin/tune4fs" ]; then
3094 bs=`/sbin/tune4fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
3095 else
3096 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
3097 fi
3098 MINDI_ADDITIONAL_BOOT_PARAMS="$MINDI_ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
3099 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
3100 res=$(($res+$?))
3101 rm -f ${rdz_fname}.tmp
3102 elif [ "$gvFileSystem" = "initramfs" ]; then
3103 # say what will be used
3104 LogFile "INFO: Creating a gzip'ed cpio (AKA initramfs) initrd image..."
3105 # make sure that cpio is there
3106 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
3107 # create cpio image file and unmount loop filesystem
3108 (cd "$mountpoint" ; find . -print | cpio -o -H newc 2> /dev/null | gzip -9 > $rdz_fname)
3109 res=$(($res+$?))
3110 sync
3111 umount $mountpoint || Die "Cannot unmount $tempfile"
3112 else
3113 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
3114 fi
3115
3116 # log that we are done
3117 if [ "$res" -eq "0" ] ; then
3118 LogAll "INFO: MakeBootInitFile finished without error."
3119 else
3120 LogAll "WARNING: MakeBootInitFile exits WITH ERRORS."
3121 fi
3122
3123 return 0
3124}
3125
3126
3127##############################################################################
3128#----------------------------------- Main -----------------------------------#
3129##############################################################################
3130
3131# Now we can create what we need
3132mkdir -p $MINDI_TMP
3133export bigdir=$MINDI_TMP/bigdir.$$
3134export targetdir=$MINDI_TMP/targetdir.$$
3135
3136# --nolog needs to be first, and is used in analyze-my-lvm
3137if [ "$1" = "--nolog" ] ; then
3138 shift
3139 LOGFILE=/dev/stderr
3140else
3141 > $LOGFILE
3142fi
3143if [ "$1" = "--printvar" ] ; then
3144 shift
3145 if [ _"$1" != _"" ] ; then
3146 set | grep -Ew "^$1" | cut -d= -f2
3147 fi
3148 exit 0
3149fi
3150
3151LogFile "mindi v$MINDI_VERSION"
3152LogFile "-----------------------------"
3153LogFile "Start date : `date`"
3154LogFile "-----------------------------"
3155LogFile "$ARCH architecture detected"
3156LogFile "mindi called with the following arguments:"
3157echo "$@">> $LOGFILE
3158LogFile "-----------------------------"
3159pbdistrocheck --version | grep Version >> $LOGFILE
3160LogFile "pbdistrocheck results:"
3161pbdistrocheck >> $LOGFILE
3162LogFile "-----------------------------"
3163LogFile "MondoRescue perl module:"
3164mr-getparam --version | grep Version >> $LOGFILE
3165LogFile "-----------------------------"
3166
3167# Log some capital variables
3168[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
3169[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
3170LogFile "MONDO_SHARE = $MONDO_SHARE"
3171LogFile "MINDI_LIB = $MINDI_LIB"
3172LogFile "MINDI_SBIN = $MINDI_SBIN"
3173LogFile "MINDI_CONF = $MINDI_CONF"
3174# Purge from potential old run
3175if [ _"$MINDI_CACHE" = _"" ]; then
3176 Die "MINDI_CACHE undefined"
3177else
3178 LogFile "MINDI_CACHE = $MINDI_CACHE"
3179fi
3180
3181if [ -f $MINDI_CONFIG ]; then
3182 LogFile "-----------------------------"
3183 LogFile "Mindi configuration file "
3184 LogFile "-----------------------------"
3185 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
3186 LogFile "-----------------------------"
3187fi
3188LogFile "In Mindi"
3189LogFile "--------"
3190LogFile "EXTRA_SPACE = $EXTRA_SPACE"
3191LogFile "--------"
3192
3193trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
3194
3195# Sanity checks
3196which which > /dev/null 2> /dev/null || Die "Please install 'which'."
3197which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
3198which 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."
3199which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
3200if which awk &> /dev/null ; then
3201 if ! which gawk &> /dev/null ; then
3202 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"
3203 fi
3204fi
3205which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
3206[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
3207
3208[ "`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"
3209
3210# Update the PATH variable if incomplete
3211if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
3212 PATH=$PATH:/sbin:/usr/sbin
3213 export PATH
3214 LogFile "INFO: Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily."
3215 LogFile "INFO: However, you may wish to ask your vendor to provide a permanent fix..."
3216 LogFile "INFO: Or you might like to call 'su -' instead of 'su', for example."
3217fi
3218
3219if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
3220 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
3221fi
3222
3223### TODO
3224### Fix as it's not mandatory on ia64
3225if [ "$ARCH" = "ia64" ] ; then
3226 if which elilo &> /dev/null ; then
3227 LILO_EXE=elilo
3228 else
3229 LILO_EXE=`which false 2> /dev/null`
3230 fi
3231else
3232 FindIsolinuxBinary
3233fi
3234trap "Aborted" SIGTERM
3235DONE="\r\t\t\t\t\t\t\t\tDone. "
3236kernelpath=""
3237MONDO_ROOT=/var/cache/mondo
3238mkdir -p $MONDO_ROOT
3239
3240if [ -d "/proc/lvm" ]; then
3241 # LVM v1
3242 LVMCMD=""
3243 LVM="v1"
3244elif [ -d "/dev/mapper" ]; then
3245 # LVM v2
3246 LVMCMD="lvm"
3247 LVM="v2"
3248else
3249 LVM="false"
3250fi
3251
3252if [ -e "/proc/cmdline" ]; then
3253 CMDLINE="/proc/cmdline"
3254elif [ -e "/tmp/cmdline" ]; then
3255 CMDLINE="/tmp/cmdline"
3256else
3257 CMDLINE="/dev/null"
3258fi
3259
3260LogFile "INFO: LVM set to $LVM"
3261LogFile "----------"
3262LogFile "mount result:"
3263LogFile "-------------"
3264mount >> $LOGFILE
3265if [ -e "/etc/raidtab" ]; then
3266 LogFile "-------------"
3267 LogFile "/etc/raidtab content:"
3268 LogFile "-------------"
3269 cat /etc/raidtab >> $LOGFILE
3270else
3271 LogFile "No file /etc/raidtab"
3272fi
3273if [ -e "/etc/mdadm.conf" ]; then
3274 LogFile "-------------"
3275 LogFile "/etc/mdadm.conf content:"
3276 LogFile "-------------"
3277 cat /etc/mdadm.conf >> $LOGFILE
3278else
3279 LogFile "-------------"
3280 LogFile "No file /etc/mdadm.conf"
3281fi
3282LogFile "-------------"
3283LogFile "cat $CMDLINE"
3284LogFile "-------------"
3285cat $CMDLINE >> $LOGFILE
3286LogFile "-------------"
3287LogFile "cat /proc/swaps:"
3288LogFile "-------------"
3289cat /proc/swaps >> $LOGFILE
3290LogFile "-------------"
3291if [ -e "/proc/mdstat" ]; then
3292 LogFile "cat /proc/mdstat:"
3293 LogFile "-------------"
3294 cat /proc/mdstat >> $LOGFILE
3295else
3296 LogFile "No pseudo file /proc/mdstat"
3297fi
3298LogFile "-------------"
3299LogFile "cat /proc/partitions:"
3300LogFile "-------------"
3301cat /proc/partitions >> $LOGFILE
3302LogFile "-------------"
3303LogFile "cat /proc/filesystems:"
3304LogFile "-------------"
3305cat /proc/filesystems >> $LOGFILE
3306LogFile "-------------"
3307LogFile "lsmod result:"
3308LogFile "-------------"
3309lsmod >> $LOGFILE
3310MODULES="`cat /proc/modules | $AWK '{print $1}'`"
3311if [ -x /usr/sbin/esxcfg-module ]; then
3312 LogFile "-------------"
3313 LogFile "INFO: VMWare ESX server detected - Enabling dedicated support"
3314 LogFile "-------------"
3315 LogFile "VMWare modules"
3316 LogFile "-------------"
3317 /usr/sbin/esxcfg-module -l >> $LOGFILE
3318 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
3319fi
3320LogFile "-------------"
3321LogFile "FORCE_MODS:"
3322LogFile "-------------"
3323LogFile "$FORCE_MODS"
3324LogFile "-------------"
3325LogFile "DENY_MODS:"
3326LogFile "-------------"
3327LogFile "$DENY_MODS"
3328LogFile "-------------"
3329LogFile "df result:"
3330LogFile "----------"
3331df -aT >> $LOGFILE
3332LogFile "-------------"
3333LogFile "df -i result:"
3334LogFile "----------"
3335df -i >> $LOGFILE
3336LogFile "-------------"
3337if [ -r /boot/grub/menu.lst ]; then
3338 LogFile "-------------"
3339 LogFile "INFO: /boot/grub/menu.lst content"
3340 LogFile "-------------"
3341 cat /boot/grub/menu.lst >> $LOGFILE
3342 LogFile "-------------"
3343fi
3344if [ -r /boot/grub/grub.conf ]; then
3345 LogFile "-------------"
3346 LogFile "INFO: /boot/grub/grub.conf content"
3347 LogFile "-------------"
3348 cat /boot/grub/grub.conf >> $LOGFILE
3349 LogFile "-------------"
3350fi
3351if [ -r /boot/grub/grub.cfg ]; then
3352 LogFile "-------------"
3353 LogFile "INFO: /boot/grub/grub.cfg content"
3354 LogFile "-------------"
3355 cat /boot/grub/grub.cfg >> $LOGFILE
3356 LogFile "-------------"
3357fi
3358if [ -r /boot/grub2/grub.cfg ]; then
3359 LogFile "-------------"
3360 LogFile "INFO: /boot/grub2/grub.cfg content"
3361 LogFile "-------------"
3362 cat /boot/grub2/grub.cfg >> $LOGFILE
3363 LogFile "-------------"
3364fi
3365if [ -r /boot/grub/device.map ]; then
3366 LogFile "-------------"
3367 LogFile "INFO: /boot/grub/device.map content"
3368 LogFile "-------------"
3369 cat /boot/grub/device.map >> $LOGFILE
3370 LogFile "-------------"
3371fi
3372if [ -r /boot/grub2/device.map ]; then
3373 LogFile "-------------"
3374 LogFile "INFO: /boot/grub2/device.map content"
3375 LogFile "-------------"
3376 cat /boot/grub2/device.map >> $LOGFILE
3377 LogFile "-------------"
3378fi
3379if [ -r /etc/lilo.conf ]; then
3380 LogFile "-------------"
3381 LogFile "INFO: /etc/lilo.conf content"
3382 LogFile "-------------"
3383 cat /etc/lilo.conf >> $LOGFILE
3384fi
3385if [ -d /boot/efi ]; then
3386 gcf=`find /boot/efi -name 'grub.c*'`
3387 if [ _"$gcf" = _"" ]; then
3388 LogFile "Found a /boot/efi directory without a grub config file in it"
3389 else
3390 LogFile "-------------"
3391 LogFile "INFO: $gcf content"
3392 LogFile "-------------"
3393 cat $gcf >> $LOGFILE
3394 LogFile "-------------"
3395 fi
3396fi
3397
3398LogFile "Full fdisk info"
3399LogFile "---------------"
3400$FDISK -l >> $LOGFILE
3401LogFile "----------------"
3402LogFile "MBRFILE = $MBRFILE"
3403LogFile "GPTMBRFILE = $GPTMBRFILE"
3404
3405# Compute libata version
3406laver=`modinfo libata 2> /dev/null | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
3407# If libata v2 is used then remove ide-generic as it will perturbate boot
3408if [ "`echo $MODULES | grep libata`" ]; then
3409 if [ "$laver" = "2" ]; then
3410 DENY_MODS="$DENY_MODS ide-generic"
3411 LogFile "INFO: ide-generic removed from module list as your system uses libata v2+"
3412 LogFile "-------------"
3413 fi
3414fi
3415
3416# Check for McAfee which disturbs the access to some files (tgz in articular)
3417if [ "x`cat /proc/linuxshield/enabled 2>/dev/null`" = "x1" ]; then
3418 LogFile "WARNING: McAfee LinuxShield is enabled. McAfee might block access to certain special files."
3419 LogFile "WARNING: Check in /var/opt/NAI/LinuxShield/etc/nailsd.cfg for 'nailsd.profile.OAS.action.error: Block'"
3420 LogFile "WARNING: You have two options:"
3421 LogFile "WARNING: - Exclude all directories with special files (check McAfee System Events Log)"
3422 LogFile "WARNING: - Disable the scanner during the backup"
3423fi
3424
3425#
3426# If we have a USB device we need to store info
3427# and remove it from the parameters line
3428#
3429if [ "$#" -ne "0" ] ; then
3430 if [ "$1" = "--usb" ] ; then
3431 shift
3432 USBDEVICE=$1
3433 if [ _"$USBDEVICE" = _"" ]; then
3434 Die "No USB device specified"
3435 fi
3436 shift
3437 fi
3438fi
3439
3440if [ "$#" -ne "0" ] ; then
3441 if [ "$1" = "--findkernel" ] ; then
3442 resk=`TryToFindKernelPath`
3443 # Avoids logfile content for mondo
3444 export MONDO_SHARE=""
3445 if [ "$resk" = "" ] ; then
3446 if [ $KERNEL_IS_XEN = "yes" ]; then
3447 echo "$xenkernelpath"
3448 LogFile "INFO: xenkernelpath = $xenkernelpath"
3449 MindiExit 0
3450 else
3451 MindiExit -1
3452 fi
3453 else
3454 echo "$resk"
3455 LogFile "INFO: kernelpath = $resk"
3456 MindiExit 0
3457 fi
3458 elif [ "$1" = "--locatedeps" ] ; then
3459 [ ! "$2" ] && Die "Please specify the binary to look at"
3460 LocateDeps $*
3461 # Avoids logfile content for mondo
3462 export MONDO_SHARE=""
3463 MindiExit $?
3464 elif [ "$1" = "--readalllink" ] ; then
3465 [ ! "$2" ] && Die "Please specify the binary to look at"
3466 # Avoids logfile content for mondo
3467 export MONDO_SHARE=""
3468 mr-read-all-link $2
3469 MindiExit $?
3470 elif [ "$1" = "--makebcf" ] ; then
3471 [ ! "$2" ] && Die "Please specify the boot loader to check (syslinux, grub, grub2)"
3472 MakeBootConfFile $2
3473 MindiExit 0
3474 elif [ "$1" = "--makemessage" ] ; then
3475 MakeMessageFile | cut -c1-80
3476 MindiExit 0
3477 elif [ "$1" = "--makemountlist" ] ; then
3478 [ ! "$2" ] && Die "Please specify the output file"
3479 MakeMountlist $2
3480 CheckMountlist $2
3481 # Avoids logfile content for mondo
3482 export MONDO_SHARE=""
3483 MindiExit $?
3484 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
3485 echo "Mindi v$MINDI_VERSION"
3486 # Avoids logfile content for mondo
3487 export MONDO_SHARE=""
3488 MindiExit 0
3489 elif [ "$1" = "--ironic" ] ; then
3490 [ ! "$2" ] && [ ! -f "$2" ] && Die "Please specify the kernel to use"
3491 [ ! "$3" ] && [ ! -f "$3" ] && Die "Please specify the initramfs to use"
3492 [ "$4" ] && [ "$4" != "UEFI" ] && [ "$4" != "BIOS" ] && Die "Please specify the boot mode as BIOS or UEFI"
3493 #TODO: See how we can influence the boot loader
3494 [ "$5" ] && [ "$5" != "isolinux" ] && [ "$5" != "grub" ] && [ "$5" != "grub2" ] && Die "Please specify the boot loader as isolinux or grub or grub2"
3495 if [ "$5" ]; then
3496 boottype=$5
3497 fi
3498 [ "$6" ] && [ ! -e "$6" ] && Die "Please specify an existing boot loader path for $boottype"
3499 if [ "$6" ]; then
3500 bootbin=$6
3501 fi
3502 kernelpath=$2
3503 BOOT_TYPE=$4
3504 # Ironic requires some specific boot parameters
3505 MINDI_ADDITIONAL_BOOT_PARAMS="selinux=0 barrier=off udevtimeout=10 systemd.debug-shell boot_method=vmedia"
3506 MINDI_BOOT_TIMEOUT=10
3507 EXTRA_SPACE=1500000
3508 # Get the local improvements to the configuration
3509 if [ -f $MINDI_CONFIG ]; then
3510 . $MINDI_CONFIG
3511 fi
3512 PrepareBootDir
3513 PrepareBigDirTar
3514 CleanBigDir
3515 cp $3 $MINDI_TMP/initrd.img
3516 MakeBootableDevice ISO
3517 MindiExit 0
3518 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
3519 MONDO_TMP=$2
3520 # Change MINDI_TMP for the one provided by mondo
3521 # So that it can get back the built files
3522 if [ _"$MONDO_TMP" = _"" ]; then
3523 Die "MONDO_TMP is empty, aborting"
3524 fi
3525 if [ _"$MONDO_TMP" = _"/" ]; then
3526 Die "MONDO_TMP is /, aborting"
3527 fi
3528 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2>> $LOGFILE
3529 rmdir $MINDI_TMP
3530 export MINDI_TMP=$MONDO_TMP
3531 mkdir -p $MINDI_TMP
3532
3533 # This is the scratch dir in mondo - subdir images
3534 MINDI_CACHE=$3
3535 LogFile "MINDI_CACHE = $MINDI_CACHE"
3536 LogFile "MINDI_TMP = $MINDI_TMP"
3537
3538 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
3539 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
3540
3541###
3542### Sq-Modification...
3543### Attempt to locate kernel specific module path
3544### if module path is found then use it other wise use uname -r to set it...
3545###
3546 if [ $KERNEL_IS_XEN = "yes" ]; then
3547 LogAll "INFO: xenkernelpath = $xenkernelpath"
3548 fi
3549 kernelname=`echo $kernelpath | cut -d'-' -f2- | sed 's/.[bg]z[2]*$//'`
3550 if [ ! -d "/lib/modules/$kernelname" ]; then
3551 LogAll "WARNING: Module path for ${kernelpath} not found..."
3552 LogAll " using running kernel\'s modules."
3553 kernelname=$KERVERRUN
3554 else
3555 LogAll "INFO: Using modules for kernel: ${kernelname}"
3556 fi
3557 LogAll "INFO: kernelname = $kernelname"
3558 LogAll "INFO: kernelpath = $kernelpath"
3559###
3560### end of Sq-Modification
3561###
3562 TAPEDEV=$5
3563 TAPESIZE=$6
3564 FILES_IN_FILELIST=$7
3565 USE_LZO=$8
3566 CDRECOVERY=$9
3567 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
3568 IMAGE_DEVS=""
3569 else
3570 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
3571 fi
3572 if [ "${11}" ] ; then
3573 LILO_OPTIONS=""
3574 # LogAll "INFO: LILO will use conservative settings, to be compatible with older BIOSes."
3575 fi
3576 LAST_FILELIST_NUMBER=${12}
3577 ESTIMATED_TOTAL_NOOF_SLICES=${13}
3578 export MINDI_EXCLUDE_DEVS="${14}"
3579 USE_COMP="${15}"
3580 USE_LILO="${16}"
3581 USE_STAR="${17}"
3582 INTERNAL_TAPE_BLOCK_SIZE="${18}"
3583 DIFFERENTIAL="${19}"
3584 USE_GZIP="${20}"
3585 USE_LZMA="${21}"
3586 NOT_BOOT="${22}"
3587 BOOT_TYPE="${23}"
3588 [ "$USE_COMP" = "" ] && USE_COMP=yes
3589 [ "$USE_GZIP" = "" ] && USE_GZIP=no
3590 [ "$USE_LZMA" = "" ] && USE_LZMA=no
3591 [ "$NOT_BOOT" = "" ] && NOT_BOOT=no
3592 [ "$TAPEDEV" ] && LogAll "INFO: This is a tape-based backup. Fine."
3593 # MONDO_ROOT is the real scratchdir
3594 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
3595 if [ _"$MONDO_ROOT" != _"" ]; then
3596 mkdir -p $MONDO_ROOT
3597 else
3598 Die "MONDO_ROOT is undefined"
3599 fi
3600 else
3601 LogScreen "Syntax: mindi [--custom ....MondoRescue parameters...]"
3602 LogScreen " mindi --ironic kernel initrd [BIOS|UEFI] [syslinux|grub|grub2] [/path/to/bootloader]"
3603 LogScreen " mindi --locatedeps file"
3604 LogScreen " mindi --makemessage"
3605 LogScreen " mindi --findkernel"
3606 LogScreen " mindi --makemountlist file"
3607 LogScreen " mindi --makebcf bootloader"
3608 LogScreen " mindi -V"
3609 MindiExit -1
3610 fi
3611fi
3612
3613if [ _"$MINDI_CACHE" != _"" ]; then
3614 rm -rf $MINDI_CACHE/* 2> /dev/null
3615 mkdir -p $MINDI_CACHE
3616fi
3617
3618[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3619
3620if [ _"$MONDO_SHARE" = _"" ]; then
3621 LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
3622 LogAll "Latest Mindi is available from http://www.mondorescue.org"
3623 LogAll "BusyBox sources are available from http://www.busybox.net"
3624 LogAll "------------------------------------------------------------------------------"
3625else
3626 LogFile "INFO: You are using Mindi v$MINDI_VERSION to make boot+data disks"
3627fi
3628if [ -f $MINDI_LIB/rootfs/usr/bin/busybox ]; then
3629 LogAll "INFO: You are using Mindi-`$MINDI_LIB/rootfs/usr/bin/busybox 2>&1 | head -1`"
3630else
3631 LogAll "ERROR: Unable to find mindi-busybox, please install it"
3632 MindiExit -1
3633fi
3634
3635for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
3636 modinfo $i 2> /dev/null 1> /dev/null
3637 if [ $? -eq 0 ]; then
3638 modprobe $i 2>&1 > /dev/null
3639 fi
3640done
3641
3642LogFile "DIFFERENTIAL = $DIFFERENTIAL"
3643LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
3644LogFile "NOT_BOOT = '$NOT_BOOT'"
3645if [ "$NOT_BOOT" != "" ] && [ "$NOT_BOOT" != "0" ] && [ "$NOT_BOOT" != "no" ] ; then
3646 LogAll "INFO: Just creating $MRCFG and a small all.tar.gz for Mondo. Nothing else."
3647 MakeMondoConfigFile $MINDI_TMP/$MRCFG
3648 MakeMountlist $MINDI_TMP/mountlist.txt
3649 CheckMountlist $MINDI_TMP/mountlist.txt
3650 mkdir -p $MINDI_TMP/small-all/tmp
3651 cp -f $MINDI_TMP/{mountlist.txt,$MRCFG,filelist.full.gz,biggielist.txt} $MINDI_TMP/small-all/tmp 2>> $LOGFILE || Die "Cannot copy small all.tar.gz"
3652 (cd $MINDI_TMP/small-all ; tar -cv ./tmp | gzip -9 > $MINDI_TMP/all.tar.gz 2>> $MINDI_TMP/$$.log || Die "Cannot make small all.tar.gz" $MINDI_TMP/$$.log)
3653 sleep 2
3654 LogAll "Done. Exiting."
3655 MindiExit 0
3656fi
3657
3658if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3659 LogAll "INFO: Including the generation of a Bootable USB device on $USBDEVICE"
3660fi
3661
3662if [ "$kernelpath" = "" ] ; then
3663 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
3664 echo -en "\nDo you want to use your own kernel to build the boot disk ([y]/n) ?"
3665 read ch
3666 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
3667 USE_OWN_KERNEL="yes"
3668 else
3669 USE_OWN_KERNEL="no"
3670 fi
3671 if [ "$USE_OWN_KERNEL" = "yes" ]; then
3672 kernelpath=`TryToFindKernelPath`
3673 if [ "$kernelpath" = "" ] ; then
3674 echo -n "Please enter kernel path : "
3675 read kernelpath
3676 fi
3677 fi
3678fi
3679
3680echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
3681[ "$(($RANDOM%64))" -eq "0" ] && LogAll "INFO: Dude, I've looked inside your computer and it's really dusty..."
3682
3683PrepareBigDir
3684bigdir_size=`du -sk $bigdir | cut -f1`
3685LogFile "---------------------------"
3686LogFile "INFO: bigdir size is $bigdir_size KB"
3687
3688PrepareTargetDir || Die "Could not create initrd.img in target dir"
3689targetdir_size=`du -sk $targetdir | cut -f1`
3690LogFile "---------------------------"
3691LogFile "INFO: targetdir size is $targetdir_size KB"
3692LogFile "---------------------------- "
3693
3694# Now we can compute it correctly with some extra in case of...
3695export ramdisk_size=$(($bigdir_size+$targetdir_size+$EXTRA_SPACE))
3696# And now we can patch the value in conf files
3697PatchBootFiles
3698# And tar them
3699PrepareBigDirTar
3700# And prepare boot setup
3701MakeBootInitFile
3702# Now cleans up stuff
3703CleanBigDir
3704CleanTargetDir
3705
3706[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
3707...Or type 'memtest' to test your machine's RAM thoroughly.\n"
3708
3709if [ _"$MONDO_SHARE" = _"" ]; then
3710 OfferToMakeBootableISO
3711 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3712 OfferToMakeBootableUSB
3713 fi
3714 LogAll "INFO: Mindi Finished"
3715elif [ "$TAPEDEV" ] ; then
3716 if [ "$ARCH" != "ia64" ] ; then
3717 # We need to keep the img file as boot file for ia64 platform
3718 rm -f $MINDI_CACHE/{*img,*iso}
3719 else
3720 rm -f $MINDI_CACHE/*iso
3721 fi
3722 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3723 OfferToMakeBootableUSB
3724 fi
3725 OfferToMakeBootableISO
3726 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3727 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
3728 else
3729 Die "Cannot find all.tar.gz, to be written to tape"
3730 fi
3731elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3732 OfferToMakeBootableUSB
3733else
3734 OfferToMakeBootableISO
3735fi
3736
3737if [ -f $MINDI_TMP/$MRCFG ]; then
3738 LogFile "INFO: Your $MRCFG file is:"
3739 LogFile "--------------------------"
3740 cat $MINDI_TMP/$MRCFG >> $LOGFILE
3741 LogFile "--------------------------"
3742else
3743 if [ _"$MONDO_SHARE" != _"" ] ; then
3744 LogAll "ERROR: You don't have a $MRCFG file !"
3745 fi
3746fi
3747# cleanup
3748MindiExit 0
Note: See TracBrowser for help on using the repository browser.