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

Last change on this file since 2444 was 2444, checked in by Bruno Cornec, 15 years ago
  • priority given to env var for tmpdir
  • fuse FS excluded from tmpdir computation
  • Improves udev timeout handling
  • fuse device is needed at restore time for sshfs
  • Avoids comment analysis in the new code handling deplist.d
  • Avoids error message if some ssh conf files do not exist
  • Improvements on sshfs/ssh management in restore mode
  • Include now all minimal requirements for sshfs
  • Fix udev support in init for Mandriva 2009.1 (udevadm settle is blocking)
  • Improve deplist.d/* files
  • adds libnss for ssh support in boot disk
  • Solve a memory management issue in DSF module (strtok => mr_strtok)
  • DSF now also supports partitions in addition to full disks
  • Adds debug in open_and_list_dir
  • Improve user management for NetFS cases
  • ssh in the restore env needs some dlopened libs (libnss_compat|files)
  • Warning emited in case of duplicate mountpoints or devices in fstab found
  • Use only the AWK veriable everywhere and not the awk command
  • Simplify GetInitrdFilesystemToUse which doesn't need to detect everything, but just know if it's initramfs (new mode) or a compressed FS ext2/3 (older mode) as initrd is anyway re-made by mindi. Should fix #353

(Backport from 2.2.9)

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