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

Last change on this file since 2446 was 2446, checked in by Bruno Cornec, 15 years ago

r3515@localhost: bruno | 2009-10-02 03:59:06 +0200

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