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

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

analyze-my-lvm now provides an option to call GiveMapperOfdm that can be used in mindi. Solve #395

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