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

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

r3867@localhost: bruno | 2010-06-10 01:35:22 +0200

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