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
Line 
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#
8# Mindi can create a multi-image boot/root kit. The first image is the boot
9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
16ARCH=`/bin/uname -m`
17KERVERRUN=`/bin/uname -r`
18# By default we use the running kernel as a reference
19KERVER=$KERVERRUN
20
21# In case of problem with udev you can try to add udevdebug
22MINDI_ADDITIONAL_BOOT_PARAMS="devfs=nomount noresume selinux=0 barrier=off udevtimeout=10"
23MINDI_DEFAULT_BOOT_OPTION="interactive"
24# For a CD Recovery use 10000 instead rather. Beware till Hardcoded below. Planned to be changed on the perl version
25# So this parameter only applies to non CD recovery.
26MINDI_BOOT_TIMEOUT="300"
27
28MINDI_REV=PBREV
29MINDI_VER=PBVER
30
31MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
32MINDI_PREFIX=XXX
33MINDI_CONF=YYY
34MINDI_SBIN=${MINDI_PREFIX}/sbin
35MINDI_LIB=LLL
36MINDI_CACHE=/var/cache/mindi
37
38MRCFG=mondorestore.cfg
39
40# Temporary directory for mindi
41TMPDIR=/tmp
42
43EXTRA_SPACE=120000 # increase if you run out of ramdisk space
44BOOT_SIZE=65600 # size of the boot disk
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
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
54USE_OWN_KERNEL="yes"
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.
58
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.
62xenkernelpath=""
63
64MY_FSTAB=/etc/fstab
65TAPE_MODS="ht st osst ide-tape ide_tape"
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"
67
68# ide-probe-mod
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"
70PCMCIA_MODS="pcmcia_core ds yenta_socket"
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"
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"
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 "
74# Replace with that line for HP OCMP e.g.
75#DENY_MODS="MPS_Driver_Mapper mps octtldrv tscttl streams kqemu fdomain"
76DENY_MODS="kqemu vxfen"
77# Force some modules to be included
78FORCE_MODS=""
79
80# Find MBR in case of bootable USB device to build
81MBRFILE=/usr/lib/syslinux/mbr.bin
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
86
87LOGFILE=/var/log/mindi.log
88BOOT_MEDIA_MESSAGE="\
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\
101"
102FDISK=$MINDI_SBIN/parted2fdisk
103
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
109DEPLIST_FILE="$MINDI_CONF/deplist.txt"
110DEPLIST_DIR="$MINDI_CONF/deplist.d"
111
112ISO_CMD="/usr/bin/mkisofs"
113ISO_OPT="-J -r -v -p Mindi -publisher http://www.mondorescue.org -A Mindi"
114
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
122
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}
131
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
153# Last function called before exiting
154# Parameter is exit code value
155# Should be declared here as used immediately below potentialy
156MindiExit() {
157 LogFile "Mindi $MINDI_VERSION is exiting"
158 LogFile "End date : `date`"
159 if [ _"$MONDO_SHARE" != _"" ] ; then
160 echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
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
166 echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
167 fi
168
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
179Die() {
180 local i
181 if [ "$1" = "" ] ; then
182 LogAll "FATAL ERROR"
183 else
184 LogAll "FATAL ERROR. $1"
185 fi
186 if [ _"$2" != _"" ]; then
187 grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
188 fi
189 rm -f "$2"
190
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"
194 MindiExit -1
195}
196
197# Now we can create what we need
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
203if [ _"$MINDI_TMP" = _"" ]; then
204 Die "MINDI_TMP is empty, aborting"
205fi
206if [ _"$MINDI_TMP" = _"/" ]; then
207 Die "MINDI_TMP is /, aborting"
208fi
209export MINDI_TMP
210
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
222 [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
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
239 LogFile "INFO: $mappath already added"
240 return
241 elif [ -d "$bigdir/$mappath" ] ; then
242 echo "Cannot add $mappath: it's a directory. Sorry."
243 return
244 fi
245 LogFile "INFO: Added kbd map $mappath"
246 if [ ! -e "$mappath" ] ; then
247 mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
248 if [ ! -e "$mappath" ] ; then
249 LogAll "WARNING: Cannot add $mappath: kbd map file not found"
250 return
251 fi
252 else
253 echo -en "`basename $mappath | tr '.' '#' | sed s/#kmap#gz// | sed s/#inc#gz//` " | tr '#' '.'
254 fi
255
256 #cp -a -n --parents -t $mappath $bigdir 2>> $MINDI_TMP/$$.log || LogAll "WARNING: AKMF -- Could not copy $mappath to $bigdir" $MINDI_TMP/$$.log
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
258 if [ "`echo $mappath | grep -F ".gz"`" ] ; then
259 included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'//g | cut -d' ' -f2`
260 else
261 included_list=`grep -Fi include $mappath | sed s/'"'//g | cut -d' ' -f2`
262 fi
263 for included_item in $included_list ; do
264 if [ ! -e "$included_item" ] ; then
265 sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
266 [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
267 for ii in $sss ; do
268 [ -e "$ii" ] && AddKeyboardMappingFile $ii
269 done
270 else
271 AddKeyboardMappingFile $included_item
272 fi
273 done
274}
275
276
277CopyDependenciesToDirectory() {
278 local outdir incoming counter d found tdir
279 outdir=$1
280 mkdir -p $outdir
281 incoming=`ReadLine`
282 counter=0
283 while [ "$incoming" != "" ] ; do
284 # Non absolute file names should not arrive till here => skipped
285 if [ `echo "$incoming" | cut -c1` != '/' ]; then
286 LogAll "WARNING: Unable to handle $incoming"
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
297 if [ -d "$incoming" -a ! -h "$incoming" ]; then
298 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir 0
299 elif [ -e "$incoming" ] && [ $found = "false" ]; then
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
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
311 gunzip -f $outdir/$incoming || LogAll "WARNING: Cannot gunzip $outdir/$incoming"
312 fi
313 [ -x "$outdir" ] && StripExecutable $outdir
314 counter=$(($counter+1))
315 LogProgress $counter $2
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
339 return 0
340 fi
341 echo -en "Dropping i686-optimized libraries if appropriate"
342 for optimized_lib_name in $list_of_optimized_libraries ; do
343 echo -en "."
344 reason=""
345 vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
346 echo "$vanilla_lib_name" >> $filelist
347 LogFile "INFO: Adding $vanilla_lib_name to filelist"
348 mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null
349 rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null
350
351 # This may return multiple files
352 for resolved in `mr-read-all-link $vanilla_lib_name`; do
353 LogFile "INFO: Adding as deps $resolved to filelist"
354 vanilla_resolved_name=`echo "$resolved" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
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
365 done
366 done
367 $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
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
375 LogAll "INFO: Analyzing your keyboard's configuration."
376 KEYDIR=/usr/lib/kbd
377 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware
378 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
379 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
380 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
381 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole-setup
382 [ ! -e "$KEYDIR" ] && KEYDIR=/lib/kbd
383 if [ ! -e "$KEYDIR" ] ; then
384 LogAll "WARNING: Keyboard mapping directory not found. I shall use default map at boot-time."
385 return 0
386 fi
387 if [ -e "/etc/sysconfig/keyboard" ] ; then
388 LogFile "INFO: Red Hat-style config detected."
389 keyfile=/etc/sysconfig/keyboard
390 elif [ -e "/etc/vconsole.conf" ] ; then
391 LogFile "INFO: New Fedora style config detected."
392 keyfile=/etc/vconsole.conf
393 elif [ -e "/etc/rc.d/rc.keymap" ] ; then
394 LogFile "INFO: Slackware-style config detected."
395 keyfile=/etc/rc.d/rc.keymap
396 elif [ -e "/etc/rc.config" ] ; then
397 LogFile "INFO: Debian-style config detected."
398 keyfile=/etc/rc.config
399 elif [ -e "/etc/console/boottime.kmap.gz" ] ; then
400 LogFile "INFO: Debian-style config detected."
401 mkdir -p $bigdir/tmp
402 echo "keymap-lives-here /etc/console/boottime.kmap.gz" >> $bigdir/tmp/$MRCFG
403 KBDEPTH=0
404 mkdir -p $bigdir/etc/console
405 cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
406 echo ""
407 echo -e "$DONE"
408 return 0
409 elif [ -e "/etc/console-setup/boottime.kmap.gz" ] || [ -e "/etc/console-setup/cached.kmap.gz" ] ; then
410 LogFile "INFO: Ubuntu-style config detected."
411 mkdir -p $bigdir/tmp
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
417 echo "keymap-lives-here $kbdfile" >> $bigdir/tmp/$MRCFG
418 KBDEPTH=0
419 mkdir -p $bigdir/etc/console-setup
420 cp $kbdfile $bigdir/etc/console-setup 2>> $LOGFILE
421 echo ""
422 echo -e "$DONE"
423 return 0
424 elif [ -e "/etc/rc.conf" ] ; then
425 LogFile "INFO: ArchLinux config detected."
426 keyfile=/etc/rc.conf
427 elif [ -e "/etc/conf.d/keymaps" ] ; then
428 LogFile "INFO: Gentoo-style config detected."
429 keyfile=/etc/conf.d/keymaps
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
433 else
434 LogFile "Searching for rc.config ..."
435 keyfile=`find /etc -name rc.config | head -n1`
436 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
437 LogAll "WARNING: Unknown config detected. Default keyboard map will be used."
438 return
439 else
440 LogFile "INFO: Found $keyfile"
441 fi
442 fi
443 if [ ! -e "$KEYDIR/keymaps" ] ; then
444 LogAll "WARNING: Keyboard mapping directory not found. Default keyboard map will be used."
445 return
446 fi
447 LogFile "INFO: keyfile=$keyfile"
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$//'`
450 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware
451 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | grep -v '^#' | tr -d '"' |cut -d'=' -f2` # Gentoo, ArchLinux & New fedora
452 [ ! "$locale" ] && locale=`grep -E 'XkbLayout' "$keyfile" | grep -v '^#' | awk '{print $3}' | tr -d '"'` # Fedora 19
453 LogFile "INFO: locale=$locale"
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 " *#.*"`
461 # If we have multiple keymaps then log it !!
462 echo "$mp" | grep -q " " >> $LOGFILE
463 if [ $? -eq 0 ]; then
464 LogAll "WARNING: Multiple keymaps found: $mp"
465 LogFile "INFO: The following one will be used"
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
472 mappath=$(find / -wholename "*/kbd/keymaps/*/$locale | head -1")
473 fi
474 LogFile "INFO: mappath = $mappath"
475 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
476 LogAll "WARNING: Keyboard mapping file not found. Default keyboard map will be used."
477 return
478 fi
479 LogAll "INFO: Adding the following keyboard mapping tables: "
480 mkdir -p $bigdir/tmp
481 echo "keymap-lives-here $mappath" >> $bigdir/tmp/$MRCFG
482 KBDEPTH=0
483 AddKeyboardMappingFile $mappath
484 echo ""
485 echo -e "$DONE"
486 rm -f $MINDI_TMP/keymaps.find
487 return 0
488}
489
490
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
497 [ ! -e "$LDLINUXC32" ] && LDLINUXC32=/usr/lib/syslinux/modules/bios/ldlinux.c32
498 [ ! -e "$LDLINUXC32" ] && LDLINUXC32=/usr/lib64/syslinux/modules/bios/ldlinux.c32
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
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
515 [ ! -e "$MBOOTC32" ] && MBOOTC32=/usr/lib/syslinux/modules/bios/mboot.c32
516 [ ! -e "$MBOOTC32" ] && MBOOTC32=/usr/lib64/syslinux/modules/bios/mboot.c32
517 [ ! -e "$MBOOTC32" ] && MBOOTC32=`find / -name mboot.c32 | grep -x "/.*/mboot.c32"`
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"
519 LogFile "INFO: Found mboot.c32 at $MBOOTC32"
520}
521
522FindIsolinuxBinary() {
523 ISOLINUX=/usr/lib/isolinux.bin
524 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
525 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
526 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
527 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
528 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
529 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/ISOLINUX/isolinux.bin
530 [ ! -e "$ISOLINUX" ] && ISOLINUX=`find / -name isolinux.bin | grep -x "/.*/isolinux.bin"`
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"
532 LogFile "INFO: Found isolinux.bin at $ISOLINUX"
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
541 tempfile=$MINDI_TMP/$$.txt
542 incoming=`ReadLine`
543
544 > $tempfile
545 progress=0
546 res=0
547 noof_lines=$2
548 while [ "$incoming" != "" ] ; do
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
556 filelist=`GenerateListForFile "$incoming"`
557 r=$?
558 [ "$r" -ne "0" ] && LogAll "WARNING: $incoming not found"
559 res=$(($res+$r))
560# LogFile "INFO: '$incoming' generates filelist '$filelist'"
561 for fname in $filelist ; do
562 [ "$fname" != "" ] && echo "$fname" >> $tempfile
563 done
564 progress=$(($progress+1))
565 LogProgress $progress $noof_lines
566 incoming=`ReadLine`
567 done
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`
579 if [ "$tool" = "$lvmresolved" ]; then
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;}'`
587 if [ "$lvmversion" = "200" ]; then
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))
616 LogProgress $progress $noof_lines
617 incoming=`ReadLine`
618 done
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`
627 LogFile "---------------------------------"
628 LogFile "List of dependencies: "
629 LogFile "---------------------------------"
630 for fname in `cat $tempfile` ; do
631 echo "$fname" | tee -a $LOGFILE >> $outfile.pre
632 LocateDeps $fname | tee -a $LOGFILE >> $outfile.pre
633 progress=$(($progress+1))
634 LogProgress $progress $noof_lines
635 done
636 if [ _"$MONDO_SHARE" != _"" ]; then
637 mkdir -p $bigdir/tmp
638 mkdir -p $bigdir/usr/bin
639 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
640 LogAll "\nINFO: Incorporating post-nuke tarball"
641 old_pwd=`pwd`
642 cd "$bigdir"
643 tar -zxf $MINDI_TMP/post-nuke.tgz 2>> $MINDI_TMP/$$.log || LogAll "ERROR: when untarring post-nuke tarball" $MINDI_TMP/$$.log
644 cd "$old_pwd"
645 fi
646 if cp -f $MINDI_TMP/mondo*restore $bigdir/usr/bin 2>> $LOGFILE ; then
647 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre
648 else
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."
654 Die "Odd."
655 fi
656 cp -f $MINDI_TMP/BOOTLOADER.* $bigdir 2>> $LOGFILE || LogIt "\nINFO: Mondo v1.2x defaults to LILO as the bootloader, BTW."
657 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
658 LogAll "\nINFO: Incorporating Network-related settings"
659 for r in NETFS-* ; do
660 cp -f $MINDI_TMP/$r $bigdir/tmp 2>> $LOGFILE || Die "Cannot copy $r - did you run out of disk space?"
661 LogFile "INFO: Copying $r to ramdisk"
662 done
663 fi
664 fi
665 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
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
700# Check kernel filesystem capabilites for accessing initrd image
701# Could be ext2 FS (old mode) or initramfs (new mode)
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"
717 local lcMagicExt2fs="EXT2-fs: blocksize too small for device."
718 local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device."
719 local lcMagicInitfs="<6>checking if image is initramfs...|[<]*6[>]*Unpacking initramfs...|<6>Trying to unpack rootfs image as initramfs"
720
721 # local variables
722 local lvOffset
723 local lvScanRes
724 local lvUseFilesystem
725
726 # say where we are.
727 LogFile "INFO: GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage"
728
729 # verify that file exists
730 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
731
732 # Kernel may be gzip compressed - Case of RHEL5 - SLES11SP1
733 file $lvKernelImage 2>&1 | grep -q gzip
734 if [ $? -eq 0 ]; then
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
745 else
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`
750 fi
751 fi
752
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"
762 else
763 # In that case, we are most probably after 2.6.30 and use the supported initramfs
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"
767 lvUseFilesystem="initramfs"
768 fi
769
770 # say what we are using
771 LogFile "INFO: GetInitrdFilesystemToUse(): Filesytem to use for initial ram disk is $lvUseFilesystem."
772
773 # return file system to use
774 echo "$lvUseFilesystem"
775
776}
777
778# Searches members of raid device
779# $1: raid device (/dev/md...)
780GetRaidDevMembers() {
781 if [ ! -f /etc/raidtab ]; then
782 return
783 fi
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
791 grep -Evx " *#.*| *none.*" $MY_FSTAB | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/\/fdd|\/cdr|\/zip|\/floppy/ {print $1}'
792 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
793 if [ -e "/vmfs/volumes" ]; then
794 # For VMWare ESX 3 get the device names of these volumes
795 vdf -P | grep -E '/vmfs/volumes' | $AWK '{print $1}'
796 fi
797 return
798}
799
800
801ListImagesForUser() {
802 local path fname
803 path=$MINDI_CACHE
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() {
813 local module_list module fname r kern
814 module_list="$MODULES"
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
819###
820### Sq-Modification ... Use kernelname for module search path if specified
821###
822 if [ "${kernelname}" != "" ]
823 then
824 kern=${kernelname}
825 else
826 kern="$KERVERRUN"
827 fi
828 export KERVER=$kern
829###
830### Sq-Mod End
831###
832 # Get rid of duplicates
833 for module in `echo $module_list | tr ' ' '\n' | sort -u` ; do
834 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
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
841 else
842 [ -f "$r" ] && echo "$r"
843 fi
844 LogFile "INFO: module $module --> $r"
845 done
846 find /lib/modules/$kern/modules.* -type f 2> /dev/null
847}
848
849#
850# Critical function which computes all dependencies (dyn. lib.)
851# for a list of binaries
852#
853LocateDeps() {
854 local incoming fname deps
855 incoming="$*"
856 deps=""
857
858 for fname in $incoming ; do
859 if [ ! -e "$fname" ] ; then
860 LogFile "WARNING: $fname does not exist; cannot be LDD'd."
861 if echo $fname | grep lvm &> /dev/null ; then
862 LogFile " This warning only affects you if you are using LVM."
863 if echo "$MODULES" | grep lvm &> /dev/null ; then
864 LogFile " I think you are, so please take heed!"
865 else
866 LogFile " I don't think you are, so don't worry about it."
867 fi
868 fi
869 else
870 deps="$deps $fname"
871 fi
872 done
873 mr-read-all-link `mr-process-ldd $deps | sort -u` | sort -u
874}
875
876
877LocateFile() {
878 local i j path fname_to_find location output resolved tmp stub cache_id loclist
879 fname_to_find="$1"
880 # It's an absolute path
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
892 if [ -h "$output" ] ; then
893 output="`mr-read-all-link $output` $output"
894 fi
895 echo "$output"
896 return 0
897 fi
898 # It's not an absolute path
899 output=""
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
906 output="`mr-read-all-link $path/$fname_to_find` $output"
907 fi
908 done
909 if [ "$output" = "" ] ; then
910 return 1
911 fi
912 echo "$output"
913 return 0
914}
915
916LogProgress() {
917 local i progress modres noof_lines title
918
919 progress=$1
920 noof_lines=$2
921 title=$3
922
923 i=$(($progress*100))
924 if [ $noof_lines -ne 0 ]; then
925 i=$(($i/$noof_lines))
926 else
927 i=0
928 fi
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
942}
943
944# Called by TurnTgzIntoRdz, to make /tmp/$MRCFG
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
951 [ "$USBDEVICE" ] && echo "usb-dev $USBDEVICE" >> $outfile
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"
956 use_gzip=$USE_GZIP; [ "$use_gzip" = "" ] && use_gzip="no"
957 use_lzma=$USE_LZMA; [ "$use_lzma" = "" ] && use_lzma="no"
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
961 echo "use-gzip $use_gzip" >> $outfile
962 echo "use-star $use_star" >> $outfile
963 echo "use-lzma $use_lzma" >> $outfile
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
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
970 AddFileToCfgIfExists $MINDI_TMP/ISO-DIR iso-dir $outfile
971 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
972 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME bootloader.name $outfile
973 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.VER bootloader.ver $outfile
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
977 AddFileToCfgIfExists $MINDI_TMP/ACL acl $outfile
978 AddFileToCfgIfExists $MINDI_TMP/XATTR xattr $outfile
979 AddFileToCfgIfExists $MINDI_TMP/OBDR obdr $outfile
980
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
985}
986
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}
997
998
999MakeMountlist() {
1000 local mountlist all_partitions current_partition \
1001partition_size partition_format outstring partition_number \
1002partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
1003absolute_partition old_partition_fmt current_lvolume uname skip
1004
1005 LogFile "------------------------------------"
1006 LogFile "Your raw fstab file looks like this:"
1007 LogFile "------------------------------------"
1008 cat $MY_FSTAB >> $LOGFILE
1009 LogAll "-----------------------------------"
1010 LogAll "Your mountlist will look like this:"
1011 LogAll "-----------------------------------"
1012
1013# mountlist(OUT)
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
1021 [ "$mountlist" != "" ] && rm -Rf $mountlist
1022 > $mountlist
1023 all_partitions=""
1024
1025 if [ $LVM != "false" ]; then
1026 LogAll "INFO: Analyzing LVM..."
1027 $MINDI_LIB/analyze-my-lvm > $MINDI_TMP/lvm.res
1028 if [ $? -ne 0 ]; then
1029 LVM="false"
1030 fi
1031 # Excluded LVs and GVs are not reported here
1032 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
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 ' ' '`"
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
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"
1042 for c_p in $all_partitions ; do
1043 # Skip fd/cd devices, network FS, cifs
1044 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] || [ "`echo "$c_p" | grep -E "^//"`" != "" ]&& continue
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
1047 current_partition=`readlink -f $c_p`
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
1051 # For SLES 11 type of distro, do not use dm devices as they are unable to be handled by lvm commands
1052 current_partition=`$MINDI_LIB/analyze-my-lvm --givevglvofdm $current_partition`
1053 fi
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=""
1060 label=""
1061 uuid=""
1062 absolute_partition=`readlink -f $c_p`
1063 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | grep -w "$current_partition" | grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1064
1065 # set default in case we dont't find it
1066 str_to_find_fmt_with=$current_partition
1067
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
1070 if [ "`echo "$current_partition" | grep -i "LABEL="`" != "" ]; then
1071 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
1072 actual_dev=""
1073
1074 # 1st try, findfs - the RHEL way of finding labels and their partitions
1075 if [ -x "/sbin/findfs" ]; then
1076 actual_dev=`/sbin/findfs LABEL="${redhat_label}" 2> /dev/null`
1077 fi
1078
1079 # 2nd try : blkid, the good way for all LABEL except swap
1080 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1081 actual_dev=`/sbin/blkid | grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
1082 # For LVM FS it will give a /dev/dm-# which should then be converted
1083 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1084 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1085 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1086 for dev in `ls /dev/mapper/*`; do
1087 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1088 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1089 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1090 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1091 break
1092 fi
1093 done
1094 fi
1095 fi
1096
1097 # 3rd try, which works on a standard partition (ext2/3), but not on swap
1098 # For LVM gives a /dev/mapper entry
1099 if [ "x$actual_dev" = "x" ]; then
1100 actual_dev=`/bin/mount -l | grep "\[$redhat_label\]" | cut -d' ' -f1`
1101 fi
1102
1103 # 4th try, with vol_id
1104 # SWAP only
1105 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1106 list_swaps=`cat /proc/swaps | grep "/dev/" | $AWK '{ print $1 }' `
1107 for dev_swap in $list_swaps ; do
1108 dev_exists=`/sbin/vol_id $dev_swap | grep "$redhat_label"`
1109 if [ "x$dev_exists" != "x" ]; then
1110 actual_dev=$dev_swap
1111 break;
1112 fi
1113 done
1114 fi
1115
1116 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
1117 # LABEL=SW-cciss/c0d0p3 (RDP)
1118 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
1119 # SWAP only
1120 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
1121 skip=""
1122 uname=$KERVERRUN
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
1129 [ "`echo $uname | grep "3.[0-9]*.[0-9]*"`" != "" ] && skip=1052
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
1133 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1134 do
1135 # Location of the swap label for kernel 2.6
1136 try_dev_label=`dd bs=1 count=16 skip=$skip if=$try_dev 2> /dev/null`
1137 if [ "x$try_dev_label" = "x$redhat_label" ]; then
1138 actual_dev=$try_dev
1139 fi
1140 done
1141 fi
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
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"
1148 fi
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
1151 elif [ "`echo "$current_partition" | grep -i "UUID="`" != "" ]; then
1152 uuid=`echo "$current_partition" | cut -d'=' -f2`
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
1160 # 2nd try : blkid, the good way for all UUID except swap
1161 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1162 actual_dev=`/sbin/blkid | grep "$uuid" | grep UUID= | cut -d':' -f1`
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
1165 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1166 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1167 for dev in `ls /dev/mapper/*`; do
1168 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1169 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1170 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1171 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
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
1180 list_dev=`mount | grep -E '^/' | $AWK '{ print $1 }' `
1181 for dev in $list_dev ; do
1182 dev_exists=`/sbin/vol_id $dev | grep "$uuid"`
1183 if [ "x$dev_exists" != "x" ]; then
1184 actual_dev=$dev
1185 break;
1186 fi
1187 done
1188 fi
1189
1190 # 4th try, with dumpuuid (VMWare only ?) for swap
1191 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1192 list_dev=`cat /proc/swaps | grep -E '^/' | $AWK '{ print $1 }' `
1193 for dev in $list_dev ; do
1194 dev_exists=`/sbin/dumpuuid $dev | grep "$uuid"`
1195 if [ "x$dev_exists" != "x" ]; then
1196 actual_dev=$dev
1197 break;
1198 fi
1199 done
1200 fi
1201
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
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."
1207 fi
1208 else
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
1212 # set default in case we dont't find it
1213 for tmpp in `tr -s '\t' ' ' < $MY_FSTAB | grep -Ev "^#" | $AWK '{print $1}'`; do
1214 if [ _"`readlink -f $tmpp`" = _"`readlink -f $current_partition`" ]; then
1215 str_to_find_fmt_with=$tmpp
1216 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | grep -w "$tmpp" | grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1217 break;
1218 fi
1219 done
1220 fi
1221 fi
1222
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
1235 # Look for devices which have to be excluded
1236 skip=0
1237 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
1238 l=""
1239 list_of_devices="`mr-read-all-link $current_partition`"
1240 for d in $list_of_devices; do
1241 l="$l `$MINDI_LIB/analyze-my-lvm --givemapperofdm $d`"
1242 done
1243
1244 # Remove PVs from LVs excluded
1245 l="$l `GetPVsForLV $current_partition`"
1246
1247 # We want a single unique list
1248 list_of_devices="`echo $l | sort -u`"
1249
1250 for d in `echo $MINDI_EXCLUDE_DEVS | sed 's/|/ /g'`; do
1251 if [ "`echo " $list_of_devices " | grep " $d"`" != "" ]; then
1252 LogFile "INFO: Excluding $current_partition from mountlist (due to excluded device $d)"
1253 skip=1
1254 continue
1255 fi
1256 done
1257 fi
1258 if [ $skip -eq 1 ]; then
1259 continue
1260 fi
1261
1262 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1263 # Detects iso9660 ISO images and exclude them
1264 if [ "`echo "$partition_format" | grep -iw iso9660`" != "" ]; then
1265 LogFile "INFO: Excluding $current_partition from mountlist (due to iso9660 format in fstab)"
1266 continue
1267 fi
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
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
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
1280 current_lvolume="$current_partition"
1281 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
1282 # .static dir are a Debian specificity
1283 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
1284 echo $current_lvolume | grep -q ' '
1285 if [ $? -eq 0 ]; then
1286 LogFile "WARNING: Multiple Logical Volumes found. Report to dev team"
1287 fi
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
1293 fi
1294 #
1295 # End of LVM device style variation code (other than $current_lvolume).
1296
1297 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1298 # Size computed via LVM not directly
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
1304 # Skip swap files
1305 [ "`echo "$current_partition" | grep -E "^/dev"`" = "" ] && continue
1306 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition " | $AWK '{print $3}'`
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
1318 LogFile "INFO: I'm guessing $c_p is $(($partition_size/1024))MB"
1319 fi
1320 else
1321 partition_size=`SizeOfPartition $current_partition`
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
1338 LogFile "INFO: Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)"
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
1346 LogFile "WARNING: Are you imaging a mounted swap partition? Silly..."
1347 LogFile "WARNING: Reverting format from $old_partition_fmt to $partition_format"
1348 partition_format=$old_partition_fmt
1349 fi
1350 fi
1351
1352 if [ ! "$partition_mountpt" ] ; then
1353 LogFile "------- $FDISK -l $qq log ------------"
1354 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
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
1358 LogFile "------- $FDISK log end ------------"
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
1362 LogAll "WARNING: Unable to find mountpoint of $current_partition - ignoring"
1363 continue
1364 fi
1365 fi
1366 if [ "$redhat_label" ]; then
1367 label="$redhat_label"
1368 elif [ "$uuid" ]; then
1369 label="$uuid"
1370 fi
1371 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
1372 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
1373 unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
1374 if [ "$current_partition" = "" ] ; then
1375 LogFile "WARNING: Unknown partition (outstring = $unofficial_outstring)"
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
1380 printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1381 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1382 else
1383 LogFile "WARNING: Unknown mountpoint (outstring = $unofficial_outstring)"
1384 fi
1385 elif [ "$partition_format" = "" ] ; then
1386 LogFile "WARNING: Unknown format (outstring = $unofficial_outstring)"
1387 elif [ "$partition_size" = "" ] ; then
1388 LogFile "WARNING: Unknown partition size (outstring = $unofficial_outstring)"
1389 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1390 continue
1391 else
1392 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1393 LogFile "WARNING: vfat should be used instead of dos/msdos as a partition format"
1394 partition_format="vfat"
1395 fi
1396 printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1397 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1398 fi
1399 done
1400 LogAll "-----------------------------------"
1401}
1402
1403CheckMountlist() {
1404 local file=$1
1405 # Coherency verification
1406 ML01=`cat $file | wc -l`
1407 ML02=`grep -vE ' lvm | raid | swap ' $file | wc -l`
1408 ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
1409 ML2=`grep -vE ' lvm | raid | swap ' $file | $AWK '{print $2}' | sort -u | wc -l`
1410 if [ "$ML01" -ne "$ML1" ]; then
1411 LogFile "--------------------------------------------"
1412 LogAll "WARNING: Duplicate device entry in mountlist"
1413 LogFile "--------------------------------------------"
1414 fi
1415 if [ "$ML02" -ne "$ML2" ]; then
1416 LogFile "--------------------------------------------"
1417 LogAll "WARNING: Duplicate mountpoint entry in mountlist"
1418 LogFile "------------------------------------------------"
1419 fi
1420}
1421
1422OfferToMakeBootableISO() {
1423 local i old_pwd
1424 if [ -z "$ISO_CMD" ]; then
1425 LogAll "ERROR: Neither mkisofs nor genisoimage found, unable to make CD image"
1426 return
1427 fi
1428 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1429 echo -en "Shall I make a bootable CD image? (y/[n]) "
1430 read i
1431 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1432 fi
1433 rm -Rf $MINDI_TMP/iso
1434 mkdir -p $MINDI_TMP/iso/{images,archives}
1435 LogFile "INFO: mindi_lib = $MINDI_LIB"
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"
1437 for i in memdisk memtest.bin memtest.img ; do
1438 j=$MINDI_LIB/$i
1439 k=$MINDI_TMP/iso
1440 if [ -e "$j" ] ; then
1441 LogAll "INFO: Copying $j to $k"
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"
1444 if [ _"$MONDO_SHARE" != _"" ]; then
1445 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1446 fi
1447 fi
1448 done
1449 MakeMessageFile $MINDI_TMP/iso | cut -c1-80 > $MINDI_TMP/iso/message.txt
1450 if [ $KERNEL_IS_XEN = "yes" ]; then
1451 FindMboot32Binary
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
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
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?"
1462
1463 if [ _"$MONDO_SHARE" != _"" ]; then
1464 if [ $KERNEL_IS_XEN = "yes" ]; then
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?"
1467 fi
1468 if [ -e $LDLINUXC32 ]; then
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?"
1470 fi
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?"
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?"
1473 fi
1474 MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
1475 if [ "$ARCH" != "ia64" ] ; then
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?"
1477 fi
1478 old_pwd=`pwd`
1479 cd "$MINDI_TMP/iso"
1480 if [ "$ARCH" != "ia64" ] ; then
1481 if [ _"$MONDO_SHARE" != _"" ]; then
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?"
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
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?"
1488 fi
1489 cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
1490 fi
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
1492 else
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
1494 fi
1495 if [ "$?" -ne "0" ] ; then
1496 LogFile "----------- $ISO_CMD's errors --------------"
1497 LogAll "$ISO_CMD returned the following errors:"
1498 cat $MINDI_TMP/mkisofs.log | tee -a $LOGFILE
1499 LogAll "ERROR: Failed to create ISO image."
1500 else
1501 LogAll "INFO: Created bootable ISO image at $MINDI_CACHE/mindi.iso"
1502 fi
1503 rm -f $MINDI_TMP/mkisofs.log
1504 cd "$old_pwd"
1505}
1506
1507
1508OfferToMakeBootableUSB() {
1509 local i
1510 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1511 echo -n "Shall I make a bootable USB device ? (y/[n]) "
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
1518 fi
1519 echo "WARNING: This will erase all content on $USBDEVICE"
1520 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1521 read i
1522 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
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 "."
1530 LogFile "INFO: Transforming $USBDEVICE in a Bootable device"
1531 LogFile "INFO: Checking $USBDEVICE"
1532 $FDISK -l $USBDEVICE 2>&1 >> $LOGFILE
1533 if [ $? -ne 0 ]; then
1534 LogAll "ERROR: Unable to access $USBDEVICE"
1535 LogAll " Make sure your USB device is plugged in"
1536 MindiExit -1
1537 fi
1538 echo -en "."
1539 # Some distro do auto mount at that point (Ubuntu)
1540 LogFile "INFO: Unmounting $USBPART just in case"
1541 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
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
1544 if [ -r $MBRFILE ]; then
1545 LogAll "INFO: Installing an MBR ($MBRFILE) on $USBDEVICE"
1546 dd if=$MBRFILE of=$USBDEVICE
1547 else
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"
1550 fi
1551 LogFile "INFO: Preparing $USBDEVICE"
1552 cat > $MINDI_TMP/fdisk.txt << EOF
1553d
1554d
1555d
1556d
1557n
1558p
15591
1560
1561
1562t
1563b
1564a
15651
1566w
1567EOF
1568 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE < $MINDI_TMP/fdisk.txt
1569 if [ $? -ne 0 ]; then
1570 LogAll "ERROR: Unable to create a vfat Filesystem on $USBDEVICE"
1571 LogAll " Make sure your USB device is plugged in"
1572 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1573 MindiExit -1
1574 fi
1575 LogFile "fdisk build file"
1576 LogFile "----------------"
1577 cat $MINDI_TMP/fdisk.txt >> $LOGFILE
1578 LogFile "----------------"
1579 rm -f $MINDI_TMP/fdisk.txt
1580 LogFile "INFO: The USB device $USBDEVICE now looks like this:"
1581 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1582 echo -en "."
1583 # Calling kpartx in case devices were not created
1584 if [ -x "/sbin/kpartx" ]; then
1585 /sbin/kpartx -a $USBDEVICE
1586 fi
1587 # Some distro do auto mount at that point (Ubuntu)
1588 LogFile "INFO: Unmounting $USBPART just in case again"
1589 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1590 echo -en "."
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 "."
1601 LogFile "INFO: Creating a vfat filesystem on $USBPART"
1602 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
1603 if [ $? -ne 0 ]; then
1604 LogAll "ERROR: Unable to create a vfat filesystem on $USBPART"
1605 LogAll " Make sure your USB device is plugged in and partitioned ($USBPART must exist on it)"
1606 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1607 MindiExit -1
1608 fi
1609 echo -en "."
1610 LogFile "INFO: Mounting $USBPART on $MINDI_TMP/usb"
1611 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1612 if [ $? -ne 0 ]; then
1613 LogAll "ERROR: Unable to mount $USBPART on $MINDI_TMP/usb"
1614 LogAll " Make sure your USB device is plugged in, partitioned and formated ($USBPART must exist on it)"
1615 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1616 MindiExit -1
1617 fi
1618 echo -en "."
1619 mkdir -p $MINDI_TMP/usb/images
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"
1621 echo -en "."
1622 LogFile "INFO: mindi_lib = $MINDI_LIB"
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
1627 LogIt "INFO: Copying $j to $k"
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"
1630 fi
1631 done
1632 echo -en "."
1633 MakeMessageFile $MINDI_TMP/usb | cut -c1-80 > $MINDI_TMP/usb/message.txt
1634 echo -en "."
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?"
1636 echo -en "."
1637 cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1638 echo -en "."
1639 MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
1640 echo -en "."
1641 LogAll "----------- syslinux's conf --------------"
1642 cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
1643 LogAll "------------------------------------------"
1644 umount $MINDI_TMP/usb
1645 if [ "$ARCH" != "ia64" ] ; then
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
1656 LogAll "----------- syslinux's errors --------------"
1657 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1658 LogAll "------------------------------------------"
1659 LogIt "ERROR: Failed to create USB image."
1660 else
1661 echo -e "$DONE"
1662 LogFile "INFO: Created bootable USB image on $USBDEVICE"
1663 fi
1664 rm -f $MINDI_TMP/syslinux.log
1665 else
1666 LogAll "ERROR: No USB boot support for ia64"
1667 MindiExit -1
1668 fi
1669}
1670
1671
1672MakeMessageFile() {
1673
1674 if [ -x "/bin/lsb_release" ]; then
1675 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
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)]"
1682 fi
1683 elif [ -r /etc/issue.net ]; then
1684 DESC=`head -1 /etc/issue.net`
1685 elif [ -r /etc/issue ]; then
1686 DESC=`head -1 /etc/issue`
1687 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1688 # For pb >= 0.9.8
1689 DESC=`/usr/bin/pbdistrocheck -s | cut -d, -f1-4`
1690 else
1691 DESC="Unknown desc"
1692 fi
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/"
1694 if [ _"$MONDO_SHARE" != _"" ]; then
1695 if [ "$CDRECOVERY" != "yes" ] ; then
1696 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
1697 echo -en "Press <0eenter07> for 0cnetwork restore07\n"
1698 echo -en "$BOOT_MEDIA_MESSAGE"
1699 elif [ ! "$MINDI_TMP" ] ; then
1700 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
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
1704 else
1705 echo -en "$BOOT_MEDIA_MESSAGE"
1706 fi
1707 else
1708 echo -en "\
1709To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1710CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1711 fi
1712 fi
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
1718}
1719
1720
1721MakeBootConfFile() {
1722 local options i ooo
1723 options=""
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
1731
1732 # Generic header for conf file
1733 if [ "$type" != "elilo" ] ; then
1734 echo -en "prompt 1\ndisplay message.txt\nF1 message.txt\nF2 boot1.txt\nF3 boot2.txt\nF4 pxe.txt\n"
1735 else
1736 echo -en "prompt\n"
1737 fi
1738
1739 # Compute which default option to boot from
1740 if [ "$CDRECOVERY" = "yes" ] ; then
1741 echo -en "default${sep}RESTORE\n"
1742 # In case it's mondoarchive
1743 elif [ _"$MONDO_SHARE" != _"" ]; then
1744 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
1745 echo -en "default${sep}iso\n"
1746 else
1747 echo -en "default${sep}${MINDI_DEFAULT_BOOT_OPTION}\n"
1748 fi
1749 else
1750 echo -en "default${sep}expert\n"
1751 fi
1752
1753 # Handle timeout
1754 if [ "$CDRECOVERY" != "yes" ] ; then
1755 echo -en "timeout${sep}${MINDI_BOOT_TIMEOUT}\n"
1756 else
1757 echo -en "timeout${sep}10000\n"
1758 fi
1759 echo -en "\n"
1760
1761 # prepare which labels will be generated
1762 if [ "$CDRECOVERY" = "yes" ] ; then
1763 options="RESTORE expert"
1764 else
1765 if [ _"$MONDO_SHARE" != _"" ]; then
1766 options="interactive expert compare iso nuke isonuke"
1767 else
1768 options="expert"
1769 fi
1770 fi
1771
1772 # Generate rest of conf file
1773 for i in $options ; do
1774 ooo=$i
1775 [ "$ooo" = "RESTORE" ] && ooo="RESTORE nuke"
1776 if [ "$type" = "elilo" ]; then
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"
1778 else
1779 ps="/"
1780 if [ "$type" = "syslinux" ]; then
1781 ps=""
1782 fi
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
1788 fi
1789 echo -en "$outstr"
1790 done
1791 if [ -e "$MINDI_LIB/memtest.img" ] ; then
1792 if [ "$type" = "elilo" ]; then
1793 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
1794 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
1795 else
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"
1802 fi
1803 fi
1804}
1805
1806
1807PrepareBootDiskImage_LILO() {
1808 local imagesdir dev imagefile fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
1809 imagesdir=$MINDI_CACHE
1810 kernelpath=$1
1811
1812 retval=0
1813
1814 old_pwd=`pwd`
1815 [ ! -e "$kernelpath" ] && Die "PBDI lilo - cannot find $kernelpath kernel"
1816 echo -en "Making "$BOOT_SIZE"KB boot disk..."
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?"
1818 echo -en "..."
1819 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1820 mkdir -p $mountpoint
1821 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1822 LogFile "Creating vfat filesystem on $imagefile"
1823 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1824 mount -t vfat -o loop $imagefile $mountpoint || LogAll "ERROR: Cannot mount (PBDI)"
1825
1826 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1827 mkdir -p $mountpoint/etc
1828 liloconf=$mountpoint/elilo.conf
1829
1830 MakeBootConfFile elilo > $liloconf
1831
1832 # Copy it so that CD-ROM menu entry is satisfied
1833 mountefi=0
1834 df -T | grep /boot/efi | grep -q vfat
1835 if [ $? -ne 0 ]; then
1836 mount /boot/efi
1837 if [ $? -ne 0 ]; then
1838 echo "You have to mount your EFI partition when using mindi"
1839 MindiExit -1
1840 fi
1841 mountefi=1
1842 fi
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
1849
1850 LogFile "INFO: Copying $MINDI_TMP/initrd.img to $mountpoint..."
1851 cp -f $MINDI_TMP/initrd.img $mountpoint 2>> $LOGFILE
1852 if [ "$?" -ne "0" ] ; then
1853 LogIt "ERROR: Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1854 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1855 LogIt " Please unload some of your modules and try again. Or increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
1856 rm -f $MINDI_TMP/mtpt.$$
1857 LogIt "ERROR: Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1858 retval=$(($retval+1))
1859 fi
1860 MakeMessageFile $mountpoint | cut -c1-80 > $mountpoint/message.txt
1861
1862 mkdir -p $mountpoint/tmp
1863 if [ -f "$MINDI_TMP/$MRCFG" ]; then
1864 cp -f $MINDI_TMP/$MRCFG $mountpoint/tmp
1865 fi
1866
1867 # copy the kernel across
1868 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1869 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1870 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1871 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2>> $LOGFILE
1872 if [ "$?" -ne "0" ] ; then
1873 LogFile "INFO: Files at mountpoint ($mountpoint) :"
1874 du -sk $mountpoint/* >> $LOGFILE
1875 LogFile "--- end of list of files ---"
1876 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n" >> $LOGFILE
1877 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1878 cd "$old_pwd"
1879 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1880 rmdir $mountpoint || LogIt "ERROR: Cannot rmdir (PBDI)"
1881 # losetup /dev/loop0 -d
1882 [ "$imagefile" != "" ] && rm -f $imagefile
1883 LogIt "ERROR: Sorry, your kernel is too big for your image"
1884 Die "Try to increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
1885 return 0
1886 fi
1887 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
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"
1890 # make it bootable
1891 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1892 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
1893 if [ "$KERN_DISK_MADE" ] ; then
1894 LogFile "INFO: Not running LILO. It's not that kind of disk."
1895 fi
1896
1897 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1898 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1899 echo -en "..."
1900 rmdir $mountpoint || LogIt "ERROR: Cannot rmdir (PBDI)"
1901 if [ "$retval" -eq "0" ] ; then
1902 echo -en "...$DONE\n"
1903 if [ "$KERN_DISK_MADE" ] ; then
1904 LogIt "INFO: $BOOT_SIZE KB boot disks were created OK\n"
1905 fi
1906 else
1907 echo -en "...failed\n"
1908 LogIt "WARNING: $BOOT_SIZE""KB boot disk was NOT created\n"
1909 [ "$imagefile" != "" ] && rm -f $imagefile
1910 fi
1911 [ "$retval" -ne "0" ] && LogIt "WARNING: PrepareBootDiskImage() is returning nonzero"
1912 return $retval
1913}
1914
1915
1916PrepareBootDiskImage_ISOLINUX() {
1917 local imagesdir dev imagefile fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage retval
1918 imagesdir=$MINDI_CACHE
1919 kernelpath=$1
1920 do_boot_root_thingy=""
1921 retval=0
1922
1923 old_pwd=`pwd`
1924 [ ! -e "$kernelpath" ] && Die "PBDI isolinux - cannot find $kernelpath kernel"
1925 echo -en "Making "$BOOT_SIZE"KB boot disk..."
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?"
1927 echo -en "..."
1928 imagefile=$MINDI_TMP/mindi-bootroot.$BOOT_SIZE.img
1929 mkdir -p $mountpoint
1930 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1931 LogFile "INFO: Creating vfat filesystem on $imagefile"
1932 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
1933 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1934 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1935
1936 # Only move it now to its final destination and use it now
1937 mv $imagefile $imagesdir
1938 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1939
1940 mount -t vfat -o loop $imagefile $mountpoint || LogIt "ERROR: Cannot mount (PBDI)"
1941
1942 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1943 MakeMessageFile $mountpoint | cut -c1-80 > $mountpoint/message.txt
1944 MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1945 LogFile "INFO: Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
1946 cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
1947 if [ "$?" -ne "0" ] ; then
1948 LogAll "ERROR: Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1949 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1950 LogAll " Please unload some of your modules and try again."
1951 rm -f $MINDI_TMP/mtpt.$$
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"
1954 retval=$(($retval+1))
1955 fi
1956
1957 mkdir -p $mountpoint/tmp
1958 if [ -f "$MINDI_TMP/$MRCFG" ]; then
1959 cp -f $MINDI_TMP/$MRCFG $mountpoint/tmp
1960 fi
1961
1962 # copy the kernel across
1963 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1964 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1965 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1966
1967 retval=0
1968 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
1969 retval=$?
1970 if [ $KERNEL_IS_XEN = "yes" ]; then
1971 cp -f $xenkernelpath $mountpoint/xenkernel &> /dev/null
1972 let retval+=$?
1973 fi
1974
1975 if [ "$retval" -ne "0" ] ; then
1976 LogFile "INFO: Files at mountpoint ($mountpoint) :"
1977 du -sk $mountpoint/* >> $LOGFILE
1978 LogFile "--- end of list of files ---"
1979 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n" >> $LOGFILE
1980 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1981 cd "$old_pwd"
1982 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1983 rmdir $mountpoint || LogAll "ERROR: Cannot rmdir (PBDI)"
1984
1985 LogIt "ERROR: Sorry, your kernel is too big for your image"
1986 Die "Try to increase EXTRA_SPACE and BOOT_SIZE in $MINDI_CONFIG"
1987 fi
1988 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
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"
1991
1992 # make it bootable
1993 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1994 mkdir -p $mountpoint/etc
1995 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
1996 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1997 echo -en "..."
1998 rmdir $mountpoint || LogAll "ERROR: Cannot rmdir (PBDI)"
1999
2000 if [ "$retval" -eq "0" ] ; then
2001 echo -en "...$DONE\n"
2002 if [ "$KERN_DISK_MADE" ] ; then
2003 [ "$imagefile" != "" ] && rm -f $imagefile
2004 LogAll "INFO: $BOOT_SIZE KB boot disks were created OK\n"
2005 fi
2006 else
2007 echo -en "...failed\n"
2008 LogAll "WARNING: $BOOT_SIZE""KB boot disk was NOT created\n"
2009 [ "$imagefile" != "" ] && rm -f $imagefile
2010 fi
2011 [ "$retval" -ne "0" ] && LogAll "ERROR: PrepareBootDiskImage() is returning nonzero"
2012 return $retval
2013}
2014
2015
2016ParseModprobeForIncludes() {
2017local MODPROBE_CONF mpincfile includes include
2018
2019MODPROBE_CONF=/etc/modprobe.conf
2020mpincfile=$1
2021touch $mpincfile
2022if [ -a $MODPROBE_CONF ]; then
2023 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
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
2036PrepareDataDiskImages() {
2037 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
2038
2039 imagesdir=$MINDI_CACHE
2040 rm -f $imagesdir/mindi.iso
2041 needlist=$MINDI_TMP/what-we-need.txt
2042 bigdir=$MINDI_TMP/bigdir
2043 mkdir -p $bigdir/usr/bin
2044 mkdir -p $bigdir/usr/sbin
2045 includefile=$MINDI_TMP/$$.includefile.txt
2046
2047 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
2048 if [ -e "$DEPLIST_FILE" ]; then
2049 lfiles="$DEPLIST_FILE $lfiles"
2050 fi
2051 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
2052 ParseModprobeForIncludes $includefile
2053 lines=$(($lines+`cat $includefile | wc -l`))
2054 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
2055 res=$?
2056 rm -f $includefile
2057 ListKernelModulePaths >> $needlist
2058 if [ "$res" -ne "0" ] ; then
2059 Die "You have $res files present in dependency list\nbut absent from filesystem."
2060 fi
2061 mkdir -p $bigdir/tmp
2062 if [ _"$MONDO_SHARE" != _"" ]; then
2063 # BCO: no reason to have the cfg file stored twice
2064 MakeMondoConfigFile $MINDI_TMP/$MRCFG
2065 cp -f $MINDI_TMP/$MRCFG $bigdir/tmp &> /dev/null
2066 fi
2067
2068 # Needs to be done after the MRCFG creation
2069 FindAndAddUserKeyboardMappingFile
2070
2071 [ -d "/mnt/.boot.d" ] && echo "GENTOO" > $bigdir/tmp/DUMBASS-GENTOO
2072 DropOptimizedLibraries $needlist $bigdir
2073 echo -en "Assembling dependency files"
2074
2075 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
2076
2077 # also copy io.sys and msdos.sys, if we can find them
2078 for i in `mount | cut -d' ' -f3` ; do
2079 for j in io.sys msdos.sys ; do
2080 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
2081 done
2082 done
2083
2084 # master boot record, too
2085 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
2086 if [ "$i" ] ; then
2087 LogAll "INFO: Backing up $i's MBR"
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`
2093 LogAll "INFO: Creating /dev/boot_device ($j)"
2094 mkdir -p $bigdir/dev
2095 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
2096 fi
2097
2098 old_pwd=`pwd`
2099 cd "$bigdir"
2100
2101 # Get terminfo content
2102 ti="usr/share/terminfo/l"
2103 if [ -d /$ti ]; then
2104 mkdir -p $ti
2105 cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "ERROR: issue copying terminfo"
2106 fi
2107 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
2108 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
2109 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
2110 fi
2111 if [ -d "/lib/dev-state" ]; then
2112 cp -a /lib/dev-state ./lib/ 2>> $MINDI_TMP/$$.log || LogAll "ERROR: Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
2113 fi
2114 cd "$old_pwd"
2115 echo -e "$DONE"
2116 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
2117 MakeMountlist $MINDI_TMP/mountlist.txt
2118 CheckMountlist $MINDI_TMP/mountlist.txt
2119 mkdir -p $bigdir/tmp
2120 cp -f $MINDI_TMP/mountlist.txt $bigdir/tmp/mountlist.txt 2>> $LOGFILE || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk"
2121 if [ _"$MONDO_SHARE" != _"" ]; then
2122 cp -f $bigdir/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2123 fi
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
2129 else
2130 LogFile "Your i-want-my-lvm file content is:"
2131 LogFile "-----------------------------------"
2132 cat $bigdir/tmp/i-want-my-lvm >> $LOGFILE
2133 LogFile "-----------------------------------"
2134 fi
2135 fi
2136 LogFile "Your mountlist.txt file content is:"
2137 LogFile "-----------------------------------"
2138 cat $bigdir/tmp/mountlist.txt >> $LOGFILE
2139 LogFile "-----------------------------------"
2140
2141 echo -en "$FILES_IN_FILELIST" > $bigdir/FILES-IN-FILELIST 2>> $LOGFILE
2142 echo -en "$LAST_FILELIST_NUMBER" > $bigdir/LAST-FILELIST-NUMBER 2>> $LOGFILE
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`
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 "------------------------"
2155 du -sk $imagesdir/*gz >> $LOGFILE
2156 LogFile "------------------------"
2157 echo -e "$DONE"
2158
2159 FRIENDLY_OUTSTRING="Boot and data disk images were created."
2160 rm -rf $bigdir
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
2176 i=$(($i+1))
2177 read incoming
2178 done
2179 echo "$incoming"
2180}
2181
2182
2183SizeOfPartition() {
2184 local devpath drive res stub
2185 device=$1
2186 if [ "`echo "$device" | grep -E "^/dev/"`" = "" ] ; then
2187 Die "Cannot find $device's size - is your /etc/fstab sane?"
2188 fi
2189 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
2190 res=`SizeOfRaidPartition $device`
2191 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2192 echo "$res"
2193 return 0
2194 fi
2195 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2196 res=`$FDISK -s $device 2>> $LOGFILE`
2197 # end patch
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`
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
2213 tmp=`SizeOfPartition $real_dev`
2214 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2215 done
2216
2217 if [ "$smallest_size" = "$silly" ] ; then
2218 echo "-1"
2219 return 1
2220 else
2221 echo "$smallest_size"
2222 return 0
2223 fi
2224}
2225
2226
2227StripExecutable()
2228{
2229 local tmpfile
2230
2231 tmpfile=$MINDI_TMP/stripped.$$.dat
2232 [ -d "$1" ] || [ -h "$1" ] && return
2233 cp -f $1 $tmpfile 2>> $LOGFILE
2234 strip $tmpfile 2> /dev/null
2235 if [ "$?" -eq "0" ] ; then
2236 cp -f $tmpfile $1 2>> $LOGFILE
2237 LogFile "INFO: Stripped binary $2"
2238 fi
2239 rm -f $tmpfile
2240}
2241
2242KernelVer() {
2243 local fkern_ver fname
2244
2245 fname=$1
2246 file $fname | grep -q gzip
2247 if [ "$?" -eq "0" ] ; then
2248 # Used by ia64
2249 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep -E "[2-9]+\.[0-9]+\.[0-9]+[^\@]*@"`
2250 else
2251 fkern_ver=`strings $fname 2> /dev/null | grep -E "[2-9]+\.[0-9]+\.[0-9]+[^\@]*@"`
2252 fi
2253 echo "$fkern_ver"
2254}
2255
2256
2257# WARNING: This function should just echo the final result !!!
2258#
2259TryToFindKernelPath() {
2260 local fname fkern_ver we_want_version possible_kernels noof_kernels possible_xenkernels noof_xenkernels kp kdate duff_kernels output root
2261
2262 we_want_version=$KERVERRUN
2263 possible_kernels=""
2264 duff_kernels=""
2265 output=""
2266
2267 if [ "$ARCH" = "ia64" ] ; then
2268 root="/boot/efi/efi"
2269 else
2270 root="/"
2271 fi
2272 # See if we're booted from a Xen kernel
2273 # From http://wiki.xensource.com/xenwiki/XenCommonProblems#head-26434581604cc8357d9762aaaf040e8d87b37752
2274 if [ -f /proc/xen/capabilities ]; then
2275 # It's a Xen kernel
2276 KERNEL_IS_XEN="yes"
2277 LogFile "INFO: It's a Xen kernel..."
2278 fi
2279
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
2281 [ ! -e "$fname" ] && continue
2282 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2283 fkern_ver=`KernelVer $fname`
2284 [ "$fkern_ver" = "" ] && continue
2285 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
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
2293 LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2294 duff_kernels="$fname $duff_kernels"
2295 else
2296 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2297 possible_kernels="$fname $possible_kernels"
2298 fi
2299 else
2300 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2301 LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2302 duff_kernels="$fname $duff_kernels"
2303 else
2304 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2305 possible_kernels="$fname $possible_kernels"
2306 fi
2307 fi
2308 done
2309 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2310 possible_kernels=`find /boot/vmlinuz-[23].* | tail -n1`
2311 fi
2312 if [ ! "$possible_kernels" ] ; then
2313 LogAll "INFO: No kernel matches exactly. Are there any duff kernels?"
2314 possible_kernels="$duff_kernels"
2315 if [ ! "$possible_kernels" ] ; then
2316 LogAll "INFO: Sorry, no duff kernels either"
2317 else
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..."
2320 fi
2321 fi
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
2326 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -vi "xen" | sort -u | tr '\n' ' '`
2327 noof_kernels=`CountItemsIn "$possible_kernels"`
2328 if [ "$noof_kernels" -eq "0" ] ; then
2329 LogAll "Could not find your kernel."
2330 if [ -e "/boot/vmlinuz" ] ; then
2331 LogAll "INFO: Using /boot/vmlinuz as a last resort."
2332 output=/boot/vmlinuz
2333 else
2334 output=""
2335 fi
2336 elif [ "$noof_kernels" -eq "1" ] ; then
2337 kp=`echo "$possible_kernels" | sed s/' '//`
2338 LogFile "INFO: Your kernel is $kp (v$KERVERRUN)"
2339 output="$kp"
2340 else
2341 for i in $possible_kernels ; do
2342 if [ "`echo $i | grep "$KERVERRUN"`" ]; then
2343 LogAll "INFO: OK, I used my initiative and found that "
2344 LogAll "INFO: $i is probably your kernel. "
2345 output="$i"
2346 break
2347 fi
2348 done
2349 if [ ! -n "$output" ]; then
2350 if [ "`echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null`" ]; then
2351 output=/boot/vmlinuz
2352 LogFile "INFO: Schlomo, this one's for you."
2353 else
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"
2357 output=""
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/' '//`
2366 LogFile "INFO: Your Xen kernel is $xenkernelpath (v$KERVERRUN)"
2367 else
2368 for i in $possible_xenkernels ; do
2369 if [ "`echo $i | grep "$KERVERRUN"`" ]; then
2370 LogFile "INFO: OK, I used my initiative and found that "
2371 LogFile "INFO: $i is probably your Xen kernel. "
2372 xenkernelpath="$i"
2373 break
2374 fi
2375 done
2376 if [ ! -n "$xenkernelpath" ]; then
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`
2380 LogFile "INFO: Using $xenkernelpath"
2381 else
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"
2385 output=""
2386 xenkernelpath=`echo $possible_xenkernels | tr -s ' ' '\n' | head -1`
2387 LogFile "INFO: Using $xenkernelpath"
2388 fi
2389 fi
2390 fi
2391 if [[ -z "$xenkernelpath" || ! -f "$xenkernelpath" ]]; then
2392 Die "Cannot find Xen kernel $xenkernelpath, aborting"
2393 fi
2394 fi
2395 LogAll "TryToFindKernelPath found $output"
2396 echo "$output"
2397}
2398
2399
2400TurnTgzIntoRdz() {
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
2402
2403 tgz_dir_fname=$1
2404 rdz_fname=$2
2405 kernelsize=$3
2406 maxsize=$(($BOOT_SIZE-$kernelsize))
2407 maxsize=$(($maxsize*2)); # to allow for compression of 50%
2408 tempfile=$MINDI_TMP/temp.rd
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 "..."
2413 LogFile "INFO: Creating ext2 filesystem on $tempfile"
2414 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
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`
2420 cd "$mountpoint"
2421
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
2439
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
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
2450
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
2457 s=`which $w 2> /dev/null`
2458 if [ -e "$s" ] ; then
2459 tar cf - -C / $s 2> /dev/null | tar xf -
2460 fi
2461 done
2462
2463 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
2464
2465 # Copy of files mandatory for ssh to automate mount if sshfs is used
2466 mkdir $mountpoint/.ssh $mountpoint/tmp
2467 cp -a ~root/.ssh/* $mountpoint/.ssh 2> /dev/null
2468 cat > $mountpoint/tmp/myssh << EOF
2469ssh -o StrictHostKeyChecking=no $*
2470EOF
2471 chmod 755 $mountpoint/tmp/myssh
2472
2473 # Copy of files mandatory for ld.so
2474 cp -a /etc/ld.so.c* $mountpoint/etc
2475
2476 # Handle the case where busybox and mount are dynamically linked
2477 file $MINDI_LIB/rootfs/usr/bin/busybox 2>&1 | grep -q "dynamically"
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
2483 # Copy of files from the minimal env needed as per the deplist.d/minimal.conf & udev.conf file (which includes all busybox deps)
2484 rm -f $MINDI_TMP/minimal.lis $MINDI_TMP/minimal2.lis
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
2496 fi
2497 done
2498 for f in `cat $MINDI_TMP/minimal.lis` `sort -u $MINDI_TMP/minimal2.lis`; do
2499 mr-read-all-link $f >> $MINDI_TMP/minimal.lis
2500 done
2501 # Initial / are trucated by tar
2502 finallist=""
2503 # Remove directories from the list, as tar/cp will create them anyway
2504 # and it may hurt if /lib is in it as on Debian/Ubuntu
2505 # recent bash says that -d is true for a link to a dir !
2506 for f in `sort -u $MINDI_TMP/minimal.lis`; do
2507 if [ -e $f -a ! -d $f ] || [ -h $f ]; then
2508 finallist="$finallist $f"
2509 fi
2510 done
2511 #tar cf - $finallist 2>> $MINDI_TMP/$$.log | tar xf - || LogIt "WARNING: Problem in minimal analysis" $MINDI_TMP/$$.log
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
2514
2515 # To improve support for distribution scripts, we now prefer to use bash as the std shell. Also fixes #600
2516 ln -sf /bin/bash bin/sh
2517 LogIt "INFO: Using bash as default shell"
2518 rm -f $MINDI_TMP/minimal.lis $MINDI_TMP/minimal2.lis
2519
2520 # Avoids an issue on some distro (RHEL5)
2521 rm -f $mountpoint/etc/ld.so.conf.d/kernelcap*
2522
2523 mkdir -p $mountpoint/tmp
2524 # Management of udev (which includes modprobe in rules)
2525 ps auxww | grep -v grep | grep -qw udevd
2526 if [ $? -eq 0 ]; then
2527 echo "udev device manager found" > $mountpoint/tmp/USE-UDEV
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
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
2532 # Do not do it if it's a link (Ubuntu 64 bits #503)
2533 if [ -e "/lib64/udev" ] && [ ! -h "/lib64" ] && [ ! -h "/lib64/udev" ]; then
2534 tar cf - -C / /lib64/udev 2>> $MINDI_TMP/$$.log | tar xf - || LogIt "ERROR: Problem in /lib64/udev analysis" $MINDI_TMP/$$.log
2535 fi
2536 if [ -e "/lib32/udev" ] && [ ! -h "/lib32" ] && [ ! -h "/lib32/udev" ]; then
2537 tar cf - -C / /lib32/udev 2>> $MINDI_TMP/$$.log | tar xf - || LogIt "ERROR: Problem in /lib32/udev analysis" $MINDI_TMP/$$.log
2538 fi
2539 if [ -e "/lib/udev" ] && [ ! -h "/lib" ] && [ ! -h "/lib/udev" ]; then
2540 tar cf - -C / /lib/udev 2>> $MINDI_TMP/$$.log | tar xf - || LogIt "ERROR: Problem in /lib/udev analysis" $MINDI_TMP/$$.log
2541 fi
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
2545 if [ -x /sbin/udevd ] || [ -x /usr/bin/udevd ] || [ -x /usr/lib/systemd/systemd-udevd ]; then
2546 lis2=`grep -Ev '^#' $DEPLIST_DIR/udev.conf`
2547 lis=""
2548 # Get only the files which exist in that list
2549 # and potentially their symlink structure
2550 for i in $lis2; do
2551 if [ -h $i ]; then
2552 j=$i
2553 while [ -h $j ]; do
2554 lis="$lis $j"
2555 j=`readlink -f $j`
2556 done
2557 lis="$lis $j"
2558 elif [ -f $i ]; then
2559 lis="$lis $i"
2560 fi
2561 done
2562 # And their deps
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-`
2567 [ "$j" != "" ] && rm -f $j
2568 fi
2569 echo "$i" >> $MINDI_TMP/udev.lis
2570 done
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
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
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
2583 rm -f $MINDI_TMP/udev.lis
2584 else
2585 LogAll "WARNING: udevd daemon not in standard place (/sbin or /usr/bin)"
2586 LogAll " mindi will use static devices which may cause problems"
2587 rm -f $mountpoint/tmp/USE-UDEV
2588 fi
2589 fi
2590
2591 # Management of potential HW info (ProLiant only at the moment)
2592 rm -rf $MINDI_CACHE/bkphw
2593 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2594 if [ -d $MINDI_CACHE/bkphw ]; then
2595 LogIt "INFO: Hardware Information found and saved ..."
2596 cp -rp $MINDI_CACHE/bkphw .
2597 if [ -f $MINDI_CACHE/tools.files ]; then
2598 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2599 LocateDeps $lis > $MINDI_TMP/tools.lis
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
2601 fi
2602 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2603 mv -f $MINDI_CACHE/mindi-rsthw .
2604 chmod 755 ./mindi-rsthw
2605 fi
2606 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2607 fi
2608
2609 # Management of perl scripts delivered needed at restore time
2610 mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` /usr/bin/mr-* > $MINDI_TMP/perl.lis
2611 tar cf - `cat $MINDI_TMP/perl.lis` 2>> $MINDI_TMP/$$.log | tar xf - || LogIt "ERROR: Problem in perl scripts analysis" $MINDI_TMP/$$.log
2612
2613 for w in cdrom groovy-stuff ; do
2614 mkdir -p mnt/$w
2615 done
2616
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
2618
2619 echo -en "..."
2620 cd /
2621
2622 needed_modules=""
2623 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
2624
2625 if [ -e "$MINDI_TMP/NETFS-SERVER-MOUNT" ] ; then
2626 # For PXE boot
2627 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2628 fi
2629 for i in $DENY_MODS; do
2630 LogFile "INFO: Removing $i from the list of modules to load"
2631 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2632 done
2633
2634 if [ "${kernelname}" != "" ]; then
2635 needed_modules_path=lib/modules/${kernelname}
2636 mkgmopt="-k ${kernelname}"
2637 else
2638 needed_modules_path=lib/modules/$KERVERRUN
2639 mkgmopt="-k $KERVERRUN"
2640 fi
2641
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
2645 LogFile "INFO: Adding $needed_modules to the rootfs with $mkgmopt"
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
2652 gunzip -f $mountpoint/$i
2653 fi
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
2663
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
2666
2667 # Copy FW in case some drivers needs it
2668 for d in "/lib" "/usr/lib"; do
2669 if [ -d "$d/firmware" -a ! -h $d ]; then
2670 cp -a "$d/firmware" "$mountpoint/$d"
2671 fi
2672 done
2673
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
2676 if [ -d "$d/multipath" -a ! -h $d ]; then
2677 cp -a "$d/multipath" "$mountpoint/$d"
2678 fi
2679 done
2680
2681 # Copy an additional ProLiant tool for OBDR support
2682 if [ -f $MINDI_TMP/OBDR ]; then
2683 found=0
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
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
2692 lis="/usr/bin/sg_map /usr/bin/sg_inq /usr/bin/sg_reset /usr/bin/rev"
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"
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"
2700 LogAll " This may lead to a tape not going back to sequential mode after OBDR boot"
2701 fi
2702 fi
2703
2704 if [ ! -e "/sbin/devfsd" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
2705 LogFile "INFO: Deleting devfsd daemon from ramdisk"
2706 [ ! -e "/sbin/devfsd" ] && LogFile " ...because /sbin/devfsd not found"
2707 rm -f $mountpoint/sbin/devfsd
2708 fi
2709 cd "$old_pwd"
2710 [ "$TAPEDEV" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
2711 if [ _"$MONDO_SHARE" != _"" ]; then
2712 MakeMondoConfigFile $mountpoint/tmp/$MRCFG
2713 cp -f $mountpoint/tmp/$MRCFG $MINDI_TMP 2>> $LOGFILE || Die "Cannot copy $MRCFG to ramdisk"
2714 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>> $LOGFILE || Die "Cannot copy mountlist to ramdisk"
2715 echo -en "$FILES_IN_FILELIST" > $mountpoint/tmp/FILES-IN-FILELIST
2716 echo -en "$LAST_FILELIST_NUMBER" > $mountpoint/tmp/LAST-FILELIST-NUMBER
2717 fi
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
2725 mkdir -p $mountpoint/proc
2726 LogFile "---------------------------"
2727 LogFile "Content of initial ramdisk:"
2728 LogFile "---------------------------"
2729 (cd "$mountpoint" ; ls -Rla ) >> $LOGFILE
2730 LogFile "---------------------------"
2731
2732 # Determine what filesystem to use for initrd image
2733 LogFile "INFO: Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
2734 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2735 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2736 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ] || [ "$gvFileSystem" = "ext4fs" ]; then
2737 # say what will be used
2738 LogFile "INFO: Creating an $gvFileSystem initrd image..."
2739 # kernel expects linuxrc in ext2 filesystem
2740 ( cd "$mountpoint" && ln -sf usr/sbin/init linuxrc )
2741 # unmount loop filesystem and create image file using the standard approach
2742 umount $mountpoint || Die "Cannot unmount $tempfile"
2743 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
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
2749 MINDI_ADDITIONAL_BOOT_PARAMS="$MINDI_ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2750 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
2751 rm -f ${rdz_fname}.tmp
2752 # log that we are done
2753 LogFile " ...done."
2754 elif [ "$gvFileSystem" = "initramfs" ]; then
2755 # say what will be used
2756 LogFile "INFO: Creating a gzip'ed cpio (AKA initramfs) initrd image..."
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
2760 cd "$mountpoint"
2761 # kernel expects init in cpio filesystem
2762 ln -sf sbin/init init
2763 # create cpio image file and unmount loop filesystem
2764 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
2765 cd "$old_pwd"
2766 umount $mountpoint || Die "Cannot unmount $tempfile"
2767 # log that we are done
2768 LogFile " ...done."
2769 else
2770 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2771 fi
2772
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##############################################################################
2783#----------------------------------- Main -----------------------------------#
2784##############################################################################
2785
2786# Now we can create what we need
2787mkdir -p $MINDI_TMP
2788
2789# Purge from potential old run
2790if [ _"$MINDI_CACHE" = _"" ]; then
2791 Die "MINDI_CACHE undefined"
2792fi
2793
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
2801if [ "$1" = "--printvar" ] ; then
2802 shift
2803 if [ _"$1" != _"" ] ; then
2804 set | grep -Ew "^$1" | cut -d= -f2
2805 fi
2806 exit 0
2807fi
2808
2809LogFile "mindi v$MINDI_VERSION"
2810LogFile "$ARCH architecture detected"
2811LogFile "mindi called with the following arguments:"
2812echo "$@">> $LOGFILE
2813LogFile "Start date : `date`"
2814LogFile "-----------------------------"
2815
2816[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && LogAll "/sbin/mkfs.vfat is missing!"
2817
2818# Log some capital variables
2819[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2820[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2821LogFile "MONDO_SHARE = $MONDO_SHARE"
2822LogFile "MINDI_LIB = $MINDI_LIB"
2823LogFile "MINDI_SBIN = $MINDI_SBIN"
2824LogFile "MINDI_CONF = $MINDI_CONF"
2825if [ -f $MINDI_CONFIG ]; then
2826 LogFile "-----------------------------"
2827 LogFile " Mindi configuration file "
2828 LogFile "-----------------------------"
2829 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
2830 LogFile "-----------------------------"
2831fi
2832LogFile "In Mindi"
2833LogFile "--------"
2834LogFile "EXTRA_SPACE = $EXTRA_SPACE"
2835LogFile "BOOT_SIZE = $BOOT_SIZE"
2836LogFile "--------"
2837
2838trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
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
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"
2848 fi
2849fi
2850which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2851[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
2852
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"
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
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..."
2861 LogFile "INFO: Or you might like to call 'su -' instead of 'su', for example."
2862fi
2863
2864if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
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
2868### TODO
2869### Fix as it's not mandatory on ia64
2870if [ "$ARCH" = "ia64" ] ; then
2871 if which elilo &> /dev/null ; then
2872 LILO_EXE=elilo
2873 else
2874 LILO_EXE=`which false 2> /dev/null`
2875 fi
2876else
2877 FindIsolinuxBinary
2878fi
2879trap "Aborted" SIGTERM
2880DONE="\r\t\t\t\t\t\t\t\tDone. "
2881kernelpath=""
2882MONDO_ROOT=/var/cache/mondo
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
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
2905LogFile "INFO: LVM set to $LVM"
2906LogFile "----------"
2907LogFile "mount result:"
2908LogFile "-------------"
2909mount >> $LOGFILE
2910if [ -e /etc/raidtab ]; then
2911 LogFile "-------------"
2912 LogFile "/etc/raidtab content:"
2913 LogFile "-------------"
2914 cat /etc/raidtab >> $LOGFILE
2915else
2916 LogFile "No file /etc/raidtab"
2917fi
2918if [ -e /etc/mdadm.conf ]; then
2919 LogFile "-------------"
2920 LogFile "/etc/mdadm.conf content:"
2921 LogFile "-------------"
2922 cat /etc/mdadm.conf >> $LOGFILE
2923else
2924 LogFile "-------------"
2925 LogFile "No file /etc/mdadm.conf"
2926fi
2927LogFile "-------------"
2928LogFile "cat $CMDLINE"
2929LogFile "-------------"
2930cat $CMDLINE >> $LOGFILE
2931LogFile "-------------"
2932LogFile "cat /proc/swaps:"
2933LogFile "-------------"
2934cat /proc/swaps >> $LOGFILE
2935LogFile "-------------"
2936if [ -e /proc/mdstat ]; then
2937 LogFile "cat /proc/mdstat:"
2938 LogFile "-------------"
2939 cat /proc/mdstat >> $LOGFILE
2940else
2941 LogFile "No pseudo file /proc/mdstat"
2942fi
2943LogFile "-------------"
2944LogFile "cat /proc/partitions:"
2945LogFile "-------------"
2946cat /proc/partitions >> $LOGFILE
2947LogFile "-------------"
2948LogFile "cat /proc/filesystems:"
2949LogFile "-------------"
2950cat /proc/filesystems >> $LOGFILE
2951LogFile "-------------"
2952LogFile "lsmod result:"
2953LogFile "-------------"
2954lsmod >> $LOGFILE
2955MODULES="`cat /proc/modules | $AWK '{print $1}'`"
2956if [ -x /usr/sbin/esxcfg-module ]; then
2957 LogFile "-------------"
2958 LogFile "INFO: VMWare ESX server detected - Enabling dedicated support"
2959 LogFile "-------------"
2960 LogFile "VMWare modules"
2961 LogFile "-------------"
2962 /usr/sbin/esxcfg-module -l >> $LOGFILE
2963 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
2964fi
2965LogFile "-------------"
2966LogFile "FORCE_MODS:"
2967LogFile "-------------"
2968LogFile "$FORCE_MODS"
2969LogFile "-------------"
2970LogFile "DENY_MODS:"
2971LogFile "-------------"
2972LogFile "$DENY_MODS"
2973LogFile "-------------"
2974LogFile "df result:"
2975LogFile "----------"
2976df -aT >> $LOGFILE
2977LogFile "-------------"
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
2987 LogFile "-------------"
2988fi
2989if [ -r /boot/grub/grub.conf ]; then
2990 LogFile "-------------"
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 "-------------"
3005 LogFile "INFO: /boot/grub/device.map content"
3006 LogFile "-------------"
3007 cat /boot/grub/device.map >> $LOGFILE
3008 LogFile "-------------"
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
3016LogFile "Full fdisk info"
3017LogFile "---------------"
3018$FDISK -l >> $LOGFILE
3019LogFile "----------------"
3020
3021# Compute libata version
3022laver=`modinfo libata 2> /dev/null | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
3023# If libata v2 is used then remove ide-generic as it will perturbate boot
3024if [ "`echo $MODULES | grep libata`" ]; then
3025 if [ "$laver" = "2" ]; then
3026 DENY_MODS="$DENY_MODS ide-generic"
3027 LogFile "INFO: ide-generic removed from module list as your system uses libata v2+"
3028 LogFile "-------------"
3029 fi
3030fi
3031
3032# Check for McAfee which disturbs the access to some files (tgz in articular)
3033if [ "x`cat /proc/linuxshield/enabled 2>/dev/null`" = "x1" ]; then
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
3041# Check for ISO_CMD command
3042if [ ! -x $ISO_CMD ]; then
3043 LogFile "NOTE: No CD image (ISO file) utility found"
3044fi
3045
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
3054#
3055# If we have a USB device we need to store info
3056# and remove it from the parameters line
3057#
3058if [ "$#" -ne "0" ] ; then
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
3070 if [ "$1" = "--findkernel" ] ; then
3071 resk=`TryToFindKernelPath`
3072 # Avoids logfile content for mondo
3073 export MONDO_SHARE=""
3074 if [ "$resk" = "" ] ; then
3075 if [ $KERNEL_IS_XEN = "yes" ]; then
3076 echo "$xenkernelpath"
3077 LogFile "INFO: xenkernelpath = $xenkernelpath"
3078 MindiExit 0
3079 else
3080 MindiExit -1
3081 fi
3082 else
3083 echo "$resk"
3084 LogFile "INFO: kernelpath = $resk"
3085 MindiExit 0
3086 fi
3087 elif [ "$1" = "--locatedeps" ] ; then
3088 [ ! "$2" ] && Die "Please specify the binary to look at"
3089 LocateDeps $*
3090 # Avoids logfile content for mondo
3091 export MONDO_SHARE=""
3092 MindiExit $?
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=""
3097 mr-read-all-link $2
3098 MindiExit $?
3099 elif [ "$1" = "--makemessage" ] ; then
3100 MakeMessageFile | cut -c1-80
3101 MindiExit 0
3102 elif [ "$1" = "--makemountlist" ] ; then
3103 [ ! "$2" ] && Die "Please specify the output file"
3104 MakeMountlist $2
3105 CheckMountlist $2
3106 # Avoids logfile content for mondo
3107 export MONDO_SHARE=""
3108 MindiExit $?
3109 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
3110 echo "Mindi v$MINDI_VERSION"
3111 # Avoids logfile content for mondo
3112 export MONDO_SHARE=""
3113 MindiExit 0
3114 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
3115 MONDO_TMP=$2
3116 # Change MINDI_TMP for the one provided by mondo
3117 # So that it can get back the built files
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
3124 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2>> $LOGFILE
3125 rmdir $MINDI_TMP
3126 export MINDI_TMP=$MONDO_TMP
3127 mkdir -p $MINDI_TMP
3128
3129 # This is the scratch dir in mondo - subdir images
3130 MINDI_CACHE=$3
3131
3132 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
3133 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
3134
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###
3140 if [ $KERNEL_IS_XEN = "yes" ]; then
3141 LogAll "INFO: xenkernelpath = $xenkernelpath"
3142 fi
3143 kernelname=`echo $kernelpath | cut -d'-' -f2- | sed 's/.[bg]z[2]*$//'`
3144 if [ ! -d "/lib/modules/$kernelname" ]; then
3145 LogAll "WARNING: Module path for ${kernelpath} not found..."
3146 LogAll " using running kernel\'s modules."
3147 kernelname=$KERVERRUN
3148 else
3149 LogAll "Using modules for kernel: ${kernelname}"
3150 fi
3151 LogAll "INFO: kernelname = $kernelname"
3152 LogAll "INFO: kernelpath = $kernelpath"
3153###
3154### end of Sq-Modification
3155###
3156 TAPEDEV=$5
3157 TAPESIZE=$6
3158 FILES_IN_FILELIST=$7
3159 USE_LZO=$8
3160 CDRECOVERY=$9
3161 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
3162 IMAGE_DEVS=""
3163 else
3164 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
3165 fi
3166 if [ "${11}" ] ; then
3167 LILO_OPTIONS=""
3168 # LogAll "INFO: LILO will use conservative settings, to be compatible with older BIOSes."
3169 fi
3170 LAST_FILELIST_NUMBER=${12}
3171 ESTIMATED_TOTAL_NOOF_SLICES=${13}
3172 export MINDI_EXCLUDE_DEVS="${14}"
3173 USE_COMP="${15}"
3174 USE_LILO="${16}"
3175 USE_STAR="${17}"
3176 INTERNAL_TAPE_BLOCK_SIZE="${18}"
3177 DIFFERENTIAL="${19}"
3178 USE_GZIP="${20}"
3179 NOT_BOOT="${21}"
3180 [ "$USE_COMP" = "" ] && USE_COMP=yes
3181 [ "$USE_GZIP" = "" ] && USE_GZIP=no
3182 [ "$NOT_BOOT" = "" ] && NOT_BOOT=no
3183 [ "$TAPEDEV" ] && LogIt "INFO: This is a tape-based backup. Fine."
3184 # MONDO_ROOT is the real scratchdir
3185 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
3186 if [ _"$MONDO_ROOT" != _"" ]; then
3187 mkdir -p $MONDO_ROOT
3188 else
3189 Die "MONDO_ROOT is undefined"
3190 fi
3191 else
3192 LogScreen "Syntax: mindi (--custom ....)"
3193 MindiExit -1
3194 fi
3195fi
3196
3197if [ _"$MINDI_CACHE" != _"" ]; then
3198 rm -rf $MINDI_CACHE/* 2> /dev/null
3199 mkdir -p $MINDI_CACHE
3200fi
3201
3202[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3203
3204if [ _"$MONDO_SHARE" = _"" ]; then
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"
3208 LogIt "------------------------------------------------------------------------------"
3209else
3210 LogFile "INFO: You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks"
3211fi
3212if [ -f $MINDI_LIB/rootfs/usr/bin/busybox ]; then
3213 LogIt "Mindi-`$MINDI_LIB/rootfs/usr/bin/busybox 2>&1 | head -1`"
3214else
3215 LogIt "ERROR: Unable to find mindi-busybox, please install it"
3216 MindiExit -1
3217fi
3218
3219for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
3220 modinfo $i 2> /dev/null 1> /dev/null
3221 if [ $? -eq 0 ]; then
3222 modprobe $i 2>&1 > /dev/null
3223 fi
3224done
3225
3226KERN_DISK_MADE=""
3227
3228LogFile "DIFFERENTIAL = $DIFFERENTIAL"
3229LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
3230LogFile "NOT_BOOT = '$NOT_BOOT'"
3231if [ "$NOT_BOOT" != "" ] && [ "$NOT_BOOT" != "0" ] && [ "$NOT_BOOT" != "no" ] ; then
3232 LogIt "INFO: Just creating $MRCFG and a small all.tar.gz for Mondo. Nothing else."
3233 MakeMondoConfigFile $MINDI_TMP/$MRCFG
3234 MakeMountlist $MINDI_TMP/mountlist.txt
3235 CheckMountlist $MINDI_TMP/mountlist.txt
3236 mkdir -p $MINDI_TMP/small-all/tmp
3237 cd "$MINDI_TMP/small-all"
3238 cp -f $MINDI_TMP/{mountlist.txt,$MRCFG,filelist.full.gz,biggielist.txt} tmp 2>> $LOGFILE || Die "Cannot copy small all.tar.gz"
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
3240 sleep 2
3241 LogIt "Done. Exiting."
3242 MindiExit 0
3243fi
3244
3245if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3246 LogIt "INFO: Including the generation of a Bootable USB device on $USBDEVICE"
3247fi
3248
3249if [ "$kernelpath" = "" ] ; then
3250 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
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"
3255 else
3256 USE_OWN_KERNEL="no"
3257 fi
3258 if [ "$USE_OWN_KERNEL" = "yes" ]; then
3259 kernelpath=`TryToFindKernelPath`
3260 if [ "$kernelpath" = "" ] ; then
3261 echo -n "Please enter kernel path : "
3262 read kernelpath
3263 fi
3264 fi
3265fi
3266
3267echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
3268[ "$(($RANDOM%64))" -eq "0" ] && LogIt "INFO: Dude, I've looked inside your computer and it's really dusty..."
3269
3270mountpoint=$MINDI_TMP/mountpoint.$$
3271PrepareDataDiskImages
3272
3273ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
3274rds=$(($ramdisk_size-$((ramdisk_size%4096))))
3275export ramdisk_size=$rds
3276
3277LogFile "INFO: Ramdisk will be $ramdisk_size KB"
3278if [ "$ARCH" = "ia64" ] ; then
3279 PrepareBootDiskImage_LILO $kernelpath || Die "Failed to create ia64 image disk image."
3280else
3281 PrepareBootDiskImage_ISOLINUX $kernelpath || Die "Failed to create $ramdisk_size KB disk image."
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
3287if [ _"$MONDO_SHARE" = _"" ]; then
3288 ListImagesForUser
3289 OfferToMakeBootableISO
3290 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3291 OfferToMakeBootableUSB
3292 fi
3293 LogAll "Finished."
3294elif [ "$TAPEDEV" ] ; then
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
3301 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3302 OfferToMakeBootableUSB
3303 fi
3304 OfferToMakeBootableISO
3305 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3306 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
3307 else
3308 Die "Cannot find all.tar.gz, to be written to tape"
3309 fi
3310elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
3311 OfferToMakeBootableUSB
3312else
3313 OfferToMakeBootableISO
3314fi
3315# cleanup
3316LogAll "INFO: $FRIENDLY_OUTSTRING"
3317for mtpt in $FLOPPY_WAS_MOUNTED ; do
3318 mount $mtpt
3319done
3320MindiExit 0
Note: See TracBrowser for help on using the repository browser.