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

Last change on this file since 3886 was 3843, checked in by Bruno Cornec, 3 months ago

Fix find_dvd_device by removing useless second param and using wodim -inq

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