source: MondoRescue/branches/3.3/mindi/mindi

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

Remove EFI references for ia64

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