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

Last change on this file since 2481 was 2481, checked in by Bruno Cornec, 14 years ago
  • If using nolvm, mondorestore should also not analyze and handle i-want-my-lvm
  • Add support for diskdumplib driver useful for RHEL 3 and IBM xseries 336
  • Fix #367 - the for loop doesn't make any test now, as it was computed before entering the loop, leading to a

n error, and was also made inside the loop anyway.

  • Adds a nolvm boot option at restore time
  • small improvement for loging in USB case

(merge from 2.2.9 2475:2480)

  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 97.4 KB
Line 
1#!/bin/bash
2
3# $Id: mindi 2481 2009-11-12 01:33:39Z 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
22ADDITIONAL_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"
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"
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 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" > $bigdir/tmp/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" > $bigdir/tmp/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" > $bigdir/tmp/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 modpaths=`find $1 -name $2.*o -type f`
442 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
443 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
444 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
445 echo "$modpaths"
446}
447
448
449GenerateGiantDependencyList() {
450 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
451
452 echo -en "Analyzing dependency requirements"
453 outfile=$1
454 tempfile=$MINDI_TMP/$$.txt
455 incoming=`ReadLine`
456
457 > $tempfile
458 progress=0
459 res=0
460 noof_lines=$2
461 while [ "$incoming" != "" ] ; do
462 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
463 incoming=`ReadLine`
464 continue
465 fi
466 if [ "$incoming" = "LVMFILES:" ] ; then
467 break
468 fi
469 filelist=`GenerateListForFile "$incoming"`
470 r=$?
471 [ "$r" -ne "0" ] && LogAll "$incoming not found"
472 res=$(($res+$r))
473# LogFile "'$incoming' generates filelist '$filelist'"
474 for fname in $filelist ; do
475 [ "$fname" != "" ] && echo "$fname" >> $tempfile
476 done
477 progress=$(($progress+1))
478 LogProgress $progress $noof_lines
479 incoming=`ReadLine`
480 done
481 if [ "$incoming" = "LVMFILES:" ] ; then
482 incoming=`ReadLine`
483 lvmversion=""
484 while [ "$incoming" != "" ] ; do
485 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
486 incoming=`ReadLine`
487 continue
488 fi
489 filelist=`GenerateListForFile "$incoming"`
490 for tool in $filelist ; do
491 lvmresolved=`readlink -f $tool`
492 if [ "$tool" = "$lvmresolved" ]; then
493 echo "$tool" >> $tempfile
494 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
495 if [ "$lvmversion" = "" ] ; then
496 lvmversion=`$lvmresolved`
497 echo "$lvmresolved" >> $tempfile
498 fi
499 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
500 if [ "$lvmversion" = "200" ]; then
501 # pvdata and lvmcreate_initrd don't exist in LVM2
502 case "$toolstripped" in
503 "pvdata")
504 continue
505 ;;
506 "lvmcreate_initrd")
507 continue
508 ;;
509 esac
510 fi
511 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
512 if [ -e "$toolpath" ] ; then
513 echo "$toolpath" >> $tempfile
514 echo "$tool" >> $tempfile
515 else
516 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
517 fi
518 if [ -e "$toolpath" ] ; then
519 echo "$toolpath" >> $tempfile
520 echo "$tool" >> $tempfile
521 else
522 echo "Where are your LVM-Tools? Couldn't find $tool"
523 fi
524 else
525 echo "$tool" >> $tempfile
526 fi
527 done
528 progress=$(($progress+1))
529 LogProgress $progress $noof_lines
530 incoming=`ReadLine`
531 done
532 fi
533 echo -en "$DONE\nMaking complete dependency list"
534
535 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
536 mv -f $tempfile.new $tempfile
537 > $outfile.pre
538 progress=0
539 noof_lines=`cat $tempfile | wc -l`
540 LogFile "---------------------------------"
541 LogFile "List of dependencies: "
542 LogFile "---------------------------------"
543 for fname in `cat $tempfile` ; do
544 echo "$fname" | tee -a $LOGFILE >> $outfile.pre
545 LocateDeps $fname | tee -a $LOGFILE >> $outfile.pre
546 progress=$(($progress+1))
547 LogProgress $progress $noof_lines
548 done
549 if [ _"$MONDO_SHARE" != _"" ]; then
550 mkdir -p $bigdir/tmp
551 mkdir -p $bigdir/sbin
552 mkdir -p $bigdir/bin
553 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
554 LogAll "\nIncorporating post-nuke tarball"
555 old_pwd=`pwd`
556 cd $bigdir
557 tar -zxf $MINDI_TMP/post-nuke.tgz 2>> $MINDI_TMP/$$.log || LogAll "Error occurred when untarring post-nuke tarball" $MINDI_TMP/$$.log
558 cd $old_pwd
559 fi
560 cp -f $MINDI_TMP/BOOTLOADER.* $bigdir 2>> $LOGFILE || LogAll "\nMondo v1.2x defaults to LILO as the bootloader, BTW."
561 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
562 LogAll "\nIncorporating NFS-related settings"
563 for r in NETFS-* ; do
564 cp -f $MINDI_TMP/$r $bigdir/tmp 2>> $LOGFILE || Die "Cannot copy $r - did you run out of disk space?"
565 LogFile "Copying $r to ramdisk"
566 done
567 fi
568 fi
569 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
570 rm -f $tempfile $outfile.pre
571 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
572 return $res
573}
574
575
576GenerateListForFile() {
577 local files_found loc fname incoming i res
578 incoming="$1"
579 files_found=""
580 res=0
581
582 for fname in $incoming ; do
583 files_found="$files_found `LocateFile $fname`"
584 done
585
586 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
587}
588
589
590# Returns all disk devices which are part of a raid array
591GetAllRaidMembers() {
592 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
593}
594
595
596GetFileSizeList() {
597 local i
598 for i in `find $1 -type d -o -print` ; do
599 du -sk $i
600 done
601}
602
603
604GetHomeDir() {
605 local res loc
606 loc=`which $1 2>/dev/null`
607 res=`file $loc | $AWK '{print $NF;}'`
608 dirname $res
609}
610
611
612# Check kernel filesystem capabilites for accessing initrd image
613# Could be ext2 FS (old mode) or initramfs (new mode)
614#
615# Interface definition:
616# param #1: absolute path to kernel image
617GetInitrdFilesystemToUse() {
618
619 # interface test: make sure we have one parameter
620 if [ $# -ne 1 ]; then
621 Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
622 fi
623
624 # interface parameters
625 local lvKernelImage=$1
626
627 # local constants (filesystem magic strings)
628 local lcMagicCramfs="<3>cramfs: wrong magic"
629 local lcMagicExt2fs="EXT2-fs: blocksize too small for device."
630 local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device."
631 local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs...|<6>Trying to unpack rootfs image as
632initramfs"
633
634 # local variables
635 local lvOffset
636 local lvScanRes
637 local lvUseFilesystem
638
639 # say where we are.
640 LogFile " GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n"
641
642 # verify that file exists
643 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
644
645 # Kernel may be gzip compressed
646 file $lvKernelImage 2>&1 | grep -q gzip
647 if [ $? -eq 0 ]; then
648 lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicExt3fs|$lcMagicInitfs"`
649
650 # determine which filesystem to use for initrd image: ext2|3fs, gzip'ed cpio (initramfs) or cramfs
651 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then
652 lvUseFilesystem="ext2fs"
653 elif [ `echo $lvScanRes | grep -Ec "$lcMagicExt3fs"` -eq 1 ]; then
654 lvUseFilesystem="ext3fs"
655 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then
656 lvUseFilesystem="initramfs"
657 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then
658 lvUseFilesystem="cramfs"
659 else
660 lvUseFilesystem="UNSUPPORTED"
661 fi
662
663 else
664 # In that case, we are after 2.6.30 and use the supported initramfs
665 lvUseFilesystem="initramfs"
666 fi
667 # say what we are using
668 LogFile " GetInitrdFilesystemToUse(): Filesytem to use for initial ramdisk is $lvUseFilesystem.\n"
669
670 # return file system to use
671 echo "$lvUseFilesystem"
672
673}
674
675# Searches parent raid device of given disk device
676# $1: disk device (i.e. /dev/hda1)
677GetParentRaidDev() {
678 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
679}
680
681
682# Searches members of raid device
683# $1: raid device (/dev/md...)
684GetRaidDevMembers() {
685 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
686}
687
688
689ListAllPartitions() {
690 local res currline partition all_partitions ap_orig remaining i j
691
692 grep -Evx " *#.*| *none.*" $MY_FSTAB | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/\/fdd|\/cdr|\/zip|\/floppy/ {print $1}'
693 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
694 if [ -e "/vmfs/volumes" ]; then
695 # For VMWare ESX 3 get the device names of these volumes
696 vdf -P | grep -E '/vmfs/volumes' | $AWK '{print $1}'
697 fi
698 return
699}
700
701
702ListImagesForUser() {
703 local path fname
704 path=$MINDI_CACHE
705 echo -en "In the directory '$path' you will find the images:-\n"
706 for fname in `ls $path | grep -F mindi-` ; do
707 printf "%19s " $fname
708 done
709 echo " "
710}
711
712
713ListKernelModulePaths() {
714 local module_list module fname oss r kern
715 outfile=$1
716 echo -en "Analyzing modules requirements"
717 oss="/root/oss/modules"
718 module_list="$MODULES"
719 # Remove unwanted modules from list
720 for i in $DENY_MODS; do
721 module_list=`echo ${module_list} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
722 EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
723 done
724###
725### Sq-Modification ... Use kernelname for module search path if specified
726###
727 if [ "${kernelname}" != "" ]
728 then
729 kern=${kernelname}
730 else
731 kern="$KERVERRUN"
732 fi
733 export KERVER=$kern
734###
735### Sq-Mod End
736###
737 noof_lines=0
738 # Get rid of duplicates, so that if a live kernel module also appears
739 # in $EXTRA_MODS that it won't get reported as "live module file not found" twice.
740 for module in `echo $module_list $EXTRA_MODS | tr ' ' '\n' | sort -u` ; do
741 noof_lines=$(($noof_lines+1))
742 done
743 progress=0
744 for module in `echo $module_list $EXTRA_MODS | tr ' ' '\n' | sort -u` ; do
745 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
746 if [ -z "$r" ]; then
747 if [ "`echo "$MODULES" | grep -w $module`" ]; then
748 r="[live module file not found]"
749 else
750 r="[extra module file not found]"
751 fi
752 fi
753 LogFile "module $module --> $r"
754 [ "$r" ] && echo "$r" >> $outfile
755 [ -f "$oss" ] && find $oss | grep -F $module >> $outfile
756 progress=$(($progress+1))
757 LogProgress $progress $noof_lines
758 done
759 find /lib/modules/$kern/modules.* -type f 2> /dev/null >> $outfile
760 [ -f "$oss" ] && find $oss.* 2> /dev/null >> $outfile
761}
762
763#
764# Critical function which computes all dependencies (dyn. lib.)
765# for a list of binaries
766#
767LocateDeps() {
768 local incoming fname deps
769 incoming="$*"
770 for fname in $incoming ; do
771 if [ ! -e "$fname" ] ; then
772 LogFile "WARNING - $fname does not exist; cannot be LDD'd."
773 if echo $fname | grep lvm &> /dev/null ; then
774 LogFile "This warning only affects you if you are using LVM."
775 if echo "$MODULES" | grep lvm &> /dev/null ; then
776 LogFile "I think you are, so please take heed!"
777 else
778 LogFile "I don't think you are, so don't worry about it."
779 fi
780 fi
781 elif [ -h "$fname" ] && [ -x "$fname" ] ; then
782 LogFile "$fname is softlink"
783 else
784 ldd $fname 2> /dev/null | ProcessLDD
785 fi
786 done
787}
788
789
790# Give all symlinks recursively of a full path name
791ReadAllLink() {
792
793 incoming="$*"
794
795 for file in $incoming ; do
796 if [ ! -f $file ]; then
797 continue
798 fi
799 echo "$file"
800 if [ ! -h $file ]; then
801 continue
802 fi
803
804 link=`readlink -e $file`
805 d=`dirname $file`
806 fchar=`echo $link | cut -c1`
807 # If mother dir is a link print it
808 if [ -h "$d" ]; then
809 echo "$d"
810 d=`readlink -e $d`
811 fi
812 if [ "$fchar" != "/" ]; then
813 # Relative or local link
814 ReadAllLink "$d/$link"
815 else
816 # Absolute path
817 ReadAllLink $link
818 fi
819 done
820}
821
822
823LocateFile() {
824 local i path fname_to_find location output resolved tmp stub cache_id loclist
825 fname_to_find="$1"
826 # It's an absolute path
827 if echo "$fname_to_find" | grep -x "/.*" ; then
828 output="$fname_to_find"
829 if [ -h "$output" ] ; then
830 output="`ReadAllLink $output` $output"
831 fi
832 echo "$output"
833 return 0
834 fi
835 # It's not an absolute path
836 output=""
837 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
838 #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
839 [ -h "$path" ] && continue
840 [ ! -e "$path/$fname_to_find" ] && continue
841 output="$path/$fname_to_find $output"
842 if [ -h "$path/$fname_to_find" ] ; then
843 output="`ReadAllLink $path/$fname_to_find` $output"
844 fi
845 done
846 if [ "$output" = "" ] ; then
847 return 1
848 fi
849 echo "$output"
850 return 0
851}
852
853LogProgress() {
854 local i progress modres noof_lines
855
856 progress=$1
857 noof_lines=$2
858
859 echo -en "\r\t\t\t\t\t\t\t\t"
860 i=$(($progress*100))
861 i=$(($i/$noof_lines))
862 echo -en "$i"
863 echo -en "%"
864 modres=$(($progress%4))
865 [ "$modres" -eq "0" ] && echo -en "\t/"
866 [ "$modres" -eq "1" ] && echo -en "\t-"
867 [ "$modres" -eq "2" ] && echo -en "\t\\"
868 [ "$modres" -eq "3" ] && echo -en "\t|"
869}
870
871# Function to log on screen only
872LogScreen() {
873 if [ -e /dev/stderr ] ; then
874 echo -e "$1" >> /dev/stderr
875 elif [ -e /usr/bin/logger ] ; then
876 /usr/bin/logger -s $1
877 fi
878}
879
880# Function to log in log file only
881LogFile() {
882
883 echo -e "$1" >> $LOGFILE
884 if [ _"$2" != _"" ]; then
885 grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
886 fi
887 rm -f "$2"
888}
889
890# Function to log in both screen and logfile
891LogAll() {
892 LogScreen "$1"
893 LogFile "$1" "$2"
894}
895
896
897# Called by TurnTgzIntoRdz, to make mondorestore.cfg
898MakeMondoConfigFile() {
899 local outfile use_lzo use_comp use_star
900 outfile=$1
901 > $outfile
902 [ "$TAPESIZE" ] && echo "media-size $TAPESIZE" >> $outfile
903 [ "$TAPEDEV" ] && echo "media-dev $TAPEDEV" >> $outfile
904 [ "$USBDEVICE" ] && echo "usb-dev $USBDEVICE" >> $outfile
905 [ "$FILES_IN_FILELIST" ] && echo "files-in-filelist $FILES_IN_FILELIST" >> $outfile
906 [ "$LAST_FILELIST_NUMBER" ] && echo "last-filelist-number $LAST_FILELIST_NUMBER" >> $outfile
907 [ "$INTERNAL_TAPE_BLOCK_SIZE" ] && echo "internal-tape-block-size $INTERNAL_TAPE_BLOCK_SIZE" >> $outfile
908 use_lzo=$USE_LZO; [ "$use_lzo" = "" ] && use_lzo="no"
909 use_gzip=$USE_GZIP; [ "$use_gzip" = "" ] && use_gzip="no"
910 use_lzma=$USE_LZMA; [ "$use_lzma" = "" ] && use_lzma="no"
911 use_comp=$USE_COMP; [ "$use_comp" = "" ] && use_comp="yes"
912 use_star=$USE_STAR; [ "$use_star" = "" ] && use_star="no"
913 echo "use-lzo $use_lzo" >> $outfile
914 echo "use-lzma $use_lzma" >> $outfile
915 echo "use-star $use_star" >> $outfile
916 echo "use-comp $use_comp" >> $outfile
917 echo "datestamp `date`" >> $outfile
918 [ "$ESTIMATED_TOTAL_NOOF_SLICES" ] && echo "total-slices $ESTIMATED_TOTAL_NOOF_SLICES" >> $outfile
919 AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-MOUNT netfs-server-mount $outfile
920 AddFileToCfgIfExists $MINDI_TMP/NETFS-SERVER-PATH netfs-server-path $outfile
921 AddFileToCfgIfExists $MINDI_TMP/NETFS-DEV netfs-dev $outfile
922 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
923 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME bootloader.name $outfile
924 AddFileToCfgIfExists $MINDI_TMP/KEYMAP-LIVES-HERE keymap-lives-here $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 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
963 fi
964 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
965# echo "all partitions = $all_partitions" > /dev/stderr
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 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1157 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1158 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1159 # the former is then a link to the latter, so we test whether
1160 # $current_partition is actually such a link or not and set
1161 # $current_lvolume accordingly. On Debian you may find more than one answer
1162 # so we remove the one corresponding to /dev/.static
1163 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1164 # principle is the same and we need to find the link to it as well.
1165 # Note that $current_lvolume may well be an
1166 # ordinary device. It is just to make sure that we feed the right value
1167 # into any of the LVM tools if possible.
1168
1169 current_lvolume="$current_partition"
1170 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
1171 # .static dir are a Debian specificity
1172 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
1173 echo $current_lvolume | grep -q ' '
1174 if [ $? -eq 0 ]; then
1175 LogFile "WARNING: Multiple Logical Volumes found. Report to dev team"
1176 fi
1177 # if it's not found, it may well be a real device such as a multipath one
1178 # /dev/mapper/mpath... Thus we revert the situation so that next test succeed
1179 if [ _"$current_lvolume" = _"" ]; then
1180 current_lvolume="$current_partition"
1181 fi
1182 fi
1183 #
1184 # End of LVM device style variation code (other than $current_lvolume).
1185
1186 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1187 # Size computed via LVM not directly
1188 partition_size="lvm"
1189 else
1190 partition_size=`SizeOfPartition $current_partition`
1191 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1192 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1193 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1194 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1195 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1196 [ "$partition_format" != "swap" ] && partition_format="swap"
1197 if [ "$partition_size" = "" ] ; then
1198 totalsize=0
1199 items=0
1200 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1201 totalsize=$(($totalsize+$i))
1202 items=$(($items+1))
1203 done
1204 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1205 [ "$partition_size" -lt "125000" ] && partition_size=125000
1206 LogFile "I'm guessing $c_p is $(($partition_size/1024))MB"
1207 fi
1208 fi
1209 fi
1210 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1211 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1212 if [ "$partition_mountpt" = "" ] ; then
1213 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1214 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1215 partition_mountpt="raid"
1216 partition_format="raid"
1217 else
1218 partition_mountpt="lvm"
1219 partition_format="lvm"
1220 fi
1221 fi
1222 fi
1223 psz=$partition_size
1224 LogFile "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)"
1225 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1226 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1227 partition_mountpt="image"
1228 old_partition_fmt=$partition_format
1229 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1230 partition_size=$(($partition_size+1)); # just in case
1231 if [ "$partition_format" = "Linux" ] ; then
1232 LogFile "Are you imaging a mounted swap partition? Silly..."
1233 LogFile "Reverting format from $old_partition_fmt to $partition_format"
1234 partition_format=$old_partition_fmt
1235 fi
1236 fi
1237 if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then
1238 LogFile "Excluding $current_partition from mountlist"
1239 continue
1240 fi
1241 if [ ! "$partition_mountpt" ] ; then
1242 LogFile "------- $FDISK -l $qq log ------------"
1243 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
1244 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1245 [ "$partition_format" ] && break
1246 done
1247 LogFile "------- $FDISK log end ------------"
1248 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1249 partition_format="compaq"
1250 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1251 LogAll "Unable to find mountpoint of $current_partition - ignoring"
1252 continue
1253 fi
1254 fi
1255 if [ "$redhat_label" ]; then
1256 label="$redhat_label"
1257 elif [ "$uuid" ]; then
1258 label="$uuid"
1259 fi
1260 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
1261 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
1262 unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
1263 if [ "$current_partition" = "" ] ; then
1264 LogFile "Unknown partition (outstring = $unofficial_outstring)"
1265 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1266 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1267 partition_mountpt=raid
1268 partition_format=raid
1269 printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1270 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1271 else
1272 LogFile "Unknown mountpoint (outstring = $unofficial_outstring)"
1273 fi
1274 elif [ "$partition_format" = "" ] ; then
1275 LogFile "Unknown format (outstring = $unofficial_outstring)"
1276 elif [ "$partition_size" = "" ] ; then
1277 LogFile "Unknown partition size (outstring = $unofficial_outstring)"
1278 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1279 continue
1280 else
1281 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1282 LogFile "vfat should be used instead of dos/msdos as a partition format"
1283 partition_format="vfat"
1284 fi
1285 printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1286 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
1287 fi
1288 done
1289 LogAll "-----------------------------------"
1290}
1291
1292CheckMountlist() {
1293 local file=$1
1294 # Coherency verification
1295 ML0=`cat $file | wc -l`
1296 ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
1297 ML2=`$AWK '{print $2}' $file | sort -u | wc -l`
1298 if [ "$ML0" -ne "$ML1" ]; then
1299 LogFile "--------------------------------------------"
1300 echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE
1301 LogFile "--------------------------------------------"
1302 fi
1303 if [ "$ML0" -ne "$ML2" ]; then
1304 LogFile "--------------------------------------------"
1305 echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE
1306 LogFile "------------------------------------------------"
1307 fi
1308}
1309
1310MakeSureNumberIsInteger() {
1311 res=`echo "$1" | tr -s '\-[0-9]' ' '`
1312 if [ "$res" != " " ] && [ "$res" != "" ] ; then
1313 echo "result = '$res'"
1314 Die "$1 should be an integer"
1315 fi
1316}
1317
1318
1319OfferToMakeBootableISO() {
1320 local i old_pwd
1321 if [ -z "$ISO_CMD" ]; then
1322 LogIt "Neither mkisofs nor genisoimage found, unable to make CD image"
1323 return
1324 fi
1325 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1326 echo -en "Shall I make a bootable CD image? (y/[n]) "
1327 read i
1328 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1329 fi
1330 rm -Rf $MINDI_TMP/iso
1331 mkdir -p $MINDI_TMP/iso/{images,archives}
1332 cp -f $MINDI_CACHE/{*.gz,*.img} $MINDI_TMP/iso/images 2>> $LOGFILE || LogAll "OfferToMakeBootableISO: Cannot copy $MINDI_CACHE/*.gz to $MINDI_TMP/iso/images"
1333 LogFile "mindi_lib = $MINDI_DATA"
1334 for i in memdisk memtest.bin memtest.img ; do
1335 j=$MINDI_DATA/$i
1336 k=$MINDI_TMP/iso
1337 if [ -e "$j" ] ; then
1338 LogAll "Copying $j to $k"
1339 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1340 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1341 if [ _"$MONDO_SHARE" != _"" ]; then
1342 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1343 fi
1344 fi
1345 done
1346 MakeMessageFile > $MINDI_TMP/iso/message.txt
1347 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?"
1348 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?"
1349 if [ _"$MONDO_SHARE" != _"" ]; then
1350 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?"
1351 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?"
1352 fi
1353 MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
1354 if [ "$ARCH" != "ia64" ] ; then
1355 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?"
1356 fi
1357 old_pwd=`pwd`
1358 cd $MINDI_TMP/iso
1359 if [ "$ARCH" != "ia64" ] ; then
1360 if [ _"$MONDO_SHARE" != _"" ]; then
1361 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?"
1362 cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
1363 fi
1364 $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
1365 else
1366 $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
1367 rm -f images/mindi-bootroot.$BOOT_SIZE.img
1368 fi
1369 if [ "$?" -ne "0" ] ; then
1370 LogFile "----------- $ISO_CMD's errors --------------"
1371 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
1372 echo "$ISO_CMD returned the following errors:-"
1373 cat $MINDI_TMP/mkisofs.log
1374 LogAll "Failed to create ISO image."
1375 else
1376 LogAll "Created bootable ISO image at $MINDI_CACHE/mindi.iso"
1377 fi
1378 rm -f $MINDI_TMP/mkisofs.log
1379 cd $old_pwd
1380}
1381
1382
1383OfferToMakeBootableUSB() {
1384 local i
1385 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
1386 echo -n "Shall I make a bootable USB image ? (y/[n]) "
1387 read i
1388 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1389 if [ "$USBDEVICE" = "" ]; then
1390 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1391 read dev
1392 USBDEVICE=$dev
1393 fi
1394 echo "WARNING: This will erase all content on $USBDEVICE"
1395 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
1396 read i
1397 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1398 fi
1399 rm -Rf $MINDI_TMP/usb
1400 mkdir -p $MINDI_TMP/usb
1401 USBPART="${USBDEVICE}1"
1402
1403 echo -en "Transforming $USBDEVICE in a Bootable device "
1404 echo -en "."
1405 LogFile "Transforming $USBDEVICE in a Bootable device"
1406 LogFile "Checking $USBDEVICE"
1407 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
1408 if [ $? -ne 0 ]; then
1409 LogAll "Unable to access $USBDEVICE"
1410 LogAll "Make sure your USB device is pluged in"
1411 exit -1
1412 fi
1413 echo -en "."
1414 LogFile "Unmounting $USBPART just in case"
1415 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1416 # If your key has no MBR it may cause an issue
1417 # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
1418 LogFile "Preparing $USBDEVICE"
1419 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
1420d
1421d
1422d
1423d
1424n
1425p
14261
1427
1428
1429t
1430b
1431a
14321
1433w
1434EOF
1435 if [ $? -ne 0 ]; then
1436 LogAll "Unable to create a vfat Filesystem on $USBDEVICE"
1437 LogAll "Make sure your USB device is pluged in"
1438 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1439 MindiExit -1
1440 fi
1441 LogFile "The USB device $USBDEVICE now looks like this:"
1442 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1443 echo -en "."
1444 # Some distro do auto mount at that point (Ubuntu)
1445 LogFile "Unmounting $USBPART just in case again"
1446 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1447 echo -en "."
1448 LogFile "Creating a vfat filesystem on $USBPART"
1449 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
1450 if [ $? -ne 0 ]; then
1451 LogAll "Unable to create a vfat filesystem on $USBPART"
1452 LogAll "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)"
1453 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1454 MindiExit -1
1455 fi
1456 echo -en "."
1457 LogFile "Mounting $USBPART on $MINDI_TMP/usb"
1458 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1459 if [ $? -ne 0 ]; then
1460 LogAll "Unable to mount $USBPART on $MINDI_TMP/usb"
1461 LogAll "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)"
1462 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1463 MindiExit -1
1464 fi
1465 echo -en "."
1466 mkdir -p $MINDI_TMP/usb/images
1467 cp -f $MINDI_CACHE/*.img $MINDI_CACHE/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogAll "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
1468 echo -en "."
1469 LogFile "mindi_lib = $MINDI_DATA"
1470 for i in memdisk memtest.bin memtest.img ; do
1471 j=$MINDI_DATA/$i
1472 k=$MINDI_TMP/usb
1473 if [ -e "$j" ] ; then
1474 LogAll "Copying $j to $k"
1475 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1476 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
1477 fi
1478 done
1479 echo -en "."
1480 MakeMessageFile > $MINDI_TMP/usb/message.txt
1481 echo -en "."
1482 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?"
1483 echo -en "."
1484 cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1485 echo -en "."
1486 MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
1487 echo -en "."
1488 echo "----------- syslinux's conf --------------" |tee -a $LOGFILE
1489 cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
1490 echo "------------------------------------------" |tee -a $LOGFILE
1491 umount $MINDI_TMP/usb
1492 if [ "$ARCH" != "ia64" ] ; then
1493 syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
1494 if [ "$?" -ne "0" ] ; then
1495 LogAll "----------- syslinux's errors --------------" |tee -a $LOGFILE
1496 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1497 echo "------------------------------------------" |tee -a $LOGFILE
1498 LogAll "Failed to create USB image."
1499 else
1500 echo -e "$DONE"
1501 LogFile "Created bootable USB image on $USBDEVICE"
1502 fi
1503 rm -f $MINDI_TMP/syslinux.log
1504 else
1505 echo "No USB boot support for ia64"
1506 MindiExit -1
1507 fi
1508}
1509
1510
1511MakeMessageFile() {
1512
1513 if [ -x "/bin/lsb_release" ]; then
1514 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1515 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1516 # For pb >= 0.9.8
1517 DESC=`/usr/bin/pbdistrocheck -d`
1518 else
1519 iss="/dev/null"
1520 [ -r /etc/issue.net ] && iss="/etc/issue.net"
1521 [ -r /etc/issue ] && iss="/etc/issue"
1522 DESC=`head -1 $iss`
1523 fi
1524 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/"
1525 if [ _"$MONDO_SHARE" != _"" ]; then
1526 if [ "$CDRECOVERY" != "yes" ] ; then
1527 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1528 echo -en "Press <enter> to continue.\n"
1529 elif [ ! "$MINDI_TMP" ] ; then
1530 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1531 if [ -e "$MINDI_DATA/memtest.img" ] ; then
1532 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
1533 fi
1534 else
1535 echo -en "$BOOT_MEDIA_MESSAGE"
1536 fi
1537 else
1538 echo -en "\
1539To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1540CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1541 fi
1542 fi
1543 echo -en "\n\n\n"
1544}
1545
1546
1547MakeBootConfFile() {
1548 local options i ooo
1549 options=""
1550 # Type of boot file (elilo or syslinux/isolinux)
1551 type=$1
1552 if [ "$type" = "elilo" ]; then
1553 sep="="
1554 else
1555 sep=" "
1556 fi
1557
1558 # Generic header for conf file
1559 if [ "$type" != "elilo" ] ; then
1560 echo -en "prompt 1\ndisplay message.txt\n"
1561 else
1562 echo -en "prompt\n"
1563 fi
1564
1565 # Compute which default option to boot from
1566 if [ "$CDRECOVERY" = "yes" ] ; then
1567 echo -en "default${sep}RESTORE\n"
1568 # In case it's mondoarchive
1569 elif [ _"$MONDO_SHARE" != _"" ]; then
1570 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
1571 echo -en "default${sep}iso\n"
1572 else
1573 echo -en "default${sep}interactive\n"
1574 fi
1575 else
1576 echo -en "default${sep}expert\n"
1577 fi
1578
1579 # Handle timeout
1580 if [ "$CDRECOVERY" != "yes" ] ; then
1581 echo -en "timeout${sep}300\n"
1582 else
1583 echo -en "timeout${sep}10000\n"
1584 fi
1585 echo -en "\n"
1586
1587 # prepare which labels will be generated
1588 if [ "$CDRECOVERY" = "yes" ] ; then
1589 options="RESTORE expert"
1590 else
1591 if [ _"$MONDO_SHARE" != _"" ]; then
1592 options="interactive expert compare iso nuke isonuke"
1593 else
1594 options="expert"
1595 fi
1596 fi
1597
1598 # Generate rest of conf file
1599 for i in $options ; do
1600 ooo=$i
1601 [ "$ooo" = "RESTORE" ] && ooo="nuke"
1602 if [ "$type" = "elilo" ]; then
1603 outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/initrd.img\n\troot=/dev/ram0 append=\" rw ramdisk_size=$ramdisk_size $ooo $ADDITIONAL_BOOT_PARAMS \"\n"
1604 else
1605 ps="/"
1606 if [ "$type" = "syslinux" ]; then
1607 ps=""
1608 fi
1609 outstr="label $i\n\tkernel ${ps}vmlinuz\n\tappend initrd=${ps}initrd.img root=/dev/ram0 rw ramdisk_size=$ramdisk_size ${ooo} $ADDITIONAL_BOOT_PARAMS\n"
1610 fi
1611 echo -en "$outstr"
1612 done
1613
1614 if [ -e "$MINDI_DATA/memtest.img" ] ; then
1615 if [ "$type" = "elilo" ]; then
1616 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
1617 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
1618 else
1619 ps="/"
1620 if [ "$type" = "syslinux" ]; then
1621 ps=""
1622 fi
1623 echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
1624 echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
1625 fi
1626 fi
1627}
1628
1629
1630PrepareBootDiskImage_LILO() {
1631 local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
1632 imagesdir=$MINDI_CACHE
1633 kernelpath=$1
1634
1635 retval=0
1636 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1637 echo -en "Making "$BOOT_SIZE"KB boot disk..."
1638 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?"
1639 echo -en "..."
1640 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1641 mountpoint=$MINDI_TMP/mountpoint.$$
1642 mkdir -p $mountpoint
1643 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1644 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1645 mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
1646 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1647 mkdir -p $mountpoint/etc
1648 liloconf=$mountpoint/elilo.conf
1649
1650 MakeBootConfFile elilo > $liloconf
1651
1652 # Copy it so that CD-ROM menu entry is satisfied
1653 mountefi=0
1654 df -T | grep /boot/efi | grep -q vfat
1655 if [ $? -ne 0 ]; then
1656 mount /boot/efi
1657 if [ $? -ne 0 ]; then
1658 echo "You have to mount your EFI partition when using mindi"
1659 MindiExit -1
1660 fi
1661 mountefi=1
1662 fi
1663 el=`find /boot/efi -name elilo.efi`
1664 cp $el $mountpoint
1665 cp $liloconf $mountpoint
1666 if [ $mountefi -eq 1 ]; then
1667 umount /boot/efi 2>&1 > /dev/null
1668 fi
1669
1670 LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint..."
1671 cp -f $MINDI_TMP/initrd.img $mountpoint 2>> $LOGFILE
1672 if [ "$?" -ne "0" ] ; then
1673 LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1674 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1675 LogAll "Please unload some of your modules and try again."
1676 rm -f $MINDI_TMP/mtpt.$$
1677 LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1678 retval=$(($retval+1))
1679 fi
1680 MakeMessageFile > $mountpoint/message.txt
1681
1682 # copy the kernel across
1683 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1684 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1685 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1686 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2>> $LOGFILE
1687 if [ "$?" -ne "0" ] ; then
1688 LogFile "Files at mountpoint ($mountpoint) :-"
1689 du -sk $mountpoint/* >> $LOGFILE
1690 LogFile "--- end of list of files ---"
1691 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
1692Sorry, your kernel is too big for your image.\n" >> $LOGFILE
1693 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1694 cd $old_pwd
1695 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1696 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1697 [ "$imagefile" != "" ] && rm -f $imagefile
1698 return 0
1699 fi
1700 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
1701 LogFile "Free space left on image = $free_space KB"
1702 LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
1703 # make it bootable
1704 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1705 [ -e "$MINDI_DATA/memdisk" ] && cp -f $MINDI_DATA/memdisk $mountpoint 2>> $LOGFILE
1706 if [ "$KERN_DISK_MADE" ] ; then
1707 LogFile "Not running LILO. It's not that kind of disk."
1708 fi
1709
1710 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1711 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1712 echo -en "..."
1713 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1714 if [ "$retval" -eq "0" ] ; then
1715 echo -en "...$DONE\n"
1716 if [ "$KERN_DISK_MADE" ] ; then
1717 LogAll "$BOOT_SIZE KB boot disks were created OK\n"
1718 fi
1719 else
1720 echo -en "...failed\n"
1721 LogAll $BOOT_SIZE"KB boot disk was NOT created\n"
1722 [ "$imagefile" != "" ] && rm -f $imagefile
1723 fi
1724 [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
1725 return $retval
1726}
1727
1728
1729PrepareBootDiskImage_ISOLINUX() {
1730 local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
1731 imagesdir=$MINDI_CACHE
1732 kernelpath=$1
1733 do_boot_root_thingy=""
1734 local retval old_pwd
1735 retval=0
1736
1737 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
1738 echo -en "Making "$BOOT_SIZE"KB boot disk..."
1739 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?"
1740 echo -en "..."
1741 imagefile=$MINDI_TMP/mindi-bootroot.$BOOT_SIZE.img
1742 mountpoint=$MINDI_TMP/mountpoint.$$
1743 mkdir -p $mountpoint
1744 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
1745 LogFile "Creating vfat filesystem on $imagefile"
1746 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
1747 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1748 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1749
1750 # Only move it now to its final destination abd use it now
1751 mv $imagefile $imagesdir
1752 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
1753
1754 mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
1755
1756 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
1757 MakeMessageFile > $mountpoint/message.txt
1758 MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1759 LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
1760 cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
1761 if [ "$?" -ne "0" ] ; then
1762 LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
1763 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
1764 LogAll "Please unload some of your modules and try again."
1765 rm -f $MINDI_TMP/mtpt.$$
1766 LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
1767 retval=$(($retval+1))
1768 fi
1769
1770 # copy the kernel across
1771 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
1772 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1773 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1774 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
1775 if [ "$?" -ne "0" ] ; then
1776 LogFile "Files at mountpoint ($mountpoint) :-"
1777 du -sk $mountpoint/* >> $LOGFILE
1778 LogFile "--- end of list of files ---"
1779 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
1780Sorry, your kernel is too big for your image.\n" >> $LOGFILE
1781 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
1782 cd $old_pwd
1783 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1784 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1785
1786 [ "$imagefile" != "" ] && rm -f $imagefile
1787 return 0
1788 fi
1789 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
1790 LogFile "Free space left on image = $free_space KB"
1791 LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
1792
1793 # make it bootable
1794 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
1795 mkdir -p $mountpoint/etc
1796 [ -e "$MINDI_DATA/memdisk" ] && cp -f $MINDI_DATA/memdisk $mountpoint 2>> $LOGFILE
1797 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1798 echo -en "..."
1799 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
1800
1801 if [ "$retval" -eq "0" ] ; then
1802 echo -en "...$DONE\n"
1803 if [ "$KERN_DISK_MADE" ] ; then
1804 [ "$imagefile" != "" ] && rm -f $imagefile
1805 LogAll "$BOOT_SIZE KB boot disks were created OK\n"
1806 fi
1807 else
1808 echo -en "...failed\n"
1809 LogAll $BOOT_SIZE"KB boot disk was NOT created\n"
1810 [ "$imagefile" != "" ] && rm -f $imagefile
1811 fi
1812 [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
1813 return $retval
1814}
1815
1816
1817ParseModprobeForIncludes() {
1818local MODPROBE_CONF mpincfile includes include
1819
1820MODPROBE_CONF=/etc/modprobe.conf
1821mpincfile=$1
1822touch $mpincfile
1823if [ -a $MODPROBE_CONF ]; then
1824 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
1825 if [ -n "$includes" ]; then
1826 for include in $includes
1827 do
1828 if [ -a "$include" ]; then
1829 echo $include >> $mpincfile
1830 fi
1831 done
1832 fi
1833fi
1834}
1835
1836
1837PrepareDataDiskImages() {
1838 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
1839
1840 imagesdir=$MINDI_CACHE
1841 rm -f $imagesdir/mindi.iso
1842 needlist=$MINDI_TMP/what-we-need.txt
1843 bigdir=$MINDI_TMP/bigdir
1844 mkdir -p $bigdir/usr/bin
1845 mkdir -p $bigdir/usr/sbin
1846 includefile=$MINDI_TMP/$$.includefile.txt
1847
1848 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
1849 if [ -e "$DEPLIST_FILE" ]; then
1850 lfiles="$DEPLIST_FILE $lfiles"
1851 fi
1852 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
1853 ParseModprobeForIncludes $includefile
1854 lines=$(($lines+`cat $includefile | wc -l`))
1855 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
1856 res=$?
1857 rm -f $includefile
1858 # This function appends to the file passed in param
1859 ListKernelModulePaths $needlist
1860 if [ "$res" -ne "0" ] ; then
1861 Die "You have $res files present in dependency list\nbut absent from filesystem."
1862 fi
1863 FindAndAddUserKeyboardMappingFile
1864 mkdir -p $bigdir/tmp
1865 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
1866 DropOptimizedLibraries $needlist $bigdir
1867 echo -en "Assembling dependency files"
1868
1869 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
1870
1871 # also copy io.sys and msdos.sys, if we can find them
1872 for i in `mount | cut -d' ' -f3` ; do
1873 for j in io.sys msdos.sys ; do
1874 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
1875 done
1876 done
1877
1878 # master boot record, too
1879 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
1880 if [ "$i" ] ; then
1881 LogAll "Backing up $i's MBR"
1882 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
1883 sleep 1
1884 sync
1885 j=$i
1886 [ -h "$j" ] && j=`readlink -f $j`
1887 LogAll "Creating /dev/boot_device ($j)"
1888 mkdir -p $bigdir/dev
1889 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
1890 fi
1891
1892 old_pwd=`pwd`
1893 cd $bigdir
1894
1895 # Get terminfo content
1896 ti="usr/share/terminfo/l"
1897 if [ -d /$ti ]; then
1898 mkdir -p $ti
1899 cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "WARNING - error occurred while copying terminfo"
1900 fi
1901 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
1902 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
1903 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
1904 fi
1905 if [ -d "/lib/dev-state" ]; then
1906 tar cf - -C / ./lib/dev-state 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
1907 fi
1908 cd $old_pwd
1909 echo -e "$DONE"
1910 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
1911 mkdir -p $bigdir/tmp
1912 if [ $LVM != "false" ]; then
1913 $MINDI_DATA/analyze-my-lvm > $bigdir/tmp/i-want-my-lvm
1914 if [ "$?" -ne "0" ]; then
1915 LVM="false"
1916 rm -f $bigdir/tmp/i-want-my-lvm
1917 fi
1918 fi
1919
1920 LogFile -en "$FILES_IN_FILELIST" > $bigdir/FILES-IN-FILELIST
1921 if [ _"$MONDO_SHARE" != _"" ]; then
1922 for q in filelist.full.gz biggielist.txt ; do
1923 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
1924 cp -pRdf $MINDI_TMP/$q $bigdir/tmp 2>> $LOGFILE
1925 done
1926 fi
1927
1928 echo -en "Tarring and zipping the data content..."
1929 size_of_all_tools=`du -sk $bigdir | cut -f1`
1930 (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)
1931 LogFile "Size of the data content"
1932 LogFile "------------------------"
1933 du -sk $imagesdir/*gz >> $LOGFILE
1934 LogFile "------------------------"
1935 echo -e "$DONE"
1936
1937 FRIENDLY_OUTSTRING="Boot and data disk images were created."
1938 rm -rf $bigdir
1939 rm -f $needlist
1940}
1941
1942
1943ProcessLDD() {
1944 local incoming f d nd bd bnd
1945 read incoming
1946 while [ "$incoming" != "" ]; do
1947 # We take the full path name of the dyn. lib. we want
1948 incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
1949 for f in $incoming ; do
1950 # echo modified file name if one of the parent dir is a link
1951 # by replacing the original dirname by the destination of the link
1952 d="`dirname $f`"
1953 found="false"
1954 while [ "$d" != "/" ]; do
1955 if [ -h "$d" ]; then
1956 nd=`readlink -f $d`
1957 bd=`basename $d`
1958 bnd=`basename $nd`
1959 f=`echo $f | sed "s~/$bd/~/$bnd/~"`
1960 echo $d
1961 fi
1962 d="`dirname $d`"
1963 done
1964
1965 echo "$f"
1966 echo "`ReadAllLink $f`"
1967 done
1968 read incoming
1969 done
1970}
1971
1972
1973Prompt() {
1974 echo -en "$1"
1975 read line
1976}
1977
1978
1979ReadLine() {
1980 local i incoming
1981 read incoming
1982 i=0
1983 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
1984 i=$(($i+1))
1985 read incoming
1986 done
1987 echo "$incoming"
1988}
1989
1990
1991SizeOfPartition() {
1992 local devpath drive res stub
1993 device=$1
1994 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
1995 res=`SizeOfRaidPartition $device`
1996 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
1997 echo "$res"
1998 return 0
1999 fi
2000 # patch from Bill <bill@iwizard.biz> - 2003/08/25
2001 res=`$FDISK -s $device 2>> $LOGFILE`
2002 # end patch
2003 # take only the first in case of multiple mount (cifs, nfs, ...)
2004 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
2005 [ "$res" = "" ] && res="-1"
2006 echo $res
2007 return 0
2008}
2009
2010
2011SizeOfRaidPartition() {
2012 local real_dev smallest_size silly tmp
2013
2014 silly=999999999
2015 smallest_size=$silly
2016
2017 for real_dev in `GetRaidDevMembers $1` ; do
2018 tmp=`SizeOfPartition $real_dev`
2019 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
2020 done
2021
2022 if [ "$smallest_size" = "$silly" ] ; then
2023 echo "-1"
2024 return 1
2025 else
2026 echo "$smallest_size"
2027 return 0
2028 fi
2029}
2030
2031
2032StripComments()
2033{
2034 local tempfile
2035
2036 tempfile=$MINDI_TMP/$$.strip.txt
2037 cp -f $1 $tempfile 2>> $LOGFILE
2038 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2039 rm -f $tempfile
2040 LogFile "Stripped comments from $2"
2041}
2042
2043
2044
2045StripExecutable()
2046{
2047 local tmpfile
2048
2049 tmpfile=$MINDI_TMP/stripped.$$.dat
2050 [ -d "$1" ] || [ -h "$1" ] && return
2051 cp -f $1 $tmpfile 2>> $LOGFILE
2052 strip $tmpfile 2> /dev/null
2053 if [ "$?" -eq "0" ] ; then
2054 cp -f $tmpfile $1 2>> $LOGFILE
2055 LogFile "Stripped binary $2"
2056 fi
2057 rm -f $tmpfile
2058}
2059
2060KernelVer() {
2061 local fkern_ver fname
2062
2063 fname=$1
2064 file $fname | grep -q gzip
2065 if [ "$?" -eq "0" ] ; then
2066 # Used by ia64
2067 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2068 else
2069 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2070 fi
2071 echo "$fkern_ver"
2072}
2073
2074
2075TryToFindKernelPath() {
2076 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
2077
2078 we_want_version=$KERVERRUN
2079 possible_kernels=""
2080 duff_kernels=""
2081
2082 if [ "$ARCH" = "ia64" ] ; then
2083 root="/boot/efi/efi"
2084 else
2085 root="/"
2086 fi
2087 for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
2088 [ ! -e "$fname" ] && continue
2089 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
2090 fkern_ver=`KernelVer $fname`
2091 [ "$fkern_ver" = "" ] && continue
2092 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
2093 [ -f "$fname" ] || continue
2094 [ -h "$fname" ] && continue
2095 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2096 file $fname | grep -q gzip
2097 if [ "$?" -eq "0" ] ; then
2098 # Used by ia64
2099 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2100 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
2101 duff_kernels="$fname $duff_kernels"
2102 else
2103 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2104 possible_kernels="$fname $possible_kernels"
2105 fi
2106 else
2107 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
2108 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
2109 duff_kernels="$fname $duff_kernels"
2110 else
2111 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2112 possible_kernels="$fname $possible_kernels"
2113 fi
2114 fi
2115 done
2116 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
2117 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
2118 fi
2119 if [ ! "$possible_kernels" ] ; then
2120 LogAll "No kernel matches exactly. Are there any duff kernels?"
2121 possible_kernels="$duff_kernels"
2122 if [ ! "$possible_kernels" ] ; then
2123 LogAll "Sorry, no duff kernels either"
2124 else
2125 LogAll "I bet you're running Debian or Gentoo, aren't you?"
2126 LogAll "Your kernel doesn't have a sane builddate. Oh well..."
2127 fi
2128 fi
2129 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2130 noof_kernels=`CountItemsIn "$possible_kernels"`
2131 if [ "$noof_kernels" -eq "0" ] ; then
2132 LogAll "Could not find your kernel."
2133 if [ -e "/boot/vmlinuz" ] ; then
2134 LogAll "Using /boot/vmlinuz as a last resort."
2135 output=/boot/vmlinuz
2136 else
2137 output=""
2138 fi
2139 elif [ "$noof_kernels" -eq "1" ] ; then
2140 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2141 LogFile "Your kernel is $kernelpath (v$KERVERRUN)"
2142 output="$kernelpath"
2143 else
2144 for i in $possible_kernels ; do
2145 if echo $i | grep "$KERVERRUN" ; then
2146 LogAll "OK, I used my initiative and found that "
2147 LogAll "$i is probably your kernel. "
2148 output="$i"
2149 return
2150 fi
2151 done
2152 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2153 output=/boot/vmlinuz
2154 LogFile "Schlomo, this one's for you."
2155 else
2156 LogAll "Two or more possible kernels found. You may specify any one of them and the "
2157 LogAll "boot disks will still work, probably. If one does not work, try another."
2158 LogAll "$possible_kernels"
2159 echo ""
2160 fi
2161 fi
2162 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2163}
2164
2165
2166TurnTgzIntoRdz() {
2167 local tgz_dir_fname rdz_fname tempfile mountpoint old_pwd nodes kernelsize res currsize not_copied j k s w needed_modules_path
2168
2169 tgz_dir_fname=$1
2170 rdz_fname=$2
2171 kernelsize=$3
2172 # Compute the list of all that should be copied/created on the final mountpoint under MINDI_TMP
2173 # mkdir.lis will contain the list of directries to create
2174 # cp.lis will contain the list of files/dirs to copy
2175 # ln.lis will contain the list of files to link to existing files
2176 # rm.lis will contain the list of files to remove after the copies
2177 # AL04Oct08: Check whether /lib64 is a link and if so explicitly create one in rootfs
2178 if [ -h "/lib64" ]; then
2179 echo lib >> $MINDI_TMP/mkdir.lis
2180 echo ln -s lib lib64 >> $MINDI_TMP/ln.lis
2181 fi
2182
2183 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > $MINDI_CACHE/USE-DEVFS
2184 echo $MINDI_CACHE/USE-DEVFS >> $MIDI_TMP/cp.lis
2185
2186 # We need a minimal conf in the initial ramdisk
2187 mountlis=`grep -v "^#.*" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | cut -d: -f2 | sort -u`
2188 ReadAllLink $mountlis >> $MINDI_TMP/mnt.lis
2189 LocateDeps `cat $MINDI_TMP/mnt.lis` >> $MINDI_TMP/deps.lis
2190 # Special for libs
2191 ReadAllLink `grep -E "/lib" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | grep -v "^#.*" | cut -d: -f2` >> $MINDI_TMP/deps.lis
2192
2193 echo `cat $MINDI_TMP/mnt.lis` `sort -u $MINDI_TMP/deps.lis` >> $MINDI_TMP/cp.lis
2194 rm -f $MINDI_TMP/deps.lis $MINDI_TMP/mnt.lis
2195
2196 # Copy of files mandatory for ld.so
2197 echo /etc/ld.so.c* >> $MINDI_TMP/cp.lis
2198
2199 # Avoid an issue on some distro (RHEL5)
2200 echo ./etc/ld.so.conf.d/kernelcap* >> $MINDI_TMP/rm.lis
2201
2202 # Need for a tmp dir
2203 echo tmp >> $MINDI_TMP/mkdir.lis
2204
2205 # Management of udev (which includes modprobe in rules)
2206 ps auxww | grep -v grep | grep -qw udevd
2207 if [ $? -eq 0 ]; then
2208 echo "udev device manager found" > $MINDI_CACHE/USE-UDEV
2209 echo $MINDI_CACHE/USE-UDEV >> $MINDI_TMP/cp.lis
2210 LogFile "udev device manager found"
2211 echo /etc/udev /lib*/udev >> $MINDI_TMP/cp.lis
2212 # This avoids NIC remapping if on another machine at restore time on Debian at least
2213 echo ./etc/udev/rules.d/z[0-9][0-9]_persistent-net.rules >> $MINDI_TMP/rm.lis
2214 # This avoids NIC remapping if on another machine at restore time on Ubuntu at least
2215 echo ./etc/udev/rules.d/[0-9][0-9]-persistent-net.rules >> $MINDI_TMP/rm.lis
2216 if [ -x /sbin/udevd ]; then
2217 # Get only the files which exist in the udev.files list
2218 # and potentially their symlink structure and their deps
2219 mountlis=`grep -Ev "^#" $MINDI_CONF/udev.files`
2220 ReadAllLink $mountlis | sort -u >> $MINDI_TMP/udev.lis
2221 LocateDeps `cat $MINDI_TMP/udev.lis` | sort -u >> $MINDI_TMP/cp.lis
2222 cat $MINDI_TMP/udev.lis >> $MINDI_TMP/cp.lis
2223 rm -f $MINDI_TMP/udev.lis
2224 else
2225 LogAll "udevd daemon not in standard place (/sbin)"
2226 LogAll "mindi will use static devices which may cause problems"
2227 rm -f $MINDI_CACHE/USE-UDEV
2228 fi
2229 fi
2230
2231 # Management of potential HW info (Proliant only at the moment)
2232 rm -rf $MINDI_CACHE/bkphw
2233 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2234 if [ -d $MINDI_CACHE/bkphw ]; then
2235 LogAll "Hardware Information found and saved ..."
2236 echo $MINDI_CACHE/bkphw >> $MIDNDI_TMP/cp.lis
2237 if [ -f $MINDI_CACHE/tools.files ]; then
2238 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2239 LocateDeps $lis > $MINDI_TMP/tools.lis
2240 echo $lis `sort -u $MINDI_TMP/tools.lis` >> $MINDI_TMP/cp.lis
2241 fi
2242 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2243 chmod 755 $MINDI_CACHE/mindi-rsthw
2244 echo $MINDI_CACHE/mindi-rsthw >> $MINDI_TMP/cp.lis
2245 fi
2246 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2247 fi
2248
2249 # Management of perl scripts delivered needed at restore time
2250 mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` >> $MINDI_TMP/cp.lis
2251
2252 for w in cdrom groovy-stuff ; do
2253 echo mnt/$w >> $MINDI_TMP/mkdir.lis
2254 done
2255
2256 ls /dev/fd0*[1,2][4,7,8]* >> $MINDI_TMP/cp.lis 2> /dev/null
2257
2258 if [ "${kernelname}" != "" ]
2259 then
2260 needed_modules_path=/lib/modules/${kernelname}
2261 else
2262 needed_modules_path=/lib/modules/$KERVERRUN
2263 fi
2264
2265 needed_modules=""
2266 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
2267
2268 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
2269 # For PXE boot
2270 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2271 fi
2272 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2273 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2274 fi
2275 for i in $DENY_MODS; do
2276 LogFile "Removing $i from the list of modules to load"
2277 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2278 done
2279
2280 [ -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."
2281 for i in $list_of_groovy_mods ; do
2282 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
2283 done
2284
2285 for i in $needed_modules ; do
2286 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2287 LogFile "Adding $i ($s KB) to the rootfs"
2288 echo $i >> $MINDI_TMP/cp.lis
2289 done
2290
2291 # Also copy modules.dep in case of udev so that normal modprobe works
2292 echo $needed_modules_path/modules.dep >> $MINDI_TMP/cp.lis
2293
2294 # Manages mountlit.txt
2295 MakeMountlist $MINDI_CACHE/mountlist.txt
2296 CheckMountlist $MINDI_CACHE/mountlist.txt
2297 echo $MINDI_CACHE/mountlist.txt >> $MINDI_TMP/cp.lis
2298 cat $MINDI_CACHE/mountlist.txt >> $LOGFILE
2299 LogFile "-----------------------------------"
2300
2301 if [ ! -e "/sbin/devfsd" ] ; then
2302 LogFile "Deleting devfsd daemon from ramdisk because /sbin/devfsd not found"
2303 echo ./sbin/devfsd >> $MINDI_TMP/rm.lis
2304 fi
2305
2306 cd $old_pwd
2307 if [ _"$MONDO_SHARE" != _"" ]; then
2308 MakeMondoConfigFile $MINDI_CACHE/mondorestore.cfg
2309 echo $MINDI_CACHE/mondorestore.cfg >> $MINDI_TMP/cp.lis
2310 fi
2311 echo proc >> $MINDI_TMP/mkdir.lis
2312
2313 # Copy of files mandatory for ssh to automate mount if sshfs is used
2314 echo .ssh >> $MINDI_TMP/mkdir.lis
2315
2316 # Now create the container and do the job
2317 tempfile=$MINDI_TMP/temp.rd
2318 mountpoint=$MINDI_TMP/mnt1
2319 res=0
2320 echo -en "..."
2321 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk ($tempfile)"
2322 echo -en "..."
2323 LogFile "Creating ext2 filesystem on $tempfile"
2324 mke2fs -b 1024 -m 0 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2325 echo -en "..."
2326 mkdir -p $mountpoint
2327 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."
2328 echo -en "..."
2329 old_pwd=`pwd`
2330
2331 # First create dirs
2332 for d in `cat $MINDI_TMP/mkdir.lis`; do
2333 mkdir -p $mountpoint/$d 2>&1 >> $LOGFILE
2334 done
2335
2336 # Then copy files needed
2337 LANGUAGE=C tar cf - `cat $MINDI_TMP/cp.lis` | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
2338
2339 # Then handle links
2340 if [ -f $MINDI_TMP/ln.lis ]; then
2341 (cd $mountpoint ; bash $MINDI_TMP/ln.lis) 2>&1 >> $LOGFILE
2342 fi
2343
2344 # Finally remove useless stff
2345 (cd $mountpoint ; rm -f `cat $MINDI_TMP/rm.lis`) 2>&1 >> $LOGFILE
2346
2347 # Copy of files mandatory for ssh to automate mount if sshfs is used
2348 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2349 cat > $mountpoint/bin/myssh << EOF
2350ssh -o StrictHostKeyChecking=no $*
2351EOF
2352 chmod 755 $mountpoint/bin/myssh
2353
2354 # Finally integrate what we provide statically as part of mindi
2355 (cd $tgz_dir_fname ; LANGUAGE=C tar cf - . ) | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
2356
2357 # Extracting devices
2358 bash
2359 (cd $mountpoint/dev ; tar -zxf dev-entries.tgz) || Die "Cannot untar dev-entries.tgz"
2360 rm -f $mountpoint/dev/dev-entries.tgz
2361
2362 LogFile "---------------------------"
2363 LogFile "Content of initial ramdisk:"
2364 LogFile "---------------------------"
2365 (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2366 LogFile "---------------------------"
2367
2368 # Determine what filesystem to use for initrd image
2369 LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
2370 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2371 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2372 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ]; then
2373 # say what will be used
2374 LogFile "Creating an $gvFileSystem initrd image..."
2375 # kernel expects linuxrc in ext2 filesystem
2376 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2377 # unmount loop filesystem and create image file using the standard approach
2378 umount $mountpoint || Die "Cannot unmount $tempfile"
2379 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
2380 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
2381 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
2382 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
2383 rm -f ${rdz_fname}.tmp
2384 # log that we are done
2385 LogFile "...done."
2386 elif [ "$gvFileSystem" = "initramfs" ]; then
2387 # say what will be used
2388 LogFile "Creating a gzip'ed cpio (AKA initramfs) initrd image..."
2389 # make sure that cpio is there
2390 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2391 # go into filesystem
2392 cd $mountpoint
2393 # kernel expects init in cpio filesystem
2394 ln -sf sbin/init init
2395 # create cpio image file and unmount loop filesystem
2396 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
2397 cd $old_pwd
2398 umount $mountpoint || Die "Cannot unmount $tempfile"
2399 # log that we are done
2400 LogFile "...done."
2401 else
2402 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2403 fi
2404
2405 if [ "$res" -eq "0" ] ; then
2406 echo -en "..."
2407 else
2408 echo -en "\rMade an rdz WITH ERRORS. \n"
2409 fi
2410 return 0
2411}
2412
2413
2414##############################################################################
2415#----------------------------------- Main -----------------------------------#
2416##############################################################################
2417
2418# Now we can create what we need
2419mkdir -p $MINDI_TMP
2420
2421# Purge from potential old run
2422if [ _"$MINDI_CACHE" = _"" ]; then
2423 Die "MINDI_CACHE undefined"
2424fi
2425
2426if [ "$1" = "--printvar" ] ; then
2427 shift
2428 if [ _"$1" != _"" ] ; then
2429 set | grep -Ew "^$1" | cut -d= -f2
2430 fi
2431 exit 0
2432fi
2433
2434> $LOGFILE
2435LogFile "mindi v$MINDI_VERSION"
2436LogFile "$ARCH architecture detected"
2437LogFile "mindi called with the following arguments:"
2438LogFile "$*"
2439LogFile "Start date : `date`"
2440LogFile "-----------------------------"
2441
2442[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2443
2444# Log some capital variables
2445[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
2446LogFile "MONDO_SHARE = $MONDO_SHARE"
2447LogFile "MINDI_DATA = $MINDI_DATA"
2448LogFile "MINDI_SBIN = $MINDI_SBIN"
2449[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2450LogFile "MINDI_CONF = $MINDI_CONF"
2451if [ -f $MINDI_CONFIG ]; then
2452 LogFile "-----------------------------"
2453 LogFile " Mindi configuration file "
2454 LogFile "-----------------------------"
2455 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
2456 LogFile "-----------------------------"
2457fi
2458
2459
2460trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
2461
2462# Sanity checks
2463which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2464which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2465which 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."
2466which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2467if which awk &> /dev/null ; then
2468 if ! which gawk &> /dev/null ; then
2469 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"
2470 fi
2471fi
2472which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2473[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
2474
2475[ "`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"
2476
2477# Update the PATH variable if incomplete
2478if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2479 PATH=$PATH:/sbin:/usr/sbin
2480 export PATH
2481 LogFile "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily."
2482 LogFile "However, you may wish to ask your vendor to provide a permanent fix..."
2483 LogFile " Or you might like to call 'su -' instead of 'su', for example."
2484fi
2485
2486if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
2487 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2488fi
2489
2490### BERLIOS
2491### Fix as it's not mandatory on ia64
2492if [ "$ARCH" = "ia64" ] ; then
2493 if which elilo &> /dev/null ; then
2494 LILO_EXE=elilo
2495 else
2496 LILO_EXE=`which false 2> /dev/null`
2497 fi
2498else
2499 FindIsolinuxBinary
2500fi
2501trap "Aborted" SIGTERM
2502DONE="\r\t\t\t\t\t\t\t\tDone. "
2503kernelpath=""
2504MONDO_ROOT=/var/cache/mondo
2505mkdir -p $MONDO_ROOT
2506
2507if [ -d "/proc/lvm" ]; then
2508 # LVM v1
2509 LVMCMD=""
2510 LVM="v1"
2511elif [ -d "/dev/mapper" ]; then
2512 # LVM v2
2513 LVMCMD="lvm"
2514 LVM="v2"
2515else
2516 LVM="false"
2517fi
2518
2519if [ -e "/proc/cmdline" ]; then
2520 CMDLINE="/proc/cmdline"
2521elif [ -e "/tmp/cmdline" ]; then
2522 CMDLINE="/tmp/cmdline"
2523else
2524 CMDLINE="/dev/null"
2525fi
2526
2527LogFile "LVM set to $LVM"
2528LogFile "----------"
2529LogFile "mount result:"
2530LogFile "-------------"
2531mount >> $LOGFILE
2532LogFile "-------------"
2533if [ -e /etc/raidtab ]; then
2534 LogFile "-------------"
2535 LogFile "/etc/raidtab content:"
2536 LogFile "-------------"
2537 cat /etc/raidtab >> $LOGFILE
2538fi
2539LogFile "-------------"
2540LogFile "cat $CMDLINE"
2541LogFile "-------------"
2542cat $CMDLINE >> $LOGFILE
2543LogFile "-------------"
2544LogFile "cat /proc/swaps:"
2545LogFile "-------------"
2546cat /proc/swaps >> $LOGFILE
2547LogFile "-------------"
2548LogFile "cat /proc/partitions:"
2549LogFile "-------------"
2550cat /proc/partitions >> $LOGFILE
2551LogFile "-------------"
2552LogFile "cat /proc/filesystems:"
2553LogFile "-------------"
2554cat /proc/filesystems >> $LOGFILE
2555LogFile "-------------"
2556LogFile "lsmod result:"
2557LogFile "-------------"
2558lsmod >> $LOGFILE
2559MODULES="`cat /proc/modules | $AWK '{print $1}'`"
2560if [ -x /usr/sbin/esxcfg-module ]; then
2561 LogFile "-------------"
2562 LogFile "VMWare ESX server detected - Enabling dedicated support"
2563 LogFile "-------------"
2564 LogFile "VMWare modules"
2565 LogFile "-------------"
2566 /usr/sbin/esxcfg-module -l >> $LOGFILE
2567 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
2568fi
2569LogFile "FORCE_MODS:"
2570LogFile "-------------"
2571LogFile $FORCE_MODS
2572LogFile "-------------"
2573LogFile "DENY_MODS:"
2574LogFile "-------------"
2575LogFile $DENY_MODS
2576LogFile "-------------"
2577LogFile "df result:"
2578LogFile "----------"
2579df -T >> $LOGFILE
2580LogFile "-------------"
2581LogFile "Liste of extra modules is:"
2582LogFile "$EXTRA_MODS"
2583LogFile "-------------"
2584
2585# Compute libata version
2586laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
2587# If libata v2 is used then remove ide-generic as it will perturbate boot
2588if [ "`echo $MODULES | grep libata`" ]; then
2589 if [ "$laver" = "2" ]; then
2590 DENY_MODS="$DENY_MODS ide-generic"
2591 LogFile "ide-generic removed from module list as your system uses libata v2+"
2592 LogFile "-------------"
2593 fi
2594fi
2595
2596# Check for ISO_CMD command
2597if [ ! -x $ISO_CMD ]; then
2598 echo "NOTE: No CD image (ISO file) utility found" >> $LOGFILE
2599fi
2600
2601FLOPPY_WAS_MOUNTED=""
2602for mtpt in /media/floppy /mnt/floppy /floppy ; do
2603 if mount | grep -w $mtpt &> /dev/null ; then
2604 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2605 umount $mtpt
2606 fi
2607done
2608
2609#
2610# If we have a USB device we need to store info
2611# and remove it from the parameters line
2612#
2613if [ "$#" -ne "0" ] ; then
2614 if [ "$1" = "--usb" ] ; then
2615 shift
2616 USBDEVICE=$1
2617 if [ _"$USBDEVICE" = _"" ]; then
2618 Die "No USB device specified"
2619 fi
2620 shift
2621 fi
2622fi
2623
2624if [ "$#" -ne "0" ] ; then
2625 if [ "$1" = "--findkernel" ] ; then
2626 res=`TryToFindKernelPath`
2627 # Avoids logfile content for mondo
2628 export MONDO_SHARE=""
2629 if [ "$res" = "" ] ; then
2630 MindiExit -1
2631 else
2632 echo "$res"
2633 MindiExit 0
2634 fi
2635 elif [ "$1" = "--locatedeps" ] ; then
2636 [ ! "$2" ] && Die "Please specify the binary to look at"
2637 LocateDeps $*
2638 # Avoids logfile content for mondo
2639 export MONDO_SHARE=""
2640 MindiExit $?
2641 elif [ "$1" = "--readalllink" ] ; then
2642 [ ! "$2" ] && Die "Please specify the binary to look at"
2643 shift
2644 ReadAllLink $*
2645 # Avoids logfile content for mondo
2646 export MONDO_SHARE=""
2647 MindiExit $?
2648 elif [ "$1" = "--makemountlist" ] ; then
2649 [ ! "$2" ] && Die "Please specify the output file"
2650 MakeMountlist $2
2651 CheckMountlist $2
2652 # Avoids logfile content for mondo
2653 export MONDO_SHARE=""
2654 MindiExit $?
2655 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2656 echo "Mindi v$MINDI_VERSION"
2657 # Avoids logfile content for mondo
2658 export MONDO_SHARE=""
2659 MindiExit 0
2660 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
2661 MONDO_TMP=$2
2662 # Change MINDI_TMP for the one provided by mondo
2663 # So that it can get back the built files
2664 if [ _"$MONDO_TMP" = _"" ]; then
2665 Die "MONDO_TMP is empty, aborting"
2666 fi
2667 if [ _"$MONDO_TMP" = _"/" ]; then
2668 Die "MONDO_TMP is /, aborting"
2669 fi
2670 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2>> $LOGFILE
2671 rmdir $MINDI_TMP
2672 export MINDI_TMP=$MONDO_TMP
2673 mkdir -p $MINDI_TMP
2674
2675 # This is the scratch dir in mondo - subdir images
2676 MINDI_CACHE=$3
2677
2678 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
2679###
2680### Sq-Modification...
2681### Attempt to locate kernel specific module path
2682### if module path is found then use it other wise use uname -r to set it...
2683###
2684 kernelname=`echo $kernelpath | cut -d'-' -f2-`
2685 LogAll "kernelname = $kernelname"
2686 LogAll "kernelpath = $kernelpath"
2687 if [ ! -d "/lib/modules/$kernelname" ]
2688 then
2689 LogAll "Module path for ${kernelpath} not found..."
2690 LogAll "using running kernel\'s modules."
2691 kernelname=$KERVERRUN
2692 else
2693 LogAll "Using modules for kernel: ${kernelname}"
2694 fi
2695###
2696### end of Sq-Modification
2697###
2698 TAPEDEV=$5
2699 TAPESIZE=$6
2700 FILES_IN_FILELIST=$7
2701 USE_LZO=$8
2702 CDRECOVERY=$9
2703 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
2704 IMAGE_DEVS=""
2705 else
2706 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
2707 fi
2708 if [ "${11}" ] ; then
2709 LILO_OPTIONS=""
2710 # LogAll "LILO will use conservative settings, to be compatible with older BIOSes."
2711 fi
2712 ESTIMATED_TOTAL_NOOF_SLICES=${12}
2713 export EXCLUDE_DEVS="${13}"
2714 USE_COMP="${14}"
2715 USE_LILO="${15}"
2716 USE_STAR="${16}"
2717 INTERNAL_TAPE_BLOCK_SIZE="${17}"
2718 DIFFERENTIAL="${18}"
2719 USE_GZIP="${19}"
2720 USE_LZMA="${20}"
2721 [ "$USE_COMP" = "" ] && USE_COMP=yes
2722 [ "$USE_GZIP" = "" ] && USE_GZIP=no
2723 [ "$USE_LZMA" = "" ] && USE_LZMA=no
2724 [ "$TAPEDEV" ] && LogAll "This is a tape-based backup. Fine."
2725 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
2726 kernelname=`echo $kernelpath | cut -d'-' -f2-`
2727 if [ ! -d "/lib/modules/$kernelname" ]
2728 then
2729 LogAll "Module path for ${kernelpath} not found..."
2730 LogAll "using running kernel\'s modules."
2731 kernelname=$KERVERRUN
2732 else
2733 LogAll "Using modules for kernel: ${kernelname}"
2734 fi
2735 # MONDO_ROOT is the real scratchdir
2736 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
2737 if [ _"$MONDO_ROOT" != _"" ]; then
2738 mkdir -p $MONDO_ROOT
2739 else
2740 Die "MONDO_ROOT is undefined"
2741 fi
2742 else
2743 LogScreen "Syntax: mindi (--custom ....)"
2744 MindiExit -1
2745 fi
2746fi
2747
2748if [ _"$MINDI_CACHE" != _"" ]; then
2749 rm -rf $MINDI_CACHE/* 2> /dev/null
2750 mkdir -p $MINDI_CACHE
2751fi
2752
2753[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2754
2755LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
2756LogAll "Latest Mindi is available from http://www.mondorescue.org"
2757LogAll "------------------------------------------------------------------------------"
2758
2759KERN_DISK_MADE=""
2760
2761LogFile "DIFFERENTIAL = $DIFFERENTIAL"
2762LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
2763
2764if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2765 LogAll "Including the generation of a Bootable USB device on $USBDEVICE"
2766fi
2767
2768if [ "$kernelpath" = "" ] ; then
2769 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
2770 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2771 read ch
2772 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2773 USE_OWN_KERNEL="yes"
2774 else
2775 USE_OWN_KERNEL="no"
2776 fi
2777 if [ "$USE_OWN_KERNEL" = "yes" ]; then
2778 kernelpath=`TryToFindKernelPath`
2779 if [ "$kernelpath" = "" ] ; then
2780 echo -n "Please enter kernel path : "
2781 read kernelpath
2782 fi
2783 fi
2784fi
2785LogFile "Mindi's temp dir=$MINDI_TMP"
2786LogFile "Mindi's output dir=$MINDI_CACHE"
2787[ "$(($RANDOM%64))" -eq "0" ] && LogAll "Dude, I've looked inside your computer and it's really dusty..."
2788
2789PrepareDataDiskImages
2790
2791export ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
2792
2793LogFile "Ramdisk will be $ramdisk_size KB"
2794if [ "$ARCH" = "ia64" ] ; then
2795 PrepareBootDiskImage_LILO $kernelpath || Die "Failed to create ia64 image disk image."
2796else
2797 PrepareBootDiskImage_ISOLINUX $kernelpath || Die "Failed to create $ramdisk_size MB disk image."
2798fi
2799
2800[ -e "$MINDI_DATA/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
2801...Or type 'memtest' to test your PC's RAM thoroughly.\n"
2802
2803if [ _"$MONDO_SHARE" = _"" ]; then
2804 ListImagesForUser
2805 OfferToMakeBootableISO
2806 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
2807 OfferToMakeBootableUSB
2808 fi
2809 LogAll "Finished."
2810elif [ "$TAPEDEV" ] ; then
2811 if [ "$ARCH" != "ia64" ] ; then
2812 # We need to keep the img file as boot file for ia64 platform
2813 rm -f $MINDI_CACHE/{*img,*iso}
2814 else
2815 rm -f $MINDI_CACHE/*iso
2816 fi
2817 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2818 OfferToMakeBootableUSB
2819 fi
2820 OfferToMakeBootableISO
2821 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
2822 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
2823 else
2824 Die "Cannot find all.tar.gz, to be written to tape"
2825 fi
2826elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2827 OfferToMakeBootableUSB
2828else
2829 OfferToMakeBootableISO
2830fi
2831# cleanup
2832LogAll "$FRIENDLY_OUTSTRING"
2833for mtpt in $FLOPPY_WAS_MOUNTED ; do
2834 mount $mtpt
2835done
2836MindiExit 0
Note: See TracBrowser for help on using the repository browser.