source: MondoRescue/branches/2.2.10/mindi/mindi@ 2704

Last change on this file since 2704 was 2704, checked in by Bruno Cornec, 13 years ago

r4180@localhost: bruno | 2011-01-27 10:26:41 +0100

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