source: MondoRescue/branches/2.2.9/mindi/mindi@ 2461

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