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

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