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

Last change on this file since 2635 was 2635, checked in by Bruno Cornec, 14 years ago

svn merge -r 2586:2634 svn+ssh://bruno@svn.mondorescue.org/mondo/svn/mondorescue/branches/2.2.9

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