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

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

r4184@localhost: bruno | 2011-01-27 15:52:51 +0100

  • Adds support for hpsa driver (new HP Smart Array driver)
  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 98.7 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 2708 2011-01-27 18:31:44Z 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 hpsa 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/NETFS-CLIENT-IPADDR netfs-client-ipaddr $outfile
936 AddFileToCfgIfExists $MINDI_TMP/NETFS-CLIENT-NETMASK netfs-client-netmask $outfile
937 AddFileToCfgIfExists $MINDI_TMP/NETFS-CLIENT-BROADCAST netfs-client-broadcast $outfile
938 AddFileToCfgIfExists $MINDI_TMP/NETFS-CLIENT-DEFGW netfs-client-defgw $outfile
939 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
940 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME bootloader.name $outfile
941 AddFileToCfgIfExists $MINDI_TMP/TAPEDEV-HAS-DATA-DISKS tapedev-has-data-disks $outfile
942}
943
944# Get PV's for an LV
945GetPVsForLV() {
946 if [ -n "$1" ]; then
947 vg=`$LVMCMD lvdisplay $1 2>/dev/null |awk '/VG Name/{print $NF;exit}'`
948 if [ -z "$vg" ]; then
949 return
950 fi
951 $LVMCMD vgdisplay -v $vg 2>/dev/null | awk '/PV Name/{print $NF}'
952 fi
953}
954
955
956MakeMountlist() {
957 local scratchdir mountlist all_partitions current_partition \
958partition_size partition_format outstring partition_number \
959partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
960absolute_partition old_partition_fmt current_lvolume uname skip
961
962 LogFile "------------------------------------"
963 LogFile "Your raw fstab file looks like this:"
964 LogFile "------------------------------------"
965 cat $MY_FSTAB >> $LOGFILE
966 LogAll "-----------------------------------"
967 LogAll "Your mountlist will look like this:"
968 LogAll "-----------------------------------"
969
970# scratchdir, mountlist(OUT)
971 scratchdir=$MINDI_TMP
972 mountlist=$1
973
974# NB: partition = device
975# NB: mountpt = where the device is mounted
976
977 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
978
979 [ "$mountlist" != "" ] && rm -Rf $mountlist
980 > $mountlist
981 all_partitions=""
982
983 if [ $LVM != "false" ]; then
984 LogFile "Analyzing LVM..."
985 $MINDI_DATA/analyze-my-lvm > $MINDI_TMP/lvm.res
986 if [ $? -ne 0 ]; then
987 LVM="false"
988 fi
989 # Excluded LVs and GVs are not reported here
990 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
991 fi
992 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
993 for i in $IMAGE_DEVS ; do
994 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
995 done
996 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
997 printf "%-15s %-15s %-15s %-15s %s\n" DEVICE MOUNTPOINT FORMAT "SIZE MB" LABEL/UUID | tee -a $LOGFILE
998 printf "%-15s %-15s %-15s %-15s %s\n" ------ ---------- ------ ------- ---------- | tee -a $LOGFILE
999 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"
1000 for c_p in $all_partitions ; do
1001 # Skip evices, network FS, cisf
1002 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] || [ "`echo "$c_p" | grep -E "^//"`" != "" ]&& continue
1003 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
1004 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
1005 current_partition=`readlink -f $c_p`
1006 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
1007 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
1008 else
1009 current_partition="$c_p"
1010 fi
1011 [ "$c_p" = "none" ] && continue
1012 # Debian 5 does that
1013 [ "$c_p" = "proc" ] && continue
1014 redhat_label=""
1015 label=""
1016 uuid=""
1017 absolute_partition=`readlink -f $c_p`
1018 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1019
1020 # Detects noauto partitions not mounted and exclude them
1021 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
1022 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then
1023 continue
1024 fi
1025
1026 # set default in case we dont't find it
1027 str_to_find_fmt_with=$current_partition
1028
1029 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1030 # current_partition contains only first column of /etc/fstab
1031 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
1032 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
1033 actual_dev=""
1034
1035 # 1st try, findfs - the RHEL way of finding labels and their partitions
1036 if [ -x "/sbin/findfs" ]; then
1037 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
1038 fi
1039
1040 # 2nd try : blkid, the good way for all LABEL except swap
1041 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1042 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
1043 # For LVM FS it will give a /dev/dm-# which should then be converted
1044 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1045 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1046 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1047 for dev in `ls /dev/mapper/*`; do
1048 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1049 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1050 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1051 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1052 break
1053 fi
1054 done
1055 fi
1056 fi
1057
1058 # 3rd try, which works on a standard partition (ext2/3), but not on swap
1059 # For LVM gives a /dev/mapper entry
1060 if [ "x$actual_dev" = "x" ]; then
1061 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
1062 fi
1063
1064 # 4th try, with vol_id
1065 # SWAP only
1066 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1067 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
1068 for dev_swap in $list_swaps ; do
1069 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1070 if [ "x$dev_exists" != "x" ]; then
1071 actual_dev=$dev_swap
1072 break;
1073 fi
1074 done
1075 fi
1076
1077 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
1078 # LABEL=SW-cciss/c0d0p3 (RDP)
1079 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
1080 # SWAP only
1081 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
1082 skip=""
1083 uname=$KERVERRUN
1084 [ "`echo $uname | grep "2.4.[0-9]"`" != "" ] && skip=16
1085 # 2.6.12 needs 16 (FC3)
1086 [ "`echo $uname | grep "2.6.[0-1]"`" != "" ] && skip=16
1087 # 2.6.19 and upper needs 1052
1088 [ "`echo $uname | grep "2.6.19"`" != "" ] && skip=1052
1089 [ "`echo $uname | grep "2.6.[2-9]"`" != "" ] && skip=1052
1090 if [ $skip = "" ]; then
1091 Die "Your kernel is too old. I don't know how to support labelled swap spaces with it"
1092 fi
1093 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1094 do
1095 # Location of the swap label for kernel 2.6
1096 try_dev_label=`dd bs=1 count=16 skip=$skip if=$try_dev 2> /dev/null`
1097 if [ "x$try_dev_label" = "x$redhat_label" ]; then
1098 actual_dev=$try_dev
1099 fi
1100 done
1101 fi
1102
1103 # Check if one of all those tries has known success
1104 if [ "x$actual_dev" != "x" ]; then
1105 current_partition=$actual_dev
1106 else
1107 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"
1108 fi
1109 # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1110 # current_partition contains only first column of /etc/fstab
1111 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
1112 uuid=`echo "$current_partition" | cut -d'=' -f2`
1113 actual_dev=""
1114
1115 # 1st try, findfs - the RHEL way of finding labels and their partitions
1116 if [ -x "/sbin/findfs" ]; then
1117 actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1118 fi
1119
1120 # 2nd try : blkid, the good way for all UUID except swap
1121 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
1122 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
1123 # For LVM FS it will give a /dev/dm-# which should then be converted
1124 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
1125 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1126 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
1127 for dev in `ls /dev/mapper/*`; do
1128 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1129 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
1130 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
1131 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
1132 break
1133 fi
1134 done
1135 fi
1136 fi
1137
1138 # 3th try, with vol_id
1139 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
1140 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1141 for dev in $list_dev ; do
1142 dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1143 if [ "x$dev_exists" != "x" ]; then
1144 actual_dev=$dev
1145 break;
1146 fi
1147 done
1148 fi
1149
1150 # 4th try, with dumpuuid (VMWare only ?) for swap
1151 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1152 list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1153 for dev in $list_dev ; do
1154 dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1155 if [ "x$dev_exists" != "x" ]; then
1156 actual_dev=$dev
1157 break;
1158 fi
1159 done
1160 fi
1161
1162 # Check if one of all those tries has known success
1163 if [ "x$actual_dev" != "x" ]; then
1164 current_partition=$actual_dev
1165 else
1166 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."
1167 fi
1168 else
1169 # Needs to handle the recent OpenSUSE fancy way of dealing with fstab :-(
1170 # they use symlinks in fstab unrelated to what is shown in mount !
1171 if [ _"$partition_mountpt" = _"" ]; then
1172 # set default in case we dont't find it
1173 for tmpp in `tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -Ev "^#" | $AWK '{print $1}'`; do
1174 if [ _"`readlink -f $tmpp`" = _"$current_partition" ]; then
1175 str_to_find_fmt_with=$tmpp
1176 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$tmpp" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1177 break;
1178 fi
1179 done
1180 fi
1181 fi
1182
1183 # Look for devices which have to be excluded
1184 skip=0
1185 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
1186 l=""
1187 list_of_devices="`ReadAllLink $current_partition`"
1188 for d in $list_of_devices; do
1189 l="$l `$MINDI_LIB/analyze-my-lvm --givemapperofdm $d`"
1190 done
1191
1192 # Remove PVs from LVs excluded
1193 l="$l `GetPVsForLV $current_partition`"
1194
1195 # We want a single unique list
1196 list_of_devices="`echo $l | sort -u`"
1197
1198 for d in $MINDI_EXCLUDE_DEVS ; do
1199 if [ "`echo " $list_of_devices " | grep " $d"`" != "" ]; then
1200 echo "Excluding $current_partition from mountlist (due to excluded device $d)" >> $LOGFILE
1201 skip=1
1202 continue
1203 fi
1204 done
1205 fi
1206 if [ $skip -eq 1 ]; then
1207 continue
1208 fi
1209
1210 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1211 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1212 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1213 # the former is then a link to the latter, so we test whether
1214 # $current_partition is actually such a link or not and set
1215 # $current_lvolume accordingly. On Debian you may find more than one answer
1216 # so we remove the one corresponding to /dev/.static
1217 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1218 # principle is the same and we need to find the link to it as well.
1219 # Note that $current_lvolume may well be an
1220 # ordinary device. It is just to make sure that we feed the right value
1221 # into any of the LVM tools if possible.
1222
1223 current_lvolume="$current_partition"
1224 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
1225 # .static dir are a Debian specificity
1226 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
1227 echo $current_lvolume | grep -q ' '
1228 if [ $? -eq 0 ]; then
1229 LogFile "WARNING: Multiple Logical Volumes found. Report to dev team"
1230 fi
1231 # if it's not found, it may well be a real device such as a multipath one
1232 # /dev/mapper/mpath... Thus we revert the situation so that next test succeed
1233 if [ _"$current_lvolume" = _"" ]; then
1234 current_lvolume="$current_partition"
1235 fi
1236 fi
1237 #
1238 # End of LVM device style variation code (other than $current_lvolume).
1239
1240 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1241 # Size computed via LVM not directly
1242 partition_size="lvm"
1243 else
1244 partition_size=`SizeOfPartition $current_partition`
1245 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1246 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1247 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1248 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1249 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1250 [ "$partition_format" != "swap" ] && partition_format="swap"
1251 if [ "$partition_size" = "" ] ; then
1252 totalsize=0
1253 items=0
1254 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1255 totalsize=$(($totalsize+$i))
1256 items=$(($items+1))
1257 done
1258 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1259 [ "$partition_size" -lt "125000" ] && partition_size=125000
1260 LogFile "I'm guessing $c_p is $(($partition_size/1024))MB"
1261 fi
1262 fi
1263 fi
1264 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1265 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1266 if [ "$partition_mountpt" = "" ] ; then
1267 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1268 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1269 partition_mountpt="raid"
1270 partition_format="raid"
1271 else
1272 partition_mountpt="lvm"
1273 partition_format="lvm"
1274 fi
1275 fi
1276 fi
1277 psz=$partition_size
1278 LogFile "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)"
1279 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1280 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1281 partition_mountpt="image"
1282 old_partition_fmt=$partition_format
1283 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1284 partition_size=$(($partition_size+1)); # just in case
1285 if [ "$partition_format" = "Linux" ] ; then
1286 LogFile "Are you imaging a mounted swap partition? Silly..."
1287 LogFile "Reverting format from $old_partition_fmt to $partition_format"
1288 partition_format=$old_partition_fmt
1289 fi
1290 fi
1291
1292 if [ ! "$partition_mountpt" ] ; then
1293 LogFile "------- $FDISK -l $qq log ------------"
1294 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
1295 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1296 [ "$partition_format" ] && break
1297 done
1298 LogFile "------- $FDISK log end ------------"
1299 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1300 partition_format="compaq"
1301 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1302 LogAll "Unable to find mountpoint of $current_partition - ignoring"
1303 continue
1304 fi
1305 fi
1306 if [ "$redhat_label" ]; then
1307 label="$redhat_label"
1308 elif [ "$uuid" ]; then
1309 label="$uuid"
1310 fi
1311 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
1312 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
1313 unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
1314 if [ "$current_partition" = "" ] ; then
1315 LogFile "Unknown partition (outstring = $unofficial_outstring)"
1316 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1317 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1318 partition_mountpt=raid
1319 partition_format=raid
1320 printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1321 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1322 else
1323 LogFile "Unknown mountpoint (outstring = $unofficial_outstring)"
1324 fi
1325 elif [ "$partition_format" = "" ] ; then
1326 LogFile "Unknown format (outstring = $unofficial_outstring)"
1327 elif [ "$partition_size" = "" ] ; then
1328 LogFile "Unknown partition size (outstring = $unofficial_outstring)"
1329 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1330 continue
1331 else
1332 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1333 LogFile "vfat should be used instead of dos/msdos as a partition format"
1334 partition_format="vfat"
1335 fi
1336 printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1337 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1338 fi
1339 done
1340 LogAll "-----------------------------------"
1341}
1342
1343CheckMountlist() {
1344 local file=$1
1345 # Coherency verification
1346 ML01=`cat $file | wc -l`
1347 ML02=`grep -v ' lvm ' $file | wc -l`
1348 ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
1349 ML2=`grep -v ' lvm ' $file | $AWK '{print $2}' | sort -u | wc -l`
1350 if [ "$ML01" -ne "$ML1" ]; then
1351 LogFile "--------------------------------------------"
1352 echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE
1353 LogFile "--------------------------------------------"
1354 fi
1355 if [ "$ML02" -ne "$ML2" ]; then
1356 LogFile "--------------------------------------------"
1357 echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE
1358 LogFile "------------------------------------------------"
1359 fi
1360}
1361
1362OfferToMakeBootableISO() {
1363 local i old_pwd
1364 if [ -z "$ISO_CMD" ]; then
1365 LogFile "Neither mkisofs nor genisoimage found, unable to make CD image"
1366 return
1367 fi
1368 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1369 echo -en "Shall I make a bootable CD image? (y/[n]) "
1370 read i
1371 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1372 fi
1373 rm -Rf $MINDI_TMP/iso
1374 mkdir -p $MINDI_TMP/iso/{images,archives}
1375 cp -f $MINDI_CACHE/{*.gz,*.img} $MINDI_TMP/iso/images 2>> $LOGFILE || LogAll "OfferToMakeBootableISO: Cannot copy $MINDI_CACHE/*.gz to $MINDI_TMP/iso/images"
1376 LogFile "mindi_lib = $MINDI_DATA"
1377 for i in memdisk memtest.bin memtest.img ; do
1378 j=$MINDI_DATA/$i
1379 k=$MINDI_TMP/iso
1380 if [ -e "$j" ] ; then
1381 LogAll "Copying $j to $k"
1382 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1383 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1384 if [ _"$MONDO_SHARE" != _"" ]; then
1385 cp -f $j $MONDO_CACHE 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_CACHE"
1386 fi
1387 fi
1388 done
1389 MakeMessageFile > $MINDI_TMP/iso/message.txt
1390 if [ $KERNEL_IS_XEN = "yes" ]; then
1391 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?"
1392 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?"
1393 fi
1394 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?"
1395 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?"
1396
1397 if [ _"$MONDO_SHARE" != _"" ]; then
1398 if [ $KERNEL_IS_XEN = "yes" ]; then
1399 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?"
1400 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?"
1401 fi
1402 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?"
1403 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?"
1404 fi
1405 MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
1406 if [ "$ARCH" != "ia64" ] ; then
1407 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?"
1408 fi
1409 old_pwd=`pwd`
1410 cd $MINDI_TMP/iso
1411 LogFile "-------------------"
1412 LogFile "Content of the ISO:"
1413 LogFile "-------------------"
1414 ls -Rla >> $LOGFILE
1415 LogFile "-------------------"
1416
1417 if [ "$ARCH" != "ia64" ] ; then
1418 if [ _"$MONDO_SHARE" != _"" ]; then
1419 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?"
1420 if [ $KERNEL_IS_XEN = "yes" ]; then
1421 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?"
1422 fi
1423 cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
1424 fi
1425 $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
1426 else
1427 $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
1428 fi
1429 if [ "$?" -ne "0" ] ; then
1430 LogFile "----------- $ISO_CMD's errors --------------"
1431 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
1432 echo "$ISO_CMD returned the following errors:-"
1433 cat $MINDI_TMP/mkisofs.log
1434 LogAll "Failed to create ISO image."
1435 else
1436 LogAll "Created bootable ISO image at $MINDI_CACHE/mindi.iso"
1437 fi
1438 rm -f $MINDI_TMP/mkisofs.log
1439 cd $old_pwd
1440}
1441
1442
1443OfferToMakeBootableUSB() {
1444 local i
1445 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1446 echo -n "Shall I make a bootable USB device ? (y/[n]) "
1447 read i
1448 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1449 if [ "$USBDEVICE" = "" ]; then
1450 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1451 read dev
1452 USBDEVICE=$dev
1453 fi
1454 echo "WARNING: This will erase all content on $USBDEVICE"
1455 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1456 read i
1457 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1458 fi
1459 rm -Rf $MINDI_TMP/usb
1460 mkdir -p $MINDI_TMP/usb
1461 USBPART="${USBDEVICE}1"
1462
1463 echo -en "Transforming $USBDEVICE in a Bootable device "
1464 echo -en "."
1465 LogFile "Transforming $USBDEVICE in a Bootable device"
1466 LogFile "Checking $USBDEVICE"
1467 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
1468 if [ $? -ne 0 ]; then
1469 LogAll "Unable to access $USBDEVICE"
1470 LogAll "Make sure your USB device is pluged in"
1471 exit -1
1472 fi
1473 echo -en "."
1474 # Some distro do auto mount at that point (Ubuntu)
1475 LogFile "Unmounting $USBPART just in case"
1476 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1477 # If your key has no MBR it may cause an issue
1478 # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
1479 LogFile "Preparing $USBDEVICE"
1480 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
1481d
1482d
1483d
1484d
1485n
1486p
14871
1488
1489
1490t
1491b
1492a
14931
1494w
1495EOF
1496 if [ $? -ne 0 ]; then
1497 LogAll "Unable to create a vfat Filesystem on $USBDEVICE"
1498 LogAll "Make sure your USB device is pluged in"
1499 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1500 MindiExit -1
1501 fi
1502 LogFile "The USB device $USBDEVICE now looks like this:"
1503 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1504 echo -en "."
1505 # Some distro do auto mount at that point (Ubuntu)
1506 LogFile "Unmounting $USBPART just in case again"
1507 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1508 echo -en "."
1509 LogFile "Creating a vfat filesystem on $USBPART"
1510 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
1511 if [ $? -ne 0 ]; then
1512 LogAll "Unable to create a vfat filesystem on $USBPART"
1513 LogAll "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)"
1514 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1515 MindiExit -1
1516 fi
1517 echo -en "."
1518 LogFile "Mounting $USBPART on $MINDI_TMP/usb"
1519 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1520 if [ $? -ne 0 ]; then
1521 LogAll "Unable to mount $USBPART on $MINDI_TMP/usb"
1522 LogAll "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)"
1523 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1524 MindiExit -1
1525 fi
1526 echo -en "."
1527 mkdir -p $MINDI_TMP/usb/images
1528 cp -f $MINDI_CACHE/*.img $MINDI_CACHE/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogAll "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
1529 echo -en "."
1530 LogFile "mindi_lib = $MINDI_DATA"
1531 for i in memdisk memtest.bin memtest.img ; do
1532 j=$MINDI_DATA/$i
1533 k=$MINDI_TMP/usb
1534 if [ -e "$j" ] ; then
1535 LogAll "Copying $j to $k"
1536 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1537 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1538 fi
1539 done
1540 echo -en "."
1541 MakeMessageFile > $MINDI_TMP/usb/message.txt
1542 echo -en "."
1543 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?"
1544 echo -en "."
1545 cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1546 echo -en "."
1547 MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
1548 echo -en "."
1549 LogAll "----------- syslinux's conf --------------"
1550 cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
1551 LogAll "------------------------------------------"
1552 LogFile "--------------------------"
1553 LogFile "Content of the USB device:"
1554 LogFile "--------------------------"
1555 (cd $MINDI_TMP/usb ; ls -Rla) >> $LOGFILE
1556 LogFile "--------------------------"
1557
1558 umount $MINDI_TMP/usb
1559 if [ "$ARCH" != "ia64" ] ; then
1560 syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
1561 if [ "$?" -ne "0" ] ; then
1562 LogAll "----------- syslinux's errors --------------"
1563 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1564 echo "------------------------------------------"
1565 LogAll "Failed to create USB image."
1566 else
1567 echo -e "$DONE"
1568 LogFile "Created bootable USB image on $USBDEVICE"
1569 fi
1570 rm -f $MINDI_TMP/syslinux.log
1571 else
1572 echo "No USB boot support for ia64"
1573 MindiExit -1
1574 fi
1575}
1576
1577
1578MakeMessageFile() {
1579
1580 if [ -x "/bin/lsb_release" ]; then
1581 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1582 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1583 # For pb >= 0.9.8
1584 DESC=`/usr/bin/pbdistrocheck -d`
1585 else
1586 iss="/dev/null"
1587 [ -r /etc/issue.net ] && iss="/etc/issue.net"
1588 [ -r /etc/issue ] && iss="/etc/issue"
1589 DESC=`head -1 $iss`
1590 fi
1591 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/"
1592 if [ _"$MONDO_SHARE" != _"" ]; then
1593 if [ "$CDRECOVERY" != "yes" ] ; then
1594 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1595 echo -en "Press <enter> to continue.\n"
1596 elif [ ! "$MINDI_TMP" ] ; then
1597 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1598 if [ -e "$MINDI_DATA/memtest.img" ] ; then
1599 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
1600 fi
1601 else
1602 echo -en "$BOOT_MEDIA_MESSAGE"
1603 fi
1604 else
1605 echo -en "\
1606To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1607CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1608 fi
1609 fi
1610 echo -en "\n\n\n"
1611}
1612
1613
1614MakeBootConfFile() {
1615 local options i ooo
1616 options=""
1617 # Type of boot file (elilo or syslinux/isolinux)
1618 type=$1
1619 if [ "$type" = "elilo" ]; then
1620 sep="="
1621 else
1622 sep=" "
1623 fi
1624
1625 # Generic header for conf file
1626 if [ "$type" != "elilo" ] ; then
1627 echo -en "prompt 1\ndisplay message.txt\n"
1628 else
1629 echo -en "prompt\n"
1630 fi
1631
1632 # Compute which default option to boot from
1633 if [ "$CDRECOVERY" = "yes" ] ; then
1634 echo -en "default${sep}RESTORE\n"
1635 # In case it's mondoarchive
1636 elif [ _"$MONDO_SHARE" != _"" ]; then
1637 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1638 echo -en "default${sep}iso\n"
1639 else
1640 echo -en "default${sep}interactive\n"
1641 fi
1642 else
1643 echo -en "default${sep}expert\n"
1644 fi
1645
1646 # Handle timeout
1647 if [ "$CDRECOVERY" != "yes" ] ; then
1648 echo -en "timeout${sep}300\n"
1649 else
1650 echo -en "timeout${sep}10000\n"
1651 fi
1652 echo -en "\n"
1653
1654 # prepare which labels will be generated
1655 if [ "$CDRECOVERY" = "yes" ] ; then
1656 options="RESTORE expert"
1657 else
1658 if [ _"$MONDO_SHARE" != _"" ]; then
1659 options="interactive expert compare iso nuke isonuke"
1660 else
1661 options="expert"
1662 fi
1663 fi
1664
1665 # Generate rest of conf file
1666 for i in $options ; do
1667 ooo=$i
1668 [ "$ooo" = "RESTORE" ] && ooo="nuke"
1669 if [ "$type" = "elilo" ]; then
1670 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"
1671 else
1672 ps="/"
1673 if [ "$type" = "syslinux" ]; then
1674 ps=""
1675 fi
1676 if [ $KERNEL_IS_XEN = "no" ]; then
1677 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"
1678 else
1679 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"
1680 fi
1681 fi
1682 echo -en "$outstr"
1683 done
1684 if [ -e "$MINDI_DATA/memtest.img" ] ; then
1685 if [ "$type" = "elilo" ]; then
1686 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
1687 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
1688 else
1689 ps="/"
1690 if [ "$type" = "syslinux" ]; then
1691 ps=""
1692 fi
1693 echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
1694 echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
1695 fi
1696 fi
1697}
1698
1699
1700
1701PrepareBootDiskImage() {
1702 local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage liloconf mountefi
1703 imagesdir=$MINDI_CACHE
1704 kernelpath=$1
1705 do_boot_root_thingy=""
1706 retval=0
1707
1708 [ ! -e "$kernelpath" ] && Die "PBDI lilo - cannot find $kernelpath kernel"
1709 echo -en "Making "$BOOT_SIZE"KB boot disk..."
1710 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?"
1711 echo -en "..."
1712 imagefile=$MINDI_CACHE/mindi-bootroot.$BOOT_SIZE.img
1713 mountpoint=$MINDI_TMP/mountpoint.$$
1714 mkdir -p $mountpoint
1715 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1716 LogFile "Creating vfat filesystem on $imagefile"
1717 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1718 if [ "$ARCH" != "ia64" ] ; then
1719 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1720 # Ensure that $MINDI_CACHE is not on NFS (it shouldn't)
1721 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1722 fi
1723
1724 mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
1725
1726 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1727 mkdir -p $mountpoint/etc
1728 liloconf=$mountpoint/elilo.conf
1729
1730 MakeMessageFile > $mountpoint/message.txt
1731
1732 if [ "$ARCH" != "ia64" ] ; then
1733 MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1734 else
1735 MakeBootConfFile elilo > $liloconf
1736 # Copy it so that CD-ROM menu entry is satisfied
1737 mountefi=0
1738 df -T | grep /boot/efi | grep -q vfat
1739 if [ $? -ne 0 ]; then
1740 mount /boot/efi
1741 if [ $? -ne 0 ]; then
1742 echo "You have to mount your EFI partition when using mindi"
1743 MindiExit -1
1744 fi
1745 mountefi=1
1746 fi
1747 el=`find /boot/efi -name elilo.efi`
1748 cp $el $mountpoint
1749 cp $liloconf $mountpoint
1750 if [ $mountefi -eq 1 ]; then
1751 umount /boot/efi 2>&1 > /dev/null
1752 fi
1753 fi
1754
1755 LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
1756 cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
1757 if [ "$?" -ne "0" ] ; then
1758 LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1759 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1760 LogAll "Please unload some of your modules and try again."
1761 rm -f $MINDI_TMP/mtpt.$$
1762 LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1763 retval=$(($retval+1))
1764 fi
1765
1766 # copy the kernel across
1767 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1768 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1769 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1770
1771 retval=0
1772 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
1773 retval=$?
1774 if [ $KERNEL_IS_XEN = "yes" ]; then
1775 cp -f $xenkernelpath $mountpoint/xenkernel &> /dev/null
1776 let retval+=$?
1777 fi
1778
1779 if [ "$retval" -ne "0" ] ; then
1780 LogFile "Files at mountpoint ($mountpoint) :-"
1781 du -sk $mountpoint/* >> $LOGFILE
1782 LogFile "--- end of list of files ---"
1783 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n" >> $LOGFILE
1784 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1785 cd $old_pwd
1786 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1787 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1788
1789 rm -f $imagefile
1790 return 0
1791 fi
1792 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
1793 LogFile "Free space left on image = $free_space KB"
1794 LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
1795
1796 # make it bootable
1797 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1798 [ -e "$MINDI_DATA/memdisk" ] && cp -f $MINDI_DATA/memdisk $mountpoint 2>> $LOGFILE
1799
1800 if [ "$ARCH" = "ia64" ] ; then
1801 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1802 fi
1803 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1804 echo -en "..."
1805 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1806
1807 if [ "$retval" -eq "0" ] ; then
1808 echo -en "...$DONE\n"
1809 LogAll "$BOOT_SIZE KB boot disk was created OK\n"
1810 else
1811 echo -en "...failed\n"
1812 LogAll "$BOOT_SIZE KB boot disk was NOT created\n"
1813 rm -f $imagefile
1814 fi
1815 [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
1816 return $retval
1817}
1818
1819
1820ParseModprobeForIncludes() {
1821local MODPROBE_CONF mpincfile includes include
1822
1823MODPROBE_CONF=/etc/modprobe.conf
1824mpincfile=$1
1825touch $mpincfile
1826if [ -a $MODPROBE_CONF ]; then
1827 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
1828 if [ -n "$includes" ]; then
1829 for include in $includes
1830 do
1831 if [ -a "$include" ]; then
1832 echo $include >> $mpincfile
1833 fi
1834 done
1835 fi
1836fi
1837}
1838
1839
1840PrepareDataDiskImages() {
1841 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
1842
1843 imagesdir=$MINDI_CACHE
1844 rm -f $imagesdir/mindi.iso
1845 needlist=$MINDI_TMP/what-we-need.txt
1846 bigdir=$MINDI_TMP/bigdir
1847 mkdir -p $bigdir/usr/bin
1848 mkdir -p $bigdir/usr/sbin
1849 includefile=$MINDI_TMP/$$.includefile.txt
1850
1851 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
1852 if [ -e "$DEPLIST_FILE" ]; then
1853 lfiles="$DEPLIST_FILE $lfiles"
1854 fi
1855 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
1856 ParseModprobeForIncludes $includefile
1857 lines=$(($lines+`cat $includefile | wc -l`))
1858 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
1859 res=$?
1860 rm -f $includefile
1861 # This function appends to the file passed in param
1862 ListKernelModulePaths $needlist
1863 if [ "$res" -ne "0" ] ; then
1864 Die "You have $res files present in dependency list\nbut absent from filesystem."
1865 fi
1866 FindAndAddUserKeyboardMappingFile
1867 mkdir -p $bigdir/tmp
1868 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
1869 DropOptimizedLibraries $needlist $bigdir
1870 echo -en "Assembling dependency files"
1871
1872 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
1873
1874 # also copy io.sys and msdos.sys, if we can find them
1875 for i in `mount | cut -d' ' -f3` ; do
1876 for j in io.sys msdos.sys ; do
1877 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
1878 done
1879 done
1880
1881 # master boot record, too
1882 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
1883 if [ "$i" ] ; then
1884 LogAll "Backing up $i's MBR"
1885 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
1886 sleep 1
1887 sync
1888 j=$i
1889 [ -h "$j" ] && j=`readlink -f $j`
1890 LogAll "Creating /dev/boot_device ($j)"
1891 mkdir -p $bigdir/dev
1892 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
1893 fi
1894
1895 old_pwd=`pwd`
1896 cd $bigdir
1897
1898 # Get terminfo content
1899 ti="usr/share/terminfo/l"
1900 if [ -d /$ti ]; then
1901 mkdir -p $ti
1902 cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "WARNING - error occurred while copying terminfo"
1903 fi
1904 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
1905 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
1906 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
1907 fi
1908 if [ -d "/lib/dev-state" ]; then
1909 tar cf - -C / ./lib/dev-state 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
1910 fi
1911 cd $old_pwd
1912 echo -e "$DONE"
1913 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
1914 mkdir -p $bigdir/tmp
1915 if [ $LVM != "false" ]; then
1916 mkdir -p $bigdir$MINDI_CACHE
1917 $MINDI_DATA/analyze-my-lvm > $bigdir$MINDI_CACHE/i-want-my-lvm
1918 if [ "$?" -ne "0" ]; then
1919 LVM="false"
1920 rm -f $bigdir$MINDI_CACHE/i-want-my-lvm
1921 else
1922 LogFile "Your i-want-my-lvm file content is:"
1923 LogFile "-----------------------------------"
1924 cat $bigdir$MINDI_CACHE/i-want-my-lvm >> $LOGFILE
1925 LogFile "-----------------------------------"
1926 fi
1927 fi
1928
1929 echo -en "Tarring and zipping the data content..."
1930 size_of_all_tools=`du -sk $bigdir | cut -f1`
1931 (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)
1932 LogFile "Size of the data content"
1933 LogFile "------------------------"
1934 du -sk $imagesdir/*gz >> $LOGFILE
1935 LogFile "------------------------"
1936 echo -e "$DONE"
1937
1938 FRIENDLY_OUTSTRING="Boot and data disk images were created."
1939 rm -rf $bigdir
1940 rm -f $needlist
1941}
1942
1943
1944ProcessLDD() {
1945 local incoming f d nd bd bnd
1946 read incoming
1947 while [ "$incoming" != "" ]; do
1948 # We take the full path name of the dyn. lib. we want
1949 incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
1950 for f in $incoming ; do
1951 # echo modified file name if one of the parent dir is a link
1952 # by replacing the original dirname by the destination of the link
1953 d="`dirname $f`"
1954 found="false"
1955 while [ "$d" != "/" ]; do
1956 if [ -h "$d" ]; then
1957 nd=`readlink -f $d`
1958 bd=`basename $d`
1959 bnd=`basename $nd`
1960 f=`echo $f | sed "s~/$bd/~/$bnd/~"`
1961 echo $d
1962 fi
1963 d="`dirname $d`"
1964 done
1965
1966 echo "$f"
1967 echo "`ReadAllLink $f`"
1968 done
1969 read incoming
1970 done
1971}
1972
1973
1974Prompt() {
1975 echo -en "$1"
1976 read line
1977}
1978
1979
1980ReadLine() {
1981 local i incoming
1982 read incoming
1983 i=0
1984 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
1985 i=$(($i+1))
1986 read incoming
1987 done
1988 echo "$incoming"
1989}
1990
1991
1992SizeOfPartition() {
1993 local devpath drive res stub
1994 device=$1
1995 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
1996 res=`SizeOfRaidPartition $device`
1997 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
1998 echo "$res"
1999 return 0
2000 fi
2001 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2002 res=`$FDISK -s $device 2>> $LOGFILE`
2003 # end patch
2004 # take only the first in case of multiple mount (cifs, nfs, ...)
2005 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
2006 [ "$res" = "" ] && res="-1"
2007 echo $res
2008 return 0
2009}
2010
2011
2012SizeOfRaidPartition() {
2013 local real_dev smallest_size silly tmp
2014
2015 silly=999999999
2016 smallest_size=$silly
2017
2018 for real_dev in `GetRaidDevMembers $1` ; do
2019 tmp=`SizeOfPartition $real_dev`
2020 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2021 done
2022
2023 if [ "$smallest_size" = "$silly" ] ; then
2024 echo "-1"
2025 return 1
2026 else
2027 echo "$smallest_size"
2028 return 0
2029 fi
2030}
2031
2032
2033StripExecutable()
2034{
2035 local tmpfile
2036
2037 tmpfile=$MINDI_TMP/stripped.$$.dat
2038 [ -d "$1" ] || [ -h "$1" ] && return
2039 cp -f $1 $tmpfile 2>> $LOGFILE
2040 strip $tmpfile 2> /dev/null
2041 if [ "$?" -eq "0" ] ; then
2042 cp -f $tmpfile $1 2>> $LOGFILE
2043 LogFile "Stripped binary $2"
2044 fi
2045 rm -f $tmpfile
2046}
2047
2048KernelVer() {
2049 local fkern_ver fname
2050
2051 fname=$1
2052 file $fname | grep -q gzip
2053 if [ "$?" -eq "0" ] ; then
2054 # Used by ia64
2055 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2056 else
2057 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2058 fi
2059 echo "$fkern_ver"
2060}
2061
2062
2063TryToFindKernelPath() {
2064 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2065
2066 we_want_version=$KERVERRUN
2067 possible_kernels=""
2068 duff_kernels=""
2069
2070 if [ "$ARCH" = "ia64" ] ; then
2071 root="/boot/efi/efi"
2072 else
2073 root="/"
2074 fi
2075 # See if we're booted from a Xen kernel
2076 if [ -d /proc/sys/xen ]; then
2077 # It's a Xen kernel
2078 KERNEL_IS_XEN="yes"
2079 LogIt "It's a Xen kernel..."
2080 fi
2081
2082 for fname in `find $root -maxdepth 2 -type f | grep -Ei 'lin|kern|xen' | grep -Ev '^/proc/|^/net/'` ; do
2083 [ ! -e "$fname" ] && continue
2084 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2085 fkern_ver=`KernelVer $fname`
2086 [ "$fkern_ver" = "" ] && continue
2087 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2088 [ -f "$fname" ] || continue
2089 [ -h "$fname" ] && continue
2090 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2091 file $fname | grep -q gzip
2092 if [ "$?" -eq "0" ] ; then
2093 # Used by ia64
2094 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2095 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2096 duff_kernels="$fname $duff_kernels"
2097 else
2098 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2099 possible_kernels="$fname $possible_kernels"
2100 fi
2101 else
2102 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2103 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2104 duff_kernels="$fname $duff_kernels"
2105 else
2106 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2107 possible_kernels="$fname $possible_kernels"
2108 fi
2109 fi
2110 done
2111 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2112 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2113 fi
2114 if [ ! "$possible_kernels" ] ; then
2115 LogAll "No kernel matches exactly. Are there any duff kernels?"
2116 possible_kernels="$duff_kernels"
2117 if [ ! "$possible_kernels" ] ; then
2118 LogAll "Sorry, no duff kernels either"
2119 else
2120 LogAll "I bet you're running Debian or Gentoo, aren't you?"
2121 LogAll "Your kernel doesn't have a sane builddate. Oh well..."
2122 fi
2123 fi
2124 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -vi "xen" | sort -u | tr '\n' ' '`
2125 noof_kernels=`CountItemsIn "$possible_kernels"`
2126 if [ $KERNEL_IS_XEN = "yes" ]; then
2127 possible_xenkernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -i "xen" | sort -u | tr '\n' ' '`
2128 noof_xenkernels=`CountItemsIn "$possible_xenkernels"`
2129 FindMboot32Binary
2130 fi
2131 if [ "$noof_kernels" -eq "0" ] ; then
2132 LogAll "Could not find your kernel."
2133 if [ -e "/boot/vmlinuz" ] ; then
2134 LogAll "Using /boot/vmlinuz as a last resort."
2135 output=/boot/vmlinuz
2136 else
2137 output=""
2138 fi
2139 elif [ "$noof_kernels" -eq "1" ] ; then
2140 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2141 LogFile "Your kernel is $kernelpath (v$KERVERRUN)"
2142 output="$kernelpath"
2143 else
2144 for i in $possible_kernels ; do
2145 if echo $i | grep "$KERVERRUN" ; then
2146 LogAll "OK, I used my initiative and found that "
2147 LogAll "$i is probably your kernel. "
2148 output="$i"
2149 fi
2150 done
2151 if [ -n "$output" ]; then
2152 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2153 output=/boot/vmlinuz
2154 echo "Schlomo, this one's for you." >> $LOGFILE
2155 else
2156 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2157 LogIt "boot disks will still work, probably. If one does not work, try another."
2158 LogIt "$possible_kernels"
2159 echo ""
2160 fi
2161 fi
2162 fi
2163 if [ $KERNEL_IS_XEN = "yes" ]; then
2164 if [ "$noof_xenkernels" -eq "0" ]; then
2165 xenkernelpath=""
2166 elif [ "$noof_xenkernels" -eq "1" ]; then
2167 xenkernelpath=`echo "$possible_xenkernels" | sed s/' '//`
2168 echo "Your Xen kernel is $xenkernelpath (v$KERVERRUN)" >> $LOGFILE
2169 else
2170 for i in $possible_xenkernels ; do
2171 if echo $i | grep "$KERVERRUN" ; then
2172 LogIt "OK, I used my initiative and found that "
2173 LogIt "$i is probably your Xen kernel. "
2174 xenkernelpath="$i"
2175 fi
2176 done
2177 if [ -n "$xenkernelpath" ]; then
2178 new_possible_xenkernels=`echo "$possible_xenkernels" | tr -s ' ' '\n' | grep -E "^/boot" | sort -u | tr '\n' ' '`
2179 if [ ! -n "$new_possible_xenkernels" ]; then
2180 xenkernelpath=`echo $new_possible_xenkernels | tr -s ' ' '\n' | head -1`
2181 LogIt "Using $xenkernelpath"
2182 else
2183 LogIt "Two or more possible Xen kernels found. You may specify any one of them and the "
2184 LogIt "boot disks will still work, probably. If one does not work, try another."
2185 LogIt "$possible_xenkernels"
2186 echo ""
2187 xenkernelpath=`echo $possible_xenkernels | tr -s ' ' '\n' | head -1`
2188 LogIt "Using $xenkernelpath"
2189 fi
2190 fi
2191 fi
2192 xenkernelname=`basename $xenkernelpath`
2193 if [[ -z "$xenkernelpath" || ! -f "$xenkernelpath" ]]; then
2194 Die "Cannot find Xen kernel $xenkernelpath, aborting"
2195 fi
2196 fi
2197 echo "$output"
2198}
2199
2200
2201TurnTgzIntoRdz() {
2202 local tgz_dir_fname rdz_fname tempfile mountpoint old_pwd nodes kernelsize res currsize not_copied j k s w needed_modules_path
2203
2204 tgz_dir_fname=$1
2205 rdz_fname=$2
2206 kernelsize=$3
2207 # Compute the list of all that should be copied/created on the final mountpoint under MINDI_TMP
2208 # mkdir.lis will contain the list of directries to create
2209 # cp.lis will contain the list of files/dirs to copy
2210 # ln.lis will contain the list of files to link to existing files
2211 # rm.lis will contain the list of files to remove after the copies
2212
2213 # Get kbd conf from data disk preparation
2214 echo $MINDI_CACHE/KEYMAP-LIVES-HERE >> $MINDI_TMP/cp.lis
2215 # AL04Oct08: Check whether /lib64 is a link and if so explicitly create one in rootfs
2216 if [ -h "/lib64" ]; then
2217 echo lib >> $MINDI_TMP/mkdir.lis
2218 echo ln -s lib lib64 >> $MINDI_TMP/ln.lis
2219 fi
2220
2221 # We need a minimal conf in the initial ramdisk
2222 mountlis=`grep -v "^#.*" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | cut -d: -f2 | sort -u`
2223 ReadAllLink $mountlis >> $MINDI_TMP/mnt.lis
2224 LocateDeps `cat $MINDI_TMP/mnt.lis` >> $MINDI_TMP/deps.lis
2225 # Special for libs
2226 ReadAllLink `grep -E "/lib" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | grep -v "^#.*" | cut -d: -f2` >> $MINDI_TMP/deps.lis
2227
2228 echo `cat $MINDI_TMP/mnt.lis` `sort -u $MINDI_TMP/deps.lis` >> $MINDI_TMP/cp.lis
2229 rm -f $MINDI_TMP/deps.lis $MINDI_TMP/mnt.lis
2230
2231 # Copy of files mandatory for ld.so
2232 echo /etc/ld.so.c* >> $MINDI_TMP/cp.lis
2233
2234 # Avoid an issue on some distro (RHEL5)
2235 echo ./etc/ld.so.conf.d/kernelcap* >> $MINDI_TMP/rm.lis
2236
2237 # Need for a tmp dir
2238 echo tmp >> $MINDI_TMP/mkdir.lis
2239
2240 # Management of udev (which includes modprobe in rules)
2241 USE_UDEV=""
2242 ps auxww | grep -v grep | grep -qw udevd
2243 if [ $? -eq 0 ]; then
2244 USE_UDEV="yes"
2245 LogFile "udev device manager found"
2246 echo /etc/udev /lib*/udev >> $MINDI_TMP/cp.lis
2247 # This avoids NIC remapping if on another machine at restore time on Debian at least
2248 echo ./etc/udev/rules.d/z[0-9][0-9]_persistent-net.rules >> $MINDI_TMP/rm.lis
2249 # This avoids NIC remapping if on another machine at restore time on Ubuntu at least
2250 echo ./etc/udev/rules.d/[0-9][0-9]-persistent-net.rules >> $MINDI_TMP/rm.lis
2251 if [ -x /sbin/udevd ]; then
2252 # Get only the files which exist in the udev.files list
2253 # and potentially their symlink structure and their deps
2254 mountlis=`grep -Ev "^#" $MINDI_CONF/udev.files`
2255 ReadAllLink $mountlis | sort -u >> $MINDI_TMP/udev.lis
2256 LocateDeps `cat $MINDI_TMP/udev.lis` | sort -u >> $MINDI_TMP/cp.lis
2257 cat $MINDI_TMP/udev.lis >> $MINDI_TMP/cp.lis
2258 rm -f $MINDI_TMP/udev.lis
2259 else
2260 LogAll "udevd daemon not in standard place (/sbin)"
2261 LogAll "mindi will use static devices which may cause problems"
2262 fi
2263 fi
2264
2265 # Management of potential HW info (Proliant only at the moment)
2266 rm -rf $MINDI_CACHE/bkphw
2267 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2268 if [ -d $MINDI_CACHE/bkphw ]; then
2269 LogAll "Hardware Information found and saved ..."
2270 echo $MINDI_CACHE/bkphw >> $MIDNDI_TMP/cp.lis
2271 if [ -f $MINDI_CACHE/tools.files ]; then
2272 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2273 LocateDeps $lis > $MINDI_TMP/tools.lis
2274 echo $lis `sort -u $MINDI_TMP/tools.lis` >> $MINDI_TMP/cp.lis
2275 fi
2276 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2277 chmod 755 $MINDI_CACHE/mindi-rsthw
2278 echo $MINDI_CACHE/mindi-rsthw >> $MINDI_TMP/cp.lis
2279 fi
2280 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2281 fi
2282
2283 # Management of perl scripts delivered needed at restore time
2284 mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` >> $MINDI_TMP/cp.lis
2285
2286 echo mnt/cdrom >> $MINDI_TMP/mkdir.lis
2287
2288 ls /dev/fd0*[1,2][4,7,8]* >> $MINDI_TMP/cp.lis 2> /dev/null
2289
2290 if [ "${kernelname}" != "" ]
2291 then
2292 needed_modules_path=/lib/modules/${kernelname}
2293 else
2294 needed_modules_path=/lib/modules/$KERVERRUN
2295 fi
2296
2297 needed_modules=""
2298 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
2299
2300 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
2301 # For PXE boot
2302 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2303 fi
2304 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2305 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2306 fi
2307 for i in $DENY_MODS; do
2308 LogFile "Removing $i from the list of modules to load"
2309 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2310 done
2311
2312 [ -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."
2313 for i in $list_of_groovy_mods ; do
2314 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
2315 done
2316
2317 for i in `echo $needed_modules | tr ' ' '\n' | sort -u`; do
2318 grep -qE '^$i$' $MINDI_TMP/cp.lis
2319 if [ $? != 0 ]; then
2320 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2321 LogFile "Adding $i ($s KB) to the rootfs"
2322 echo $i >> $MINDI_TMP/cp.lis
2323 fi
2324 done
2325
2326 # Also copy modules.dep in case of udev so that normal modprobe works
2327 echo $needed_modules_path/modules.dep >> $MINDI_TMP/cp.lis
2328
2329 # Manages mountlit.txt
2330 MakeMountlist $MINDI_CACHE/mountlist.txt
2331 CheckMountlist $MINDI_CACHE/mountlist.txt
2332 echo $MINDI_CACHE/mountlist.txt >> $MINDI_TMP/cp.lis
2333 cat $MINDI_CACHE/mountlist.txt >> $LOGFILE
2334 LogFile "-----------------------------------"
2335
2336 # Copy FW in case some drivers needs it
2337 if [ -d "/lib/firmware" ]; then
2338 echo "lib/firmware" >> $MINDI_TMP/mkdir.lis
2339 echo "/lib/firmware" >> $MINDI_TMP/cp.lis
2340 fi
2341
2342 cd $old_pwd
2343 if [ _"$MONDO_SHARE" != _"" ]; then
2344 MakeMondoConfigFile $MINDI_CACHE/mondorestore.cfg
2345 echo $MINDI_CACHE/mondorestore.cfg >> $MINDI_TMP/cp.lis
2346 LogFile "-----------------------------------"
2347 LogFile "Content of mondorestore.cfg: "
2348 LogFile "-----------------------------------"
2349 cat $MINDI_CACHE/mondorestore.cfg >> $LOGFILE
2350 LogFile "-----------------------------------"
2351 fi
2352 echo proc >> $MINDI_TMP/mkdir.lis
2353
2354 # Copy of files mandatory for ssh to automate mount if sshfs is used
2355 echo .ssh >> $MINDI_TMP/mkdir.lis
2356
2357 # Now create the container and do the job
2358 tempfile=$MINDI_TMP/temp.rd
2359 mountpoint=$MINDI_TMP/mnt1
2360 res=0
2361 echo -en "..."
2362 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk ($tempfile)"
2363 echo -en "..."
2364 LogFile "Creating ext2 filesystem on $tempfile"
2365 mke2fs -b 1024 -m 0 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2366 echo -en "..."
2367 mkdir -p $mountpoint
2368 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."
2369 echo -en "..."
2370 old_pwd=`pwd`
2371
2372 # First create dirs
2373 for d in `cat $MINDI_TMP/mkdir.lis`; do
2374 mkdir -p $mountpoint/$d 2>&1 >> $LOGFILE
2375 done
2376
2377 # Then copy files needed
2378 LANGUAGE=C tar cf - `cat $MINDI_TMP/cp.lis` 2> /dev/null | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
2379
2380 # Then handle links
2381 if [ -f $MINDI_TMP/ln.lis ]; then
2382 (cd $mountpoint ; bash $MINDI_TMP/ln.lis) 2>&1 >> $LOGFILE
2383 fi
2384
2385 # Finally remove useless stff
2386 (cd $mountpoint ; rm -f `cat $MINDI_TMP/rm.lis`) 2>&1 >> $LOGFILE
2387
2388 # Copy of files mandatory for ssh to automate mount if sshfs is used
2389 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2390 cat > $mountpoint/bin/myssh << EOF
2391ssh -o StrictHostKeyChecking=no $*
2392EOF
2393 chmod 755 $mountpoint/bin/myssh
2394
2395 # Finally integrate what we provide statically as part of mindi
2396 (cd $tgz_dir_fname ; LANGUAGE=C tar cf - . ) | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
2397
2398 # Extracting devices
2399 (cd $mountpoint/dev ; tar -zxf dev-entries.tgz) || Die "Cannot untar dev-entries.tgz"
2400 rm -f $mountpoint/dev/dev-entries.tgz
2401
2402 LogFile "---------------------------"
2403 LogFile "Content of initial ramdisk:"
2404 LogFile "---------------------------"
2405 (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2406 LogFile "---------------------------"
2407
2408 # Determine what filesystem to use for initrd image
2409 LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
2410 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2411 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2412 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ]; then
2413 # say what will be used
2414 LogFile "Creating an $gvFileSystem initrd image..."
2415 # kernel expects linuxrc in ext2 filesystem
2416 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2417 # unmount loop filesystem and create image file using the standard approach
2418 umount $mountpoint || Die "Cannot unmount $tempfile"
2419 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
2420 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
2421 MINDI_ADDITIONAL_BOOT_PARAMS="$MINDI_ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2422 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
2423 rm -f ${rdz_fname}.tmp
2424 # log that we are done
2425 LogFile "...done."
2426 elif [ "$gvFileSystem" = "initramfs" ]; then
2427 # say what will be used
2428 LogFile "Creating a gzip'ed cpio (AKA initramfs) initrd image..."
2429 # make sure that cpio is there
2430 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2431 # go into filesystem
2432 cd $mountpoint
2433 # kernel expects init in cpio filesystem
2434 ln -sf sbin/init init
2435 # create cpio image file and unmount loop filesystem
2436 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
2437 cd $old_pwd
2438 umount $mountpoint || Die "Cannot unmount $tempfile"
2439 # log that we are done
2440 LogFile "...done."
2441 else
2442 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2443 fi
2444 ls -al $MINDI_TMP/initrd.img > /tmp/initrd.log
2445
2446 if [ "$res" -eq "0" ] ; then
2447 echo -en "..."
2448 else
2449 echo -en "\rMade an rdz WITH ERRORS. \n"
2450 fi
2451 return 0
2452}
2453
2454
2455##############################################################################
2456#----------------------------------- Main -----------------------------------#
2457##############################################################################
2458
2459# Now we can create what we need
2460mkdir -p $MINDI_TMP
2461
2462# Purge from potential old run
2463if [ _"$MINDI_CACHE" = _"" ]; then
2464 Die "MINDI_CACHE undefined"
2465fi
2466
2467if [ "$1" = "--printvar" ] ; then
2468 shift
2469 if [ _"$1" != _"" ] ; then
2470 set | grep -Ew "^$1" | cut -d= -f2
2471 fi
2472 exit 0
2473fi
2474
2475> $LOGFILE
2476LogFile "mindi v$MINDI_VERSION"
2477LogFile "$ARCH architecture detected"
2478LogFile "mindi called with the following arguments:"
2479LogFile "$*"
2480LogFile "Start date : `date`"
2481LogFile "-----------------------------"
2482
2483# Log some capital variables
2484[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2485[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2486LogFile "MONDO_SHARE = $MONDO_SHARE"
2487LogFile "MINDI_DATA = $MINDI_DATA"
2488LogFile "MINDI_SBIN = $MINDI_SBIN"
2489LogFile "MINDI_CONF = $MINDI_CONF"
2490if [ -f $MINDI_CONFIG ]; then
2491 LogFile "-----------------------------"
2492 LogFile " Mindi configuration file "
2493 LogFile "-----------------------------"
2494 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
2495 LogFile "-----------------------------"
2496fi
2497
2498
2499trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2500
2501# Sanity checks
2502which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2503which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2504which 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."
2505which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2506if which awk &> /dev/null ; then
2507 if ! which gawk &> /dev/null ; then
2508 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"
2509 fi
2510fi
2511which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2512[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
2513
2514[ "`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"
2515
2516# Update the PATH variable if incomplete
2517if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2518 PATH=$PATH:/sbin:/usr/sbin
2519 export PATH
2520 LogFile "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily."
2521 LogFile "However, you may wish to ask your vendor to provide a permanent fix..."
2522 LogFile " Or you might like to call 'su -' instead of 'su', for example."
2523fi
2524
2525if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
2526 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2527fi
2528
2529### TODO
2530### Fix as it's not mandatory on ia64
2531if [ "$ARCH" = "ia64" ] ; then
2532 if which elilo &> /dev/null ; then
2533 LILO_EXE=elilo
2534 else
2535 LILO_EXE=`which false 2> /dev/null`
2536 fi
2537else
2538 FindIsolinuxBinary
2539fi
2540trap "Aborted" SIGTERM
2541DONE="\r\t\t\t\t\t\t\t\tDone. "
2542kernelpath=""
2543
2544if [ -d "/proc/lvm" ]; then
2545 # LVM v1
2546 LVMCMD=""
2547 LVM="v1"
2548elif [ -d "/dev/mapper" ]; then
2549 # LVM v2
2550 LVMCMD="lvm"
2551 LVM="v2"
2552else
2553 LVM="false"
2554fi
2555
2556if [ -e "/proc/cmdline" ]; then
2557 CMDLINE="/proc/cmdline"
2558elif [ -e "/tmp/cmdline" ]; then
2559 CMDLINE="/tmp/cmdline"
2560else
2561 CMDLINE="/dev/null"
2562fi
2563
2564LogFile "LVM set to $LVM"
2565LogFile "----------"
2566LogFile "mount result:"
2567LogFile "-------------"
2568mount >> $LOGFILE
2569LogFile "-------------"
2570if [ -e /etc/raidtab ]; then
2571 LogFile "-------------"
2572 LogFile "/etc/raidtab content:"
2573 LogFile "-------------"
2574 cat /etc/raidtab >> $LOGFILE
2575fi
2576LogFile "-------------"
2577LogFile "cat $CMDLINE"
2578LogFile "-------------"
2579cat $CMDLINE >> $LOGFILE
2580LogFile "-------------"
2581LogFile "cat /proc/swaps:"
2582LogFile "-------------"
2583cat /proc/swaps >> $LOGFILE
2584LogFile "-------------"
2585LogFile "cat /proc/partitions:"
2586LogFile "-------------"
2587cat /proc/partitions >> $LOGFILE
2588LogFile "-------------"
2589LogFile "cat /proc/filesystems:"
2590LogFile "-------------"
2591cat /proc/filesystems >> $LOGFILE
2592LogFile "-------------"
2593LogFile "lsmod result:"
2594LogFile "-------------"
2595lsmod >> $LOGFILE
2596MODULES="`cat /proc/modules | $AWK '{print $1}'`"
2597if [ -x /usr/sbin/esxcfg-module ]; then
2598 LogFile "-------------"
2599 LogFile "VMWare ESX server detected - Enabling dedicated support"
2600 LogFile "-------------"
2601 LogFile "VMWare modules"
2602 LogFile "-------------"
2603 /usr/sbin/esxcfg-module -l >> $LOGFILE
2604 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
2605fi
2606LogFile "FORCE_MODS:"
2607LogFile "-------------"
2608LogFile $FORCE_MODS
2609LogFile "-------------"
2610LogFile "DENY_MODS:"
2611LogFile "-------------"
2612LogFile $DENY_MODS
2613LogFile "-------------"
2614LogFile "df result:"
2615LogFile "----------"
2616df -T >> $LOGFILE
2617LogFile "-------------"
2618LogFile "Liste of extra modules is:"
2619LogFile "-------------"
2620LogFile "$EXTRA_MODS"
2621LogFile "-------------"
2622
2623# Compute libata version
2624laver=`modinfo libata 2> /dev/null | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
2625# If libata v2 is used then remove ide-generic as it will perturbate boot
2626if [ "`echo $MODULES | grep libata`" ]; then
2627 if [ "$laver" = "2" ]; then
2628 DENY_MODS="$DENY_MODS ide-generic"
2629 LogFile "ide-generic removed from module list as your system uses libata v2+"
2630 LogFile "-------------"
2631 fi
2632fi
2633
2634# Check for ISO_CMD command
2635if [ ! -x $ISO_CMD ]; then
2636 echo "NOTE: No CD image (ISO file) utility found" >> $LOGFILE
2637fi
2638
2639FLOPPY_WAS_MOUNTED=""
2640for mtpt in /media/floppy /mnt/floppy /floppy ; do
2641 if mount | grep -w $mtpt &> /dev/null ; then
2642 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2643 umount $mtpt
2644 fi
2645done
2646
2647#
2648# If we have a USB device we need to store info
2649# and remove it from the parameters line
2650#
2651if [ "$#" -ne "0" ] ; then
2652 if [ "$1" = "--usb" ] ; then
2653 shift
2654 USBDEVICE=$1
2655 if [ _"$USBDEVICE" = _"" ]; then
2656 Die "No USB device specified"
2657 fi
2658 shift
2659 fi
2660fi
2661
2662if [ "$#" -ne "0" ] ; then
2663 if [ "$1" = "--findkernel" ] ; then
2664 res=`TryToFindKernelPath`
2665 # Avoids logfile content for mondo
2666 export MONDO_SHARE=""
2667 if [ "$res" = "" ] ; then
2668 MindiExit -1
2669 else
2670 echo "$res"
2671 MindiExit 0
2672 fi
2673 elif [ "$1" = "--locatedeps" ] ; then
2674 [ ! "$2" ] && Die "Please specify the binary to look at"
2675 LocateDeps $*
2676 # Avoids logfile content for mondo
2677 export MONDO_SHARE=""
2678 MindiExit $?
2679 elif [ "$1" = "--readalllink" ] ; then
2680 [ ! "$2" ] && Die "Please specify the binary to look at"
2681 shift
2682 ReadAllLink $*
2683 # Avoids logfile content for mondo
2684 export MONDO_SHARE=""
2685 MindiExit $?
2686 elif [ "$1" = "--makemountlist" ] ; then
2687 [ ! "$2" ] && Die "Please specify the output file"
2688 MakeMountlist $2
2689 CheckMountlist $2
2690 # Avoids logfile content for mondo
2691 export MONDO_SHARE=""
2692 MindiExit $?
2693 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2694 echo "Mindi v$MINDI_VERSION"
2695 # Avoids logfile content for mondo
2696 export MONDO_SHARE=""
2697 MindiExit 0
2698 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
2699 MONDO_TMP=$2
2700 # Change MINDI_TMP for the one provided by mondo
2701 # So that it can get back the built files
2702 if [ _"$MONDO_TMP" = _"" ]; then
2703 Die "MONDO_TMP is empty, aborting"
2704 fi
2705 if [ _"$MONDO_TMP" = _"/" ]; then
2706 Die "MONDO_TMP is /, aborting"
2707 fi
2708 rmdir $MINDI_TMP
2709 export MINDI_TMP=$MONDO_TMP
2710 mkdir -p $MINDI_TMP
2711
2712 # This is the scratch dir in mondo - subdir images
2713 # Now useless
2714 #MINDI_CACHE=$3
2715
2716 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
2717 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
2718
2719###
2720### Sq-Modification...
2721### Attempt to locate kernel specific module path
2722### if module path is found then use it other wise use uname -r to set it...
2723###
2724 if [ $KERNEL_IS_XEN = "yes" ]; then
2725 LogAll "xenkernelpath = $xenkernelpath"
2726 LogAll "xenkernelname = $xenkernelname"
2727 fi
2728 kernelname=`echo $kernelpath | cut -d'-' -f2- | sed 's/.[bg]z[2]*$//'`
2729 if [ ! -d "/lib/modules/$kernelname" ]
2730 then
2731 LogAll "Module path for ${kernelpath} not found..."
2732 LogAll "using running kernel\'s modules."
2733 kernelname=$KERVERRUN
2734 else
2735 LogAll "Using modules for kernel: ${kernelname}"
2736 fi
2737 LogAll "kernelname = $kernelname"
2738 LogAll "kernelpath = $kernelpath"
2739###
2740### end of Sq-Modification
2741###
2742 TAPEDEV=$5
2743 TAPESIZE=$6
2744 FILES_IN_FILELIST=$7
2745 USE_LZO=$8
2746 CDRECOVERY=$9
2747 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
2748 IMAGE_DEVS=""
2749 else
2750 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
2751 fi
2752 if [ "${11}" ] ; then
2753 LILO_OPTIONS=""
2754 # LogAll "LILO will use conservative settings, to be compatible with older BIOSes."
2755 fi
2756 ESTIMATED_TOTAL_NOOF_SLICES=${12}
2757 export MINDI_EXCLUDE_DEVS="${13}"
2758 USE_COMP="${14}"
2759 USE_LILO="${15}"
2760 USE_STAR="${16}"
2761 INTERNAL_TAPE_BLOCK_SIZE="${17}"
2762 DIFFERENTIAL="${18}"
2763 USE_GZIP="${19}"
2764 USE_LZMA="${20}"
2765 BACKUP_MEDIA_TYPE="${21}"
2766 [ "$USE_COMP" = "" ] && USE_COMP=yes
2767 [ "$USE_GZIP" = "" ] && USE_GZIP=no
2768 [ "$USE_LZMA" = "" ] && USE_LZMA=no
2769 [ "$TAPEDEV" ] && LogAll "This is a tape-based backup. Fine."
2770
2771 MONDO_CACHE=/var/cache/mondo
2772 mkdir -p $MONDO_CACHE
2773 else
2774 LogScreen "Syntax: mindi (--custom ....)"
2775 MindiExit -1
2776 fi
2777fi
2778
2779if [ _"$MINDI_CACHE" != _"" ]; then
2780 rm -rf $MINDI_CACHE/* 2> /dev/null
2781 mkdir -p $MINDI_CACHE
2782fi
2783
2784[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2785
2786LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
2787LogAll "Latest Mindi is available from http://www.mondorescue.org"
2788LogAll "------------------------------------------------------------------------------"
2789LogFile "DIFFERENTIAL = $DIFFERENTIAL"
2790LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
2791
2792if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2793 LogAll "Including the generation of a Bootable USB device on $USBDEVICE"
2794fi
2795
2796if [ "$kernelpath" = "" ] ; then
2797 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
2798 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2799 read ch
2800 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2801 USE_OWN_KERNEL="yes"
2802 else
2803 USE_OWN_KERNEL="no"
2804 fi
2805 if [ "$USE_OWN_KERNEL" = "yes" ]; then
2806 kernelpath=`TryToFindKernelPath`
2807 if [ "$kernelpath" = "" ] ; then
2808 echo -n "Please enter kernel path : "
2809 read kernelpath
2810 fi
2811 fi
2812fi
2813LogFile "Mindi's temp dir=$MINDI_TMP"
2814LogFile "Mindi's output dir=$MINDI_CACHE"
2815[ "$(($RANDOM%64))" -eq "0" ] && LogAll "Dude, I've looked inside your computer and it's really dusty..."
2816
2817PrepareDataDiskImages
2818
2819export ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
2820
2821LogFile "Ramdisk will be $ramdisk_size KB"
2822PrepareBootDiskImage $kernelpath || Die "Failed to create $ramdisk_size MB disk image."
2823
2824[ -e "$MINDI_DATA/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
2825...Or type 'memtest' to test your PC's RAM thoroughly.\n"
2826
2827if [ _"$MONDO_SHARE" = _"" ]; then
2828 ListImagesForUser
2829 OfferToMakeBootableISO
2830 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
2831 OfferToMakeBootableUSB
2832 fi
2833 LogAll "Finished."
2834elif [ "$TAPEDEV" ] ; then
2835 if [ "$ARCH" != "ia64" ] ; then
2836 # We need to keep the img file as boot file for ia64 platform
2837 rm -f $MINDI_CACHE/{*img,*iso}
2838 else
2839 rm -f $MINDI_CACHE/*iso
2840 fi
2841 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2842 OfferToMakeBootableUSB
2843 fi
2844 OfferToMakeBootableISO
2845 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
2846 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
2847 else
2848 Die "Cannot find all.tar.gz, to be written to tape"
2849 fi
2850elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2851 OfferToMakeBootableUSB
2852else
2853 OfferToMakeBootableISO
2854fi
2855# cleanup
2856LogAll "$FRIENDLY_OUTSTRING"
2857for mtpt in $FLOPPY_WAS_MOUNTED ; do
2858 mount $mtpt
2859done
2860MindiExit 0
Note: See TracBrowser for help on using the repository browser.