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

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