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

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

svn merge -r 2545:2567 /mondorescue/branches/2.2.9

  • Improve device exclusion for LVM by adding support for symlinks and mapper systematically at all levels (PV, VG, LV). Shoul

d really provvide the best support possible for LVM exclusion.

  • Now supports also exclusion of LVs directly
  • Improve mindi by handling excluded devices earlier in the loop.
  • Fix LV exclusion when VGs are excluded (the excludedvgs file has to be removed at start and end of analyze-my-lvm not in fu

nctions, as they are called multiple times)

  • Rename some variables exported to avoid accidental conflict (EXCLUDE_DEVS => MINDI_EXCLUDE_DEVS and ADDITIONAL_BOOT_PARAMS

=> MINDI_ADDITIONAL_BOOT_PARAMS)

  • setfattr also needs the -h flag to restore attributes on symlinks, not on the target file (which may not exist BTW). Should solve #388.
  • Using forcemods="mod1 mod2" will now do something and load those modules first
  • Update web page on distributions to download
  • Add support for ums_cypress module in mindi
  • Fix acl backup which was completely wrong.
  • Fix a bug where LV were not created anymore if no exclusion !!
  • In analyze-my-lvm only use pv.tmp2 when it exists to avoid error msgs

-Adds support for links to modules (.ko pointing to .o) such as with VMWare extensions

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