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

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