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

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

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

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