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

Last change on this file since 2708 was 2708, checked in by Bruno Cornec, 13 years ago

r4184@localhost: bruno | 2011-01-27 15:52:51 +0100

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