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

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

r4180@localhost: bruno | 2011-01-27 10:26:41 +0100

  • Fix multiple port issues from 2.2.9 that prevented mindi to work
  • Change interface of call_program_and_get_last_line_of_output to allow not logging (call to mindi)
  • Status is working boot, but NFS interface broken due to conf file issues
  • Property svn:executable set to *
  • Property svn:keywords set to Rev Id
File size: 98.3 KB
RevLine 
[747]1#!/bin/bash
2
3# $Id: mindi 2704 2011-01-27 18:31:24Z 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"
[2696]59SCSI_MODS="3w-xxxx 3w_xxxx 3w_9xxx 3w-9xxx 53c7,8xx a100u2w a320raid aacraid adpahci advansys aha152x aha1542 aha1740 aic79xx aic79xx_mod aic7xxx aic7xxx_mod aic7xxx_old AM53C974 atp870u BusLogic cciss cpqfc dmx3191d dpt_i2o dtc eata eata_dma eata_pio fdomain gdth g_NCR5380 i2o_block i2o_core ide-scsi ieee1394 imm in2000 initio ips iscsi iscsi_tcp libiscsi scsi_transport_iscsi libiscsi_tcp isp megaraid megaraid_mm megaraid_mbox megaraid_sas 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
[940]935 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.DEVICE bootloader.device $outfile
936 AddFileToCfgIfExists $MINDI_TMP/BOOTLOADER.NAME bootloader.name $outfile
937 AddFileToCfgIfExists $MINDI_TMP/TAPEDEV-HAS-DATA-DISKS tapedev-has-data-disks $outfile
[747]938}
939
[2635]940# Get PV's for an LV
941GetPVsForLV() {
942 if [ -n "$1" ]; then
943 vg=`$LVMCMD lvdisplay $1 2>/dev/null |awk '/VG Name/{print $NF;exit}'`
944 if [ -z "$vg" ]; then
945 return
946 fi
947 $LVMCMD vgdisplay -v $vg 2>/dev/null | awk '/PV Name/{print $NF}'
948 fi
949}
[747]950
[2635]951
[747]952MakeMountlist() {
953 local scratchdir mountlist all_partitions current_partition \
954partition_size partition_format outstring partition_number \
955partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
[2013]956absolute_partition old_partition_fmt current_lvolume uname skip
[747]957
[2445]958 LogFile "------------------------------------"
[2341]959 LogFile "Your raw fstab file looks like this:"
960 LogFile "------------------------------------"
[747]961 cat $MY_FSTAB >> $LOGFILE
[2445]962 LogAll "-----------------------------------"
[2341]963 LogAll "Your mountlist will look like this:"
964 LogAll "-----------------------------------"
[747]965
966# scratchdir, mountlist(OUT)
[940]967 scratchdir=$MINDI_TMP
[747]968 mountlist=$1
969
970# NB: partition = device
971# NB: mountpt = where the device is mounted
972
973 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
974
[1684]975 [ "$mountlist" != "" ] && rm -Rf $mountlist
[747]976 > $mountlist
977 all_partitions=""
978
979 if [ $LVM != "false" ]; then
[2445]980 LogFile "Analyzing LVM..."
[2462]981 $MINDI_DATA/analyze-my-lvm > $MINDI_TMP/lvm.res
[971]982 if [ $? -ne 0 ]; then
[963]983 LVM="false"
984 fi
[2546]985 # Excluded LVs and GVs are not reported here
[2428]986 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-`
[747]987 fi
988 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
989 for i in $IMAGE_DEVS ; do
990 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
991 done
992 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
[2462]993 printf "%-15s %-15s %-15s %-15s %s\n" DEVICE MOUNTPOINT FORMAT "SIZE MB" LABEL/UUID | tee -a $LOGFILE
994 printf "%-15s %-15s %-15s %-15s %s\n" ------ ---------- ------ ------- ---------- | tee -a $LOGFILE
[747]995 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"
996 for c_p in $all_partitions ; do
[2460]997 # Skip evices, network FS, cisf
998 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] || [ "`echo "$c_p" | grep -E "^//"`" != "" ]&& continue
[747]999 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
1000 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]1001 current_partition=`readlink -f $c_p`
[747]1002 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
1003 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
1004 else
1005 current_partition="$c_p"
1006 fi
1007 [ "$c_p" = "none" ] && continue
[2193]1008 # Debian 5 does that
1009 [ "$c_p" = "proc" ] && continue
[747]1010 redhat_label=""
[1831]1011 label=""
[957]1012 uuid=""
[861]1013 absolute_partition=`readlink -f $c_p`
[747]1014 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1015
1016 # Detects noauto partitions not mounted and exclude them
1017 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
1018 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then
1019 continue
1020 fi
1021
[1986]1022 # set default in case we dont't find it
1023 str_to_find_fmt_with=$current_partition
1024
[747]1025 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1026 # current_partition contains only first column of /etc/fstab
1027 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
[980]1028 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
[747]1029 actual_dev=""
[853]1030
1031 # 1st try, findfs - the RHEL way of finding labels and their partitions
1032 if [ -x "/sbin/findfs" ]; then
[855]1033 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
[853]1034 fi
[747]1035
[853]1036 # 2nd try : blkid, the good way for all LABEL except swap
1037 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1038 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
[747]1039 # For LVM FS it will give a /dev/dm-# which should then be converted
[748]1040 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1041 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1042 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[747]1043 for dev in `ls /dev/mapper/*`; do
[963]1044 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1045 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[747]1046 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1047 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[747]1048 break
1049 fi
1050 done
1051 fi
1052 fi
1053
[853]1054 # 3rd try, which works on a standard partition (ext2/3), but not on swap
[747]1055 # For LVM gives a /dev/mapper entry
1056 if [ "x$actual_dev" = "x" ]; then
[980]1057 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
[747]1058 fi
1059
[853]1060 # 4th try, with vol_id
[747]1061 # SWAP only
1062 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1063 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
[747]1064 for dev_swap in $list_swaps ; do
1065 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1066 if [ "x$dev_exists" != "x" ]; then
1067 actual_dev=$dev_swap
1068 break;
1069 fi
1070 done
1071 fi
1072
[853]1073 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
[789]1074 # LABEL=SW-cciss/c0d0p3 (RDP)
[853]1075 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
[747]1076 # SWAP only
[789]1077 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
[2013]1078 skip=""
[2293]1079 uname=$KERVERRUN
[2013]1080 [ "`echo $uname | grep "2.4.[0-9]"`" != "" ] && skip=16
1081 # 2.6.12 needs 16 (FC3)
1082 [ "`echo $uname | grep "2.6.[0-1]"`" != "" ] && skip=16
1083 # 2.6.19 and upper needs 1052
1084 [ "`echo $uname | grep "2.6.19"`" != "" ] && skip=1052
1085 [ "`echo $uname | grep "2.6.[2-9]"`" != "" ] && skip=1052
1086 if [ $skip = "" ]; then
1087 Die "Your kernel is too old. I don't know how to support labelled swap spaces with it"
1088 fi
[853]1089 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1090 do
1091 # Location of the swap label for kernel 2.6
[2013]1092 try_dev_label=`dd bs=1 count=16 skip=$skip if=$try_dev 2> /dev/null`
[853]1093 if [ "x$try_dev_label" = "x$redhat_label" ]; then
[855]1094 actual_dev=$try_dev
[853]1095 fi
1096 done
[747]1097 fi
[1008]1098
1099 # Check if one of all those tries has known success
1100 if [ "x$actual_dev" != "x" ]; then
1101 current_partition=$actual_dev
1102 else
[1885]1103 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]1104 fi
[957]1105 # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1106 # current_partition contains only first column of /etc/fstab
[1009]1107 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
[980]1108 uuid=`echo "$current_partition" | cut -d'=' -f2`
[957]1109 actual_dev=""
1110
1111 # 1st try, findfs - the RHEL way of finding labels and their partitions
1112 if [ -x "/sbin/findfs" ]; then
1113 actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1114 fi
1115
[1531]1116 # 2nd try : blkid, the good way for all UUID except swap
[957]1117 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1118 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
[957]1119 # For LVM FS it will give a /dev/dm-# which should then be converted
1120 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1121 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1122 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[957]1123 for dev in `ls /dev/mapper/*`; do
[963]1124 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1125 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[957]1126 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1127 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[957]1128 break
1129 fi
1130 done
1131 fi
1132 fi
1133
1134 # 3th try, with vol_id
1135 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1136 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
[957]1137 for dev in $list_dev ; do
1138 dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1139 if [ "x$dev_exists" != "x" ]; then
1140 actual_dev=$dev
1141 break;
1142 fi
1143 done
1144 fi
1145
[1531]1146 # 4th try, with dumpuuid (VMWare only ?) for swap
1147 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1148 list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1149 for dev in $list_dev ; do
1150 dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1151 if [ "x$dev_exists" != "x" ]; then
1152 actual_dev=$dev
1153 break;
1154 fi
1155 done
1156 fi
1157
[747]1158 # Check if one of all those tries has known success
1159 if [ "x$actual_dev" != "x" ]; then
1160 current_partition=$actual_dev
1161 else
[2069]1162 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]1163 fi
1164 else
[1863]1165 # Needs to handle the recent OpenSUSE fancy way of dealing with fstab :-(
1166 # they use symlinks in fstab unrelated to what is shown in mount !
1167 if [ _"$partition_mountpt" = _"" ]; then
[1986]1168 # set default in case we dont't find it
[1863]1169 for tmpp in `tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -Ev "^#" | $AWK '{print $1}'`; do
[1864]1170 if [ _"`readlink -f $tmpp`" = _"$current_partition" ]; then
[1863]1171 str_to_find_fmt_with=$tmpp
[1865]1172 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$tmpp" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
[1864]1173 break;
[1863]1174 fi
1175 done
1176 fi
[747]1177 fi
1178
[2569]1179 # Look for devices which have to be excluded
1180 skip=0
1181 if [ "$MINDI_EXCLUDE_DEVS" ] ; then
[2576]1182 l=""
1183 list_of_devices="`ReadAllLink $current_partition`"
1184 for d in $list_of_devices; do
[2587]1185 l="$l `$MINDI_LIB/analyze-my-lvm --givemapperofdm $d`"
[2576]1186 done
[2635]1187
1188 # Remove PVs from LVs excluded
1189 l="$l `GetPVsForLV $current_partition`"
1190
1191 # We want a single unique list
[2576]1192 list_of_devices="`echo $l | sort -u`"
[2635]1193
[2569]1194 for d in $MINDI_EXCLUDE_DEVS ; do
[2576]1195 if [ "`echo " $list_of_devices " | grep " $d"`" != "" ]; then
[2569]1196 echo "Excluding $current_partition from mountlist (due to excluded device $d)" >> $LOGFILE
1197 skip=1
1198 continue
1199 fi
1200 done
1201 fi
1202 if [ $skip -eq 1 ]; then
1203 continue
1204 fi
1205
[747]1206 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1207 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1208 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1209 # the former is then a link to the latter, so we test whether
1210 # $current_partition is actually such a link or not and set
[755]1211 # $current_lvolume accordingly. On Debian you may find more than one answer
1212 # so we remove the one corresponding to /dev/.static
1213 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1214 # principle is the same and we need to find the link to it as well.
1215 # Note that $current_lvolume may well be an
[747]1216 # ordinary device. It is just to make sure that we feed the right value
1217 # into any of the LVM tools if possible.
1218
1219 current_lvolume="$current_partition"
[763]1220 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
[755]1221 # .static dir are a Debian specificity
[763]1222 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
[755]1223 echo $current_lvolume | grep -q ' '
[784]1224 if [ $? -eq 0 ]; then
[2341]1225 LogFile "WARNING: Multiple Logical Volumes found. Report to dev team"
[755]1226 fi
[2072]1227 # if it's not found, it may well be a real device such as a multipath one
1228 # /dev/mapper/mpath... Thus we revert the situation so that next test succeed
1229 if [ _"$current_lvolume" = _"" ]; then
1230 current_lvolume="$current_partition"
1231 fi
[747]1232 fi
1233 #
1234 # End of LVM device style variation code (other than $current_lvolume).
1235
[745]1236 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1237 # Size computed via LVM not directly
[747]1238 partition_size="lvm"
1239 else
1240 partition_size=`SizeOfPartition $current_partition`
1241 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1242 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1243 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1244 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1245 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1246 [ "$partition_format" != "swap" ] && partition_format="swap"
1247 if [ "$partition_size" = "" ] ; then
1248 totalsize=0
1249 items=0
1250 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1251 totalsize=$(($totalsize+$i))
1252 items=$(($items+1))
1253 done
1254 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1255 [ "$partition_size" -lt "125000" ] && partition_size=125000
[2341]1256 LogFile "I'm guessing $c_p is $(($partition_size/1024))MB"
[747]1257 fi
1258 fi
1259 fi
1260 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1261 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1262 if [ "$partition_mountpt" = "" ] ; then
1263 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1264 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1265 partition_mountpt="raid"
1266 partition_format="raid"
1267 else
1268 partition_mountpt="lvm"
1269 partition_format="lvm"
1270 fi
1271 fi
1272 fi
1273 psz=$partition_size
[2341]1274 LogFile "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)"
[747]1275 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1276 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1277 partition_mountpt="image"
1278 old_partition_fmt=$partition_format
1279 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1280 partition_size=$(($partition_size+1)); # just in case
1281 if [ "$partition_format" = "Linux" ] ; then
[2341]1282 LogFile "Are you imaging a mounted swap partition? Silly..."
1283 LogFile "Reverting format from $old_partition_fmt to $partition_format"
[747]1284 partition_format=$old_partition_fmt
1285 fi
1286 fi
[2569]1287
[747]1288 if [ ! "$partition_mountpt" ] ; then
[2341]1289 LogFile "------- $FDISK -l $qq log ------------"
[1883]1290 for qq in "" `find /dev/ida/c*d* ! -name '*p*' 2> /dev/null`; do
[747]1291 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1292 [ "$partition_format" ] && break
1293 done
[2341]1294 LogFile "------- $FDISK log end ------------"
[747]1295 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1296 partition_format="compaq"
1297 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
[2341]1298 LogAll "Unable to find mountpoint of $current_partition - ignoring"
[747]1299 continue
1300 fi
1301 fi
[1755]1302 if [ "$redhat_label" ]; then
1303 label="$redhat_label"
[1756]1304 elif [ "$uuid" ]; then
[1755]1305 label="$uuid"
1306 fi
[747]1307 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
[963]1308 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
[2445]1309 unofficial_outstring=`printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
[747]1310 if [ "$current_partition" = "" ] ; then
[2341]1311 LogFile "Unknown partition (outstring = $unofficial_outstring)"
[747]1312 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1313 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1314 partition_mountpt=raid
1315 partition_format=raid
[2445]1316 printf "%-15s %-15s %-15s %7s %15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
[1755]1317 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1318 else
[2341]1319 LogFile "Unknown mountpoint (outstring = $unofficial_outstring)"
[747]1320 fi
1321 elif [ "$partition_format" = "" ] ; then
[2341]1322 LogFile "Unknown format (outstring = $unofficial_outstring)"
[747]1323 elif [ "$partition_size" = "" ] ; then
[2341]1324 LogFile "Unknown partition size (outstring = $unofficial_outstring)"
[747]1325 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1326 continue
1327 else
1328 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
[2444]1329 LogFile "vfat should be used instead of dos/msdos as a partition format"
[747]1330 partition_format="vfat"
1331 fi
[2445]1332 printf "%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
[1755]1333 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1334 fi
1335 done
[2445]1336 LogAll "-----------------------------------"
[747]1337}
1338
[2444]1339CheckMountlist() {
1340 local file=$1
1341 # Coherency verification
[2546]1342 ML01=`cat $file | wc -l`
[2587]1343 ML02=`grep -v ' lvm ' $file | wc -l`
[2444]1344 ML1=`$AWK '{print $1}' $file | sort -u | wc -l`
[2587]1345 ML2=`grep -v ' lvm ' $file | $AWK '{print $2}' | sort -u | wc -l`
[2546]1346 if [ "$ML01" -ne "$ML1" ]; then
[2444]1347 LogFile "--------------------------------------------"
1348 echo "WARNING: Duplicate device entry in mountlist" | tee -a $LOGFILE
1349 LogFile "--------------------------------------------"
1350 fi
[2546]1351 if [ "$ML02" -ne "$ML2" ]; then
[2444]1352 LogFile "--------------------------------------------"
1353 echo "WARNING: Duplicate mountpoint entry in mountlist" | tee -a $LOGFILE
1354 LogFile "------------------------------------------------"
1355 fi
1356}
[747]1357
1358OfferToMakeBootableISO() {
1359 local i old_pwd
[2460]1360 if [ -z "$ISO_CMD" ]; then
[2635]1361 LogFile "Neither mkisofs nor genisoimage found, unable to make CD image"
[2460]1362 return
1363 fi
[1684]1364 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[966]1365 echo -en "Shall I make a bootable CD image? (y/[n]) "
[747]1366 read i
1367 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1368 fi
[940]1369 rm -Rf $MINDI_TMP/iso
[1983]1370 mkdir -p $MINDI_TMP/iso/{images,archives}
[2341]1371 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]1372 LogFile "mindi_lib = $MINDI_DATA"
[747]1373 for i in memdisk memtest.bin memtest.img ; do
[2462]1374 j=$MINDI_DATA/$i
[1983]1375 k=$MINDI_TMP/iso
[953]1376 if [ -e "$j" ] ; then
[2341]1377 LogAll "Copying $j to $k"
[2092]1378 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1379 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
[1885]1380 if [ _"$MONDO_SHARE" != _"" ]; then
[2598]1381 cp -f $j $MONDO_CACHE 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_CACHE"
[1885]1382 fi
[953]1383 fi
[747]1384 done
[1983]1385 MakeMessageFile > $MINDI_TMP/iso/message.txt
[2635]1386 if [ $KERNEL_IS_XEN = "yes" ]; then
1387 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?"
1388 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?"
1389 fi
[2696]1390 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?"
1391 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]1392
[1885]1393 if [ _"$MONDO_SHARE" != _"" ]; then
[2696]1394 if [ $KERNEL_IS_XEN = "yes" ]; then
1395 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?"
1396 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?"
1397 fi
[2598]1398 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?"
1399 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]1400 fi
[2073]1401 MakeBootConfFile isolinux > $MINDI_TMP/iso/isolinux.cfg
[747]1402 if [ "$ARCH" != "ia64" ] ; then
[2092]1403 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]1404 fi
[1983]1405 old_pwd=`pwd`
[940]1406 cd $MINDI_TMP/iso
[2603]1407 LogFile "-------------------"
1408 LogFile "Content of the ISO:"
1409 LogFile "-------------------"
1410 ls -Rla >> $LOGFILE
1411 LogFile "-------------------"
1412
[747]1413 if [ "$ARCH" != "ia64" ] ; then
[1885]1414 if [ _"$MONDO_SHARE" != _"" ]; then
[2704]1415 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]1416 if [ $KERNEL_IS_XEN = "yes" ]; then
[2704]1417 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]1418 fi
[1983]1419 cp -f $MONDO_SHARE/autorun $MINDI_TMP/iso 2>> $LOGFILE
[1885]1420 fi
[1983]1421 $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]1422 else
[1983]1423 $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]1424 fi
1425 if [ "$?" -ne "0" ] ; then
[2341]1426 LogFile "----------- $ISO_CMD's errors --------------"
[940]1427 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
[1885]1428 echo "$ISO_CMD returned the following errors:-"
[940]1429 cat $MINDI_TMP/mkisofs.log
[2341]1430 LogAll "Failed to create ISO image."
[747]1431 else
[2341]1432 LogAll "Created bootable ISO image at $MINDI_CACHE/mindi.iso"
[747]1433 fi
[940]1434 rm -f $MINDI_TMP/mkisofs.log
[747]1435 cd $old_pwd
1436}
1437
1438
[1684]1439OfferToMakeBootableUSB() {
[2041]1440 local i
[1684]1441 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[2635]1442 echo -n "Shall I make a bootable USB device ? (y/[n]) "
[1764]1443 read i
1444 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1445 if [ "$USBDEVICE" = "" ]; then
1446 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1447 read dev
1448 USBDEVICE=$dev
[1722]1449 fi
[1764]1450 echo "WARNING: This will erase all content on $USBDEVICE"
1451 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
[2040]1452 read i
1453 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
[1684]1454 fi
1455 rm -Rf $MINDI_TMP/usb
1456 mkdir -p $MINDI_TMP/usb
1457 USBPART="${USBDEVICE}1"
1458
1459 echo -en "Transforming $USBDEVICE in a Bootable device "
1460 echo -en "."
[2341]1461 LogFile "Transforming $USBDEVICE in a Bootable device"
1462 LogFile "Checking $USBDEVICE"
[1857]1463 $FDISK -l $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE
[1684]1464 if [ $? -ne 0 ]; then
[2341]1465 LogAll "Unable to access $USBDEVICE"
1466 LogAll "Make sure your USB device is pluged in"
[1684]1467 exit -1
1468 fi
1469 echo -en "."
[2488]1470 # Some distro do auto mount at that point (Ubuntu)
[2462]1471 LogFile "Unmounting $USBPART just in case"
[1721]1472 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
[2057]1473 # If your key has no MBR it may cause an issue
1474 # Use dd if=mbr.bin of=$USBDEVICE or ms-sys -s $USBDEVICE
[2341]1475 LogFile "Preparing $USBDEVICE"
[1721]1476 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
[2057]1477d
1478d
1479d
1480d
[1684]1481n
1482p
14831
1484
1485
1486t
1487b
1488a
14891
1490w
1491EOF
1492 if [ $? -ne 0 ]; then
[2341]1493 LogAll "Unable to create a vfat Filesystem on $USBDEVICE"
1494 LogAll "Make sure your USB device is pluged in"
[1684]1495 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1496 MindiExit -1
1497 fi
[2341]1498 LogFile "The USB device $USBDEVICE now looks like this:"
[2190]1499 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1684]1500 echo -en "."
[2462]1501 # Some distro do auto mount at that point (Ubuntu)
1502 LogFile "Unmounting $USBPART just in case again"
1503 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
1504 echo -en "."
[2341]1505 LogFile "Creating a vfat filesystem on $USBPART"
[1688]1506 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
[1684]1507 if [ $? -ne 0 ]; then
[2341]1508 LogAll "Unable to create a vfat filesystem on $USBPART"
1509 LogAll "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)"
[1684]1510 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1511 MindiExit -1
1512 fi
1513 echo -en "."
[2341]1514 LogFile "Mounting $USBPART on $MINDI_TMP/usb"
[1684]1515 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1516 if [ $? -ne 0 ]; then
[2341]1517 LogAll "Unable to mount $USBPART on $MINDI_TMP/usb"
1518 LogAll "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)"
[1684]1519 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
1520 MindiExit -1
1521 fi
1522 echo -en "."
[1691]1523 mkdir -p $MINDI_TMP/usb/images
[2341]1524 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]1525 echo -en "."
[2462]1526 LogFile "mindi_lib = $MINDI_DATA"
[1684]1527 for i in memdisk memtest.bin memtest.img ; do
[2462]1528 j=$MINDI_DATA/$i
[1684]1529 k=$MINDI_TMP/usb
1530 if [ -e "$j" ] ; then
[2341]1531 LogAll "Copying $j to $k"
[2092]1532 cp -f $j $k 2>> $LOGFILE || Die "Failed to copy $j to $k"
1533 cp -f $j $MINDI_TMP 2>> $LOGFILE || Die "Failed to copy $j to $MINDI_TMP"
[1684]1534 fi
1535 done
1536 echo -en "."
[1983]1537 MakeMessageFile > $MINDI_TMP/usb/message.txt
[1684]1538 echo -en "."
[2092]1539 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]1540 echo -en "."
[1983]1541 cp $MINDI_TMP/initrd.img $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
[1684]1542 echo -en "."
[2041]1543 MakeBootConfFile syslinux > $MINDI_TMP/usb/syslinux.cfg
[1684]1544 echo -en "."
[2508]1545 LogAll "----------- syslinux's conf --------------"
[2481]1546 cat $MINDI_TMP/usb/syslinux.cfg |tee -a $LOGFILE
[2508]1547 LogAll "------------------------------------------"
[2603]1548 LogFile "--------------------------"
1549 LogFile "Content of the USB device:"
1550 LogFile "--------------------------"
1551 (cd $MINDI_TMP/usb ; ls -Rla) >> $LOGFILE
1552 LogFile "--------------------------"
1553
[1721]1554 umount $MINDI_TMP/usb
[1684]1555 if [ "$ARCH" != "ia64" ] ; then
[2056]1556 syslinux -s $USBPART 2>> $MINDI_TMP/syslinux.log
[1684]1557 if [ "$?" -ne "0" ] ; then
[2508]1558 LogAll "----------- syslinux's errors --------------"
[1684]1559 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
[2514]1560 echo "------------------------------------------"
[2341]1561 LogAll "Failed to create USB image."
[1684]1562 else
1563 echo -e "$DONE"
[2341]1564 LogFile "Created bootable USB image on $USBDEVICE"
[1684]1565 fi
1566 rm -f $MINDI_TMP/syslinux.log
1567 else
[2341]1568 echo "No USB boot support for ia64"
[1684]1569 MindiExit -1
1570 fi
1571}
1572
1573
[747]1574MakeMessageFile() {
[2293]1575
1576 if [ -x "/bin/lsb_release" ]; then
1577 DESC=`/bin/lsb_release -d | cut -d: -f2 | sed "s/[ \t]*//"`
1578 elif [ -x "/usr/bin/pbdistrocheck" ]; then
1579 # For pb >= 0.9.8
1580 DESC=`/usr/bin/pbdistrocheck -d`
[747]1581 else
[2293]1582 iss="/dev/null"
1583 [ -r /etc/issue.net ] && iss="/etc/issue.net"
1584 [ -r /etc/issue ] && iss="/etc/issue"
1585 DESC=`head -1 $iss`
[747]1586 fi
[2462]1587 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]1588 if [ _"$MONDO_SHARE" != _"" ]; then
1589 if [ "$CDRECOVERY" != "yes" ] ; then
[2382]1590 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[1885]1591 echo -en "Press <enter> to continue.\n"
1592 elif [ ! "$MINDI_TMP" ] ; then
1593 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
[2462]1594 if [ -e "$MINDI_DATA/memtest.img" ] ; then
[1983]1595 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n"
1596 fi
[1885]1597 else
1598 echo -en "$BOOT_MEDIA_MESSAGE"
[747]1599 fi
[1983]1600 else
1601 echo -en "\
[747]1602To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1603CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
[1983]1604 fi
[747]1605 fi
1606 echo -en "\n\n\n"
1607}
1608
1609
[1983]1610MakeBootConfFile() {
[1885]1611 local options i ooo
[747]1612 options=""
[1983]1613 # Type of boot file (elilo or syslinux/isolinux)
1614 type=$1
1615 if [ "$type" = "elilo" ]; then
1616 sep="="
1617 else
1618 sep=" "
1619 fi
[925]1620
[1983]1621 # Generic header for conf file
1622 if [ "$type" != "elilo" ] ; then
1623 echo -en "prompt 1\ndisplay message.txt\n"
1624 else
1625 echo -en "prompt\n"
[925]1626 fi
[1983]1627
1628 # Compute which default option to boot from
[747]1629 if [ "$CDRECOVERY" = "yes" ] ; then
[1983]1630 echo -en "default${sep}RESTORE\n"
1631 # In case it's mondoarchive
[1885]1632 elif [ _"$MONDO_SHARE" != _"" ]; then
[2382]1633 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[1983]1634 echo -en "default${sep}iso\n"
[747]1635 else
[1983]1636 echo -en "default${sep}interactive\n"
[747]1637 fi
1638 else
[1983]1639 echo -en "default${sep}expert\n"
[747]1640 fi
1641
[1983]1642 # Handle timeout
[747]1643 if [ "$CDRECOVERY" != "yes" ] ; then
[1983]1644 echo -en "timeout${sep}300\n"
1645 else
1646 echo -en "timeout${sep}10000\n"
[747]1647 fi
1648 echo -en "\n"
[1983]1649
[2124]1650 # prepare which labels will be generated
[747]1651 if [ "$CDRECOVERY" = "yes" ] ; then
[925]1652 options="RESTORE expert"
[1885]1653 else
1654 if [ _"$MONDO_SHARE" != _"" ]; then
[2345]1655 options="interactive expert compare iso nuke isonuke"
[747]1656 else
1657 options="expert"
[925]1658 fi
[747]1659 fi
[1983]1660
1661 # Generate rest of conf file
[747]1662 for i in $options ; do
[925]1663 ooo=$i
1664 [ "$ooo" = "RESTORE" ] && ooo="nuke"
[1983]1665 if [ "$type" = "elilo" ]; then
[2569]1666 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]1667 else
[2073]1668 ps="/"
1669 if [ "$type" = "syslinux" ]; then
1670 ps=""
1671 fi
[2635]1672 if [ $KERNEL_IS_XEN = "no" ]; then
1673 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"
1674 else
1675 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"
1676 fi
[925]1677 fi
[1885]1678 echo -en "$outstr"
[747]1679 done
[2462]1680 if [ -e "$MINDI_DATA/memtest.img" ] ; then
[1983]1681 if [ "$type" = "elilo" ]; then
1682 echo -en "image=/memtest.bin\n\tlabel=memtest\n"
[2073]1683 echo -en "image=/memdisk\n\tlabel=memdisk\nappend=\"initrd=memtest.img\"\n"
[1983]1684 else
[2073]1685 ps="/"
1686 if [ "$type" = "syslinux" ]; then
1687 ps=""
1688 fi
1689 echo -en "label memtest\n\tkernel ${ps}memtest.bin\n"
1690 echo -en "label memdisk\n\tkernel ${ps}memdisk\nappend initrd=${ps}memtest.img\n"
[1983]1691 fi
1692 fi
[747]1693}
1694
1695
[2488]1696
1697PrepareBootDiskImage() {
1698 local imagesdir dev imagefile mountpoint fname i kernelpath cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage liloconf mountefi
[1983]1699 imagesdir=$MINDI_CACHE
1700 kernelpath=$1
[2488]1701 do_boot_root_thingy=""
1702 retval=0
[747]1703
[2696]1704 [ ! -e "$kernelpath" ] && Die "PBDI lilo - cannot find $kernelpath kernel"
[1885]1705 echo -en "Making "$BOOT_SIZE"KB boot disk..."
[2462]1706 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]1707 echo -en "..."
[2488]1708 imagefile=$MINDI_CACHE/mindi-bootroot.$BOOT_SIZE.img
[940]1709 mountpoint=$MINDI_TMP/mountpoint.$$
[747]1710 mkdir -p $mountpoint
[1885]1711 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[2488]1712 LogFile "Creating vfat filesystem on $imagefile"
[1983]1713 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
[2488]1714 if [ "$ARCH" != "ia64" ] ; then
1715 # syslinux should be run on a local file (doen't work through NFS Cf: #297)
1716 # Ensure that $MINDI_CACHE is not on NFS (it shouldn't)
1717 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
1718 fi
1719
[2341]1720 mount -t vfat -o loop $imagefile $mountpoint || LogAll "Cannot mount (PBDI)"
[2488]1721
[964]1722 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]1723 mkdir -p $mountpoint/etc
[1983]1724 liloconf=$mountpoint/elilo.conf
[747]1725
[2488]1726 MakeMessageFile > $mountpoint/message.txt
[747]1727
[2488]1728 if [ "$ARCH" != "ia64" ] ; then
1729 MakeBootConfFile isolinux > $mountpoint/syslinux.cfg
1730 else
1731 MakeBootConfFile elilo > $liloconf
1732 # Copy it so that CD-ROM menu entry is satisfied
1733 mountefi=0
1734 df -T | grep /boot/efi | grep -q vfat
[1230]1735 if [ $? -ne 0 ]; then
[2488]1736 mount /boot/efi
1737 if [ $? -ne 0 ]; then
1738 echo "You have to mount your EFI partition when using mindi"
1739 MindiExit -1
1740 fi
1741 mountefi=1
[1230]1742 fi
[2488]1743 el=`find /boot/efi -name elilo.efi`
1744 cp $el $mountpoint
1745 cp $liloconf $mountpoint
1746 if [ $mountefi -eq 1 ]; then
1747 umount /boot/efi 2>&1 > /dev/null
[747]1748 fi
1749 fi
1750
[2341]1751 LogFile "Copying $MINDI_TMP/initrd.img to $mountpoint/initrd.img..."
[1983]1752 cp -f $MINDI_TMP/initrd.img $mountpoint/initrd.img 2>> $LOGFILE
[747]1753 if [ "$?" -ne "0" ] ; then
[2341]1754 LogAll "Failed to copy $MINDI_TMP/initrd.img to $mountpoint"
[940]1755 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[2341]1756 LogAll "Please unload some of your modules and try again."
[940]1757 rm -f $MINDI_TMP/mtpt.$$
[2341]1758 LogAll "Cannot incorporate initrd.img in bootdisk (kernel / modules too big?)"
[747]1759 retval=$(($retval+1))
1760 fi
1761
[925]1762 # copy the kernel across
[1230]1763 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]1764 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
[1796]1765 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
[2635]1766
1767 retval=0
[2696]1768 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
1769 retval=$?
1770 if [ $KERNEL_IS_XEN = "yes" ]; then
[2635]1771 cp -f $xenkernelpath $mountpoint/xenkernel &> /dev/null
1772 let retval+=$?
1773 fi
1774
1775 if [ "$retval" -ne "0" ] ; then
[2341]1776 LogFile "Files at mountpoint ($mountpoint) :-"
[747]1777 du -sk $mountpoint/* >> $LOGFILE
[2341]1778 LogFile "--- end of list of files ---"
[2696]1779 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n" >> $LOGFILE
[1998]1780 [ "$mountpoint" != "" ] && rm -f $mountpoint/vmlinuz
[747]1781 cd $old_pwd
1782 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[2341]1783 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
[747]1784
[2488]1785 rm -f $imagefile
[1885]1786 return 0
[747]1787 fi
1788 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
[2341]1789 LogFile "Free space left on image = $free_space KB"
1790 LogFile "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K"
[925]1791
1792 # make it bootable
[1998]1793 [ "$mountpoint" != "" ] && rm -f $mountpoint/zero
[2462]1794 [ -e "$MINDI_DATA/memdisk" ] && cp -f $MINDI_DATA/memdisk $mountpoint 2>> $LOGFILE
[2488]1795
1796 if [ "$ARCH" = "ia64" ] ; then
1797 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
1798 fi
[747]1799 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1800 echo -en "..."
[2341]1801 rmdir $mountpoint || LogAll "Cannot rmdir (PBDI)"
[747]1802
1803 if [ "$retval" -eq "0" ] ; then
[1885]1804 echo -en "...$DONE\n"
[2488]1805 LogAll "$BOOT_SIZE KB boot disk was created OK\n"
[747]1806 else
[1885]1807 echo -en "...failed\n"
[2488]1808 LogAll "$BOOT_SIZE KB boot disk was NOT created\n"
1809 rm -f $imagefile
[747]1810 fi
[2341]1811 [ "$retval" -ne "0" ] && LogAll "PrepareBootDiskImage() is returning nonzero"
[747]1812 return $retval
1813}
1814
1815
[2006]1816ParseModprobeForIncludes() {
1817local MODPROBE_CONF mpincfile includes include
1818
1819MODPROBE_CONF=/etc/modprobe.conf
1820mpincfile=$1
1821touch $mpincfile
1822if [ -a $MODPROBE_CONF ]; then
[2444]1823 includes=$($AWK '/^[ \t]*include[ \t]+/ {if(NF>=2){print $2}}' $MODPROBE_CONF|sort -u)
[2006]1824 if [ -n "$includes" ]; then
1825 for include in $includes
1826 do
1827 if [ -a "$include" ]; then
1828 echo $include >> $mpincfile
1829 fi
1830 done
1831 fi
1832fi
1833}
1834
1835
[747]1836PrepareDataDiskImages() {
[2006]1837 local needlist bigdir diskdir imagesdir res i j k old_pwd lines lfiles includefile
[747]1838
[1983]1839 imagesdir=$MINDI_CACHE
[1902]1840 rm -f $imagesdir/mindi.iso
[940]1841 needlist=$MINDI_TMP/what-we-need.txt
1842 bigdir=$MINDI_TMP/bigdir
[747]1843 mkdir -p $bigdir/usr/bin
[1983]1844 mkdir -p $bigdir/usr/sbin
[2006]1845 includefile=$MINDI_TMP/$$.includefile.txt
[747]1846
[2445]1847 lfiles=`ls $DEPLIST_DIR/* | grep -v /minimal`
[2412]1848 if [ -e "$DEPLIST_FILE" ]; then
[2445]1849 lfiles="$DEPLIST_FILE $lfiles"
[2412]1850 fi
[1885]1851 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
[2006]1852 ParseModprobeForIncludes $includefile
[2019]1853 lines=$(($lines+`cat $includefile | wc -l`))
[2006]1854 cat $lfiles $includefile | GenerateGiantDependencyList $needlist $lines
[747]1855 res=$?
[2006]1856 rm -f $includefile
[2462]1857 # This function appends to the file passed in param
1858 ListKernelModulePaths $needlist
[747]1859 if [ "$res" -ne "0" ] ; then
[1902]1860 Die "You have $res files present in dependency list\nbut absent from filesystem."
[747]1861 fi
[2603]1862 FindAndAddUserKeyboardMappingFile
[747]1863 mkdir -p $bigdir/tmp
1864 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
1865 DropOptimizedLibraries $needlist $bigdir
1866 echo -en "Assembling dependency files"
1867
[2445]1868 CopyDependenciesToDirectory < $needlist $bigdir `wc -l $needlist`
1869
[925]1870 # also copy io.sys and msdos.sys, if we can find them
[747]1871 for i in `mount | cut -d' ' -f3` ; do
[925]1872 for j in io.sys msdos.sys ; do
[963]1873 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
[925]1874 done
[747]1875 done
1876
[925]1877 # master boot record, too
[940]1878 i=`cat $MINDI_TMP/BOOTLOADER.DEVICE 2> /dev/null`
[747]1879 if [ "$i" ] ; then
[2341]1880 LogAll "Backing up $i's MBR"
[925]1881 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
1882 sleep 1
1883 sync
1884 j=$i
1885 [ -h "$j" ] && j=`readlink -f $j`
[2341]1886 LogAll "Creating /dev/boot_device ($j)"
[925]1887 mkdir -p $bigdir/dev
[2089]1888 cp -pRdf $j $bigdir/dev/boot_device 2>> $LOGFILE || Die "Unable to create /dev/boot_device on ramdisk"
[747]1889 fi
1890
1891 old_pwd=`pwd`
1892 cd $bigdir
1893
[1983]1894 # Get terminfo content
1895 ti="usr/share/terminfo/l"
1896 if [ -d /$ti ]; then
1897 mkdir -p $ti
[2341]1898 cp -Rdf /$ti/* $ti 2>> $LOGFILE || LogAll "WARNING - error occurred while copying terminfo"
[747]1899 fi
[1764]1900 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
[747]1901 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
[1335]1902 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
[747]1903 fi
[2291]1904 if [ -d "/lib/dev-state" ]; then
[2341]1905 tar cf - -C / ./lib/dev-state 2>> $MINDI_TMP/$$.log | tar xf - || LogAll "Unable to handle /lib/dev-state" $MINDI_TMP/$$.log
[2291]1906 fi
[747]1907 cd $old_pwd
1908 echo -e "$DONE"
1909 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
[1902]1910 mkdir -p $bigdir/tmp
[2032]1911 if [ $LVM != "false" ]; then
[2644]1912 mkdir -p $bigdir$MINDI_CACHE
[2623]1913 $MINDI_DATA/analyze-my-lvm > $bigdir$MINDI_CACHE/i-want-my-lvm
[2032]1914 if [ "$?" -ne "0" ]; then
1915 LVM="false"
[2623]1916 rm -f $bigdir$MINDI_CACHE/i-want-my-lvm
[2569]1917 else
[2589]1918 LogFile "Your i-want-my-lvm file content is:"
1919 LogFile "-----------------------------------"
[2623]1920 cat $bigdir$MINDI_CACHE/i-want-my-lvm >> $LOGFILE
[2589]1921 LogFile "-----------------------------------"
[2032]1922 fi
1923 fi
[2444]1924
[1902]1925 echo -en "Tarring and zipping the data content..."
1926 size_of_all_tools=`du -sk $bigdir | cut -f1`
[2341]1927 (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]1928 LogFile "Size of the data content"
1929 LogFile "------------------------"
[1902]1930 du -sk $imagesdir/*gz >> $LOGFILE
[2462]1931 LogFile "------------------------"
[1902]1932 echo -e "$DONE"
1933
[747]1934 FRIENDLY_OUTSTRING="Boot and data disk images were created."
[1902]1935 rm -rf $bigdir
[747]1936 rm -f $needlist
1937}
1938
1939
1940ProcessLDD() {
[1784]1941 local incoming f d nd bd bnd
[747]1942 read incoming
[1784]1943 while [ "$incoming" != "" ]; do
[859]1944 # We take the full path name of the dyn. lib. we want
[2444]1945 incoming=`echo "$incoming" | $AWK '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
[1526]1946 for f in $incoming ; do
[1784]1947 # echo modified file name if one of the parent dir is a link
1948 # by replacing the original dirname by the destination of the link
1949 d="`dirname $f`"
1950 found="false"
1951 while [ "$d" != "/" ]; do
1952 if [ -h "$d" ]; then
1953 nd=`readlink -f $d`
1954 bd=`basename $d`
1955 bnd=`basename $nd`
1956 f=`echo $f | sed "s~/$bd/~/$bnd/~"`
1957 echo $d
1958 fi
1959 d="`dirname $d`"
1960 done
1961
[1721]1962 echo "$f"
1963 echo "`ReadAllLink $f`"
[747]1964 done
1965 read incoming
1966 done
1967}
1968
1969
1970Prompt() {
1971 echo -en "$1"
1972 read line
1973}
1974
1975
1976ReadLine() {
1977 local i incoming
1978 read incoming
1979 i=0
1980 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
[925]1981 i=$(($i+1))
1982 read incoming
[747]1983 done
1984 echo "$incoming"
1985}
1986
1987
1988SizeOfPartition() {
1989 local devpath drive res stub
1990 device=$1
1991 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
[925]1992 res=`SizeOfRaidPartition $device`
1993 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
1994 echo "$res"
1995 return 0
[747]1996 fi
[925]1997 # patch from Bill <bill@iwizard.biz> - 2003/08/25
[960]1998 res=`$FDISK -s $device 2>> $LOGFILE`
[925]1999 # end patch
[2451]2000 # take only the first in case of multiple mount (cifs, nfs, ...)
2001 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2 | head -1`
[747]2002 [ "$res" = "" ] && res="-1"
2003 echo $res
2004 return 0
2005}
2006
2007
2008SizeOfRaidPartition() {
2009 local real_dev smallest_size silly tmp
2010
2011 silly=999999999
2012 smallest_size=$silly
2013
2014 for real_dev in `GetRaidDevMembers $1` ; do
[925]2015 tmp=`SizeOfPartition $real_dev`
2016 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
[747]2017 done
2018
2019 if [ "$smallest_size" = "$silly" ] ; then
[925]2020 echo "-1"
2021 return 1
[747]2022 else
[925]2023 echo "$smallest_size"
2024 return 0
[747]2025 fi
2026}
2027
2028
2029StripExecutable()
2030{
2031 local tmpfile
[925]2032
[940]2033 tmpfile=$MINDI_TMP/stripped.$$.dat
[747]2034 [ -d "$1" ] || [ -h "$1" ] && return
[963]2035 cp -f $1 $tmpfile 2>> $LOGFILE
[747]2036 strip $tmpfile 2> /dev/null
2037 if [ "$?" -eq "0" ] ; then
[963]2038 cp -f $tmpfile $1 2>> $LOGFILE
[2341]2039 LogFile "Stripped binary $2"
[747]2040 fi
2041 rm -f $tmpfile
2042}
2043
[2293]2044KernelVer() {
2045 local fkern_ver fname
[747]2046
[2293]2047 fname=$1
2048 file $fname | grep -q gzip
2049 if [ "$?" -eq "0" ] ; then
2050 # Used by ia64
2051 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2052 else
2053 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
2054 fi
2055 echo "$fkern_ver"
2056}
2057
2058
[747]2059TryToFindKernelPath() {
2060 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
[925]2061
[2293]2062 we_want_version=$KERVERRUN
[747]2063 possible_kernels=""
2064 duff_kernels=""
2065
2066 if [ "$ARCH" = "ia64" ] ; then
2067 root="/boot/efi/efi"
2068 else
2069 root="/"
2070 fi
[2696]2071 # See if we're booted from a Xen kernel
2072 if [ -d /proc/sys/xen ]; then
2073 # It's a Xen kernel
2074 KERNEL_IS_XEN="yes"
2075 LogIt "It's a Xen kernel..."
2076 fi
2077
2078 for fname in `find $root -maxdepth 2 -type f | grep -Ei 'lin|kern|xen' | grep -Ev '^/proc/|^/net/'` ; do
[925]2079 [ ! -e "$fname" ] && continue
[747]2080 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
[2293]2081 fkern_ver=`KernelVer $fname`
[747]2082 [ "$fkern_ver" = "" ] && continue
2083 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
[925]2084 [ -f "$fname" ] || continue
2085 [ -h "$fname" ] && continue
2086 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2087 file $fname | grep -q gzip
2088 if [ "$?" -eq "0" ] ; then
2089 # Used by ia64
2090 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[2341]2091 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
[925]2092 duff_kernels="$fname $duff_kernels"
2093 else
[747]2094 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2095 possible_kernels="$fname $possible_kernels"
[925]2096 fi
[747]2097 else
[925]2098 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[2341]2099 LogAll "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
[925]2100 duff_kernels="$fname $duff_kernels"
2101 else
[747]2102 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2103 possible_kernels="$fname $possible_kernels"
[925]2104 fi
[747]2105 fi
2106 done
2107 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
[925]2108 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
[747]2109 fi
2110 if [ ! "$possible_kernels" ] ; then
[2341]2111 LogAll "No kernel matches exactly. Are there any duff kernels?"
[747]2112 possible_kernels="$duff_kernels"
2113 if [ ! "$possible_kernels" ] ; then
[2341]2114 LogAll "Sorry, no duff kernels either"
[747]2115 else
[2341]2116 LogAll "I bet you're running Debian or Gentoo, aren't you?"
2117 LogAll "Your kernel doesn't have a sane builddate. Oh well..."
[747]2118 fi
2119 fi
[2696]2120 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -vi "xen" | sort -u | tr '\n' ' '`
[747]2121 noof_kernels=`CountItemsIn "$possible_kernels"`
[2696]2122 if [ $KERNEL_IS_XEN = "yes" ]; then
2123 possible_xenkernels=`echo "$possible_kernels" | tr -s ' ' '\n' | grep -i "xen" | sort -u | tr '\n' ' '`
2124 noof_xenkernels=`CountItemsIn "$possible_xenkernels"`
2125 FindMboot32Binary
2126 fi
[747]2127 if [ "$noof_kernels" -eq "0" ] ; then
[2341]2128 LogAll "Could not find your kernel."
[925]2129 if [ -e "/boot/vmlinuz" ] ; then
[2341]2130 LogAll "Using /boot/vmlinuz as a last resort."
[925]2131 output=/boot/vmlinuz
[747]2132 else
[925]2133 output=""
2134 fi
[747]2135 elif [ "$noof_kernels" -eq "1" ] ; then
2136 kernelpath=`echo "$possible_kernels" | sed s/' '//`
[2341]2137 LogFile "Your kernel is $kernelpath (v$KERVERRUN)"
[747]2138 output="$kernelpath"
2139 else
2140 for i in $possible_kernels ; do
[2293]2141 if echo $i | grep "$KERVERRUN" ; then
[2341]2142 LogAll "OK, I used my initiative and found that "
2143 LogAll "$i is probably your kernel. "
[925]2144 output="$i"
2145 fi
[747]2146 done
[2696]2147 if [ -n "$output" ]; then
2148 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2149 output=/boot/vmlinuz
2150 echo "Schlomo, this one's for you." >> $LOGFILE
2151 else
2152 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2153 LogIt "boot disks will still work, probably. If one does not work, try another."
2154 LogIt "$possible_kernels"
2155 echo ""
2156 fi
2157 fi
2158 fi
2159 if [ $KERNEL_IS_XEN = "yes" ]; then
2160 if [ "$noof_xenkernels" -eq "0" ]; then
2161 xenkernelpath=""
2162 elif [ "$noof_xenkernels" -eq "1" ]; then
2163 xenkernelpath=`echo "$possible_xenkernels" | sed s/' '//`
2164 echo "Your Xen kernel is $xenkernelpath (v$KERVERRUN)" >> $LOGFILE
[925]2165 else
[2696]2166 for i in $possible_xenkernels ; do
2167 if echo $i | grep "$KERVERRUN" ; then
2168 LogIt "OK, I used my initiative and found that "
2169 LogIt "$i is probably your Xen kernel. "
2170 xenkernelpath="$i"
2171 fi
2172 done
2173 if [ -n "$xenkernelpath" ]; then
2174 new_possible_xenkernels=`echo "$possible_xenkernels" | tr -s ' ' '\n' | grep -E "^/boot" | sort -u | tr '\n' ' '`
2175 if [ ! -n "$new_possible_xenkernels" ]; then
2176 xenkernelpath=`echo $new_possible_xenkernels | tr -s ' ' '\n' | head -1`
2177 LogIt "Using $xenkernelpath"
2178 else
2179 LogIt "Two or more possible Xen kernels found. You may specify any one of them and the "
2180 LogIt "boot disks will still work, probably. If one does not work, try another."
2181 LogIt "$possible_xenkernels"
2182 echo ""
2183 xenkernelpath=`echo $possible_xenkernels | tr -s ' ' '\n' | head -1`
2184 LogIt "Using $xenkernelpath"
2185 fi
2186 fi
[925]2187 fi
[2696]2188 xenkernelname=`basename $xenkernelpath`
2189 if [[ -z "$xenkernelpath" || ! -f "$xenkernelpath" ]]; then
2190 Die "Cannot find Xen kernel $xenkernelpath, aborting"
2191 fi
[747]2192 fi
[2696]2193 echo "$output"
[747]2194}
2195
2196
2197TurnTgzIntoRdz() {
[2462]2198 local tgz_dir_fname rdz_fname tempfile mountpoint old_pwd nodes kernelsize res currsize not_copied j k s w needed_modules_path
[925]2199
[747]2200 tgz_dir_fname=$1
2201 rdz_fname=$2
[1983]2202 kernelsize=$3
[2462]2203 # Compute the list of all that should be copied/created on the final mountpoint under MINDI_TMP
2204 # mkdir.lis will contain the list of directries to create
2205 # cp.lis will contain the list of files/dirs to copy
2206 # ln.lis will contain the list of files to link to existing files
2207 # rm.lis will contain the list of files to remove after the copies
[2603]2208
2209 # Get kbd conf from data disk preparation
2210 echo $MINDI_CACHE/KEYMAP-LIVES-HERE >> $MINDI_TMP/cp.lis
[2034]2211 # AL04Oct08: Check whether /lib64 is a link and if so explicitly create one in rootfs
[2042]2212 if [ -h "/lib64" ]; then
[2462]2213 echo lib >> $MINDI_TMP/mkdir.lis
2214 echo ln -s lib lib64 >> $MINDI_TMP/ln.lis
[2042]2215 fi
[2034]2216
[2445]2217 # We need a minimal conf in the initial ramdisk
2218 mountlis=`grep -v "^#.*" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | cut -d: -f2 | sort -u`
[2462]2219 ReadAllLink $mountlis >> $MINDI_TMP/mnt.lis
[2446]2220 LocateDeps `cat $MINDI_TMP/mnt.lis` >> $MINDI_TMP/deps.lis
[2445]2221 # Special for libs
[2446]2222 ReadAllLink `grep -E "/lib" $DEPLIST_FILE_MIN $DEPLIST_DIR/minimal*.conf | grep -v "^#.*" | cut -d: -f2` >> $MINDI_TMP/deps.lis
2223
[2462]2224 echo `cat $MINDI_TMP/mnt.lis` `sort -u $MINDI_TMP/deps.lis` >> $MINDI_TMP/cp.lis
2225 rm -f $MINDI_TMP/deps.lis $MINDI_TMP/mnt.lis
[1786]2226
[2039]2227 # Copy of files mandatory for ld.so
[2462]2228 echo /etc/ld.so.c* >> $MINDI_TMP/cp.lis
[2039]2229
[2164]2230 # Avoid an issue on some distro (RHEL5)
[2462]2231 echo ./etc/ld.so.conf.d/kernelcap* >> $MINDI_TMP/rm.lis
[2164]2232
[2462]2233 # Need for a tmp dir
2234 echo tmp >> $MINDI_TMP/mkdir.lis
2235
[1724]2236 # Management of udev (which includes modprobe in rules)
[2596]2237 USE_UDEV=""
[1759]2238 ps auxww | grep -v grep | grep -qw udevd
[1716]2239 if [ $? -eq 0 ]; then
[2596]2240 USE_UDEV="yes"
[2446]2241 LogFile "udev device manager found"
[2462]2242 echo /etc/udev /lib*/udev >> $MINDI_TMP/cp.lis
[1790]2243 # This avoids NIC remapping if on another machine at restore time on Debian at least
[2462]2244 echo ./etc/udev/rules.d/z[0-9][0-9]_persistent-net.rules >> $MINDI_TMP/rm.lis
[2145]2245 # This avoids NIC remapping if on another machine at restore time on Ubuntu at least
[2462]2246 echo ./etc/udev/rules.d/[0-9][0-9]-persistent-net.rules >> $MINDI_TMP/rm.lis
[1720]2247 if [ -x /sbin/udevd ]; then
[2462]2248 # Get only the files which exist in the udev.files list
2249 # and potentially their symlink structure and their deps
2250 mountlis=`grep -Ev "^#" $MINDI_CONF/udev.files`
2251 ReadAllLink $mountlis | sort -u >> $MINDI_TMP/udev.lis
2252 LocateDeps `cat $MINDI_TMP/udev.lis` | sort -u >> $MINDI_TMP/cp.lis
2253 cat $MINDI_TMP/udev.lis >> $MINDI_TMP/cp.lis
[1721]2254 rm -f $MINDI_TMP/udev.lis
[1720]2255 else
[2341]2256 LogAll "udevd daemon not in standard place (/sbin)"
2257 LogAll "mindi will use static devices which may cause problems"
[1720]2258 fi
[1716]2259 fi
[1786]2260
[1761]2261 # Management of potential HW info (Proliant only at the moment)
[1880]2262 rm -rf $MINDI_CACHE/bkphw
2263 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2264 if [ -d $MINDI_CACHE/bkphw ]; then
[2341]2265 LogAll "Hardware Information found and saved ..."
[2462]2266 echo $MINDI_CACHE/bkphw >> $MIDNDI_TMP/cp.lis
[1880]2267 if [ -f $MINDI_CACHE/tools.files ]; then
2268 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
[1863]2269 LocateDeps $lis > $MINDI_TMP/tools.lis
[2462]2270 echo $lis `sort -u $MINDI_TMP/tools.lis` >> $MINDI_TMP/cp.lis
[1863]2271 fi
[1880]2272 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
[2462]2273 chmod 755 $MINDI_CACHE/mindi-rsthw
2274 echo $MINDI_CACHE/mindi-rsthw >> $MINDI_TMP/cp.lis
[1761]2275 fi
[1880]2276 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
[1761]2277 fi
2278
[2183]2279 # Management of perl scripts delivered needed at restore time
[2462]2280 mindi-get-perl-modules `cat $MINDI_CONF/perl-scripts` >> $MINDI_TMP/cp.lis
[2183]2281
[2488]2282 echo mnt/cdrom >> $MINDI_TMP/mkdir.lis
[747]2283
[2462]2284 ls /dev/fd0*[1,2][4,7,8]* >> $MINDI_TMP/cp.lis 2> /dev/null
[1721]2285
[2462]2286 if [ "${kernelname}" != "" ]
2287 then
2288 needed_modules_path=/lib/modules/${kernelname}
[747]2289 else
[2462]2290 needed_modules_path=/lib/modules/$KERVERRUN
[747]2291 fi
[1885]2292
2293 needed_modules=""
[1993]2294 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS"
[1885]2295
[2382]2296 if [ -e "$MINDI_TMP/NETFS-DEV" ] ; then
[747]2297 # For PXE boot
2298 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2299 fi
[1715]2300 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2301 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2302 fi
[1727]2303 for i in $DENY_MODS; do
[2341]2304 LogFile "Removing $i from the list of modules to load"
[1727]2305 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2306 done
2307
[2341]2308 [ -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]2309 for i in $list_of_groovy_mods ; do
[1885]2310 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
[747]2311 done
[1914]2312
[2599]2313 for i in `echo $needed_modules | tr ' ' '\n' | sort -u`; do
2314 grep -qE '^$i$' $MINDI_TMP/cp.lis
2315 if [ $? != 0 ]; then
2316 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
2317 LogFile "Adding $i ($s KB) to the rootfs"
2318 echo $i >> $MINDI_TMP/cp.lis
2319 fi
[747]2320 done
[1815]2321
2322 # Also copy modules.dep in case of udev so that normal modprobe works
[2462]2323 echo $needed_modules_path/modules.dep >> $MINDI_TMP/cp.lis
[1815]2324
[2462]2325 # Manages mountlit.txt
2326 MakeMountlist $MINDI_CACHE/mountlist.txt
2327 CheckMountlist $MINDI_CACHE/mountlist.txt
2328 echo $MINDI_CACHE/mountlist.txt >> $MINDI_TMP/cp.lis
2329 cat $MINDI_CACHE/mountlist.txt >> $LOGFILE
2330 LogFile "-----------------------------------"
2331
[2696]2332 # Copy FW in case some drivers needs it
2333 if [ -d "/lib/firmware" ]; then
[2704]2334 echo "lib/firmware" >> $MINDI_TMP/mkdir.lis
2335 echo "/lib/firmware" >> $MINDI_TMP/cp.lis
[2696]2336 fi
2337
[747]2338 cd $old_pwd
[1885]2339 if [ _"$MONDO_SHARE" != _"" ]; then
[2462]2340 MakeMondoConfigFile $MINDI_CACHE/mondorestore.cfg
2341 echo $MINDI_CACHE/mondorestore.cfg >> $MINDI_TMP/cp.lis
[2603]2342 LogFile "-----------------------------------"
2343 LogFile "Content of mondorestore.cfg: "
2344 LogFile "-----------------------------------"
2345 cat $MINDI_CACHE/mondorestore.cfg >> $LOGFILE
2346 LogFile "-----------------------------------"
[747]2347 fi
[2462]2348 echo proc >> $MINDI_TMP/mkdir.lis
[2444]2349
[2462]2350 # Copy of files mandatory for ssh to automate mount if sshfs is used
2351 echo .ssh >> $MINDI_TMP/mkdir.lis
2352
2353 # Now create the container and do the job
2354 tempfile=$MINDI_TMP/temp.rd
2355 mountpoint=$MINDI_TMP/mnt1
2356 res=0
2357 echo -en "..."
2358 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk ($tempfile)"
2359 echo -en "..."
2360 LogFile "Creating ext2 filesystem on $tempfile"
2361 mke2fs -b 1024 -m 0 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
2362 echo -en "..."
2363 mkdir -p $mountpoint
2364 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."
2365 echo -en "..."
2366 old_pwd=`pwd`
2367
2368 # First create dirs
2369 for d in `cat $MINDI_TMP/mkdir.lis`; do
2370 mkdir -p $mountpoint/$d 2>&1 >> $LOGFILE
2371 done
2372
2373 # Then copy files needed
[2488]2374 LANGUAGE=C tar cf - `cat $MINDI_TMP/cp.lis` 2> /dev/null | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
[2462]2375
2376 # Then handle links
2377 if [ -f $MINDI_TMP/ln.lis ]; then
2378 (cd $mountpoint ; bash $MINDI_TMP/ln.lis) 2>&1 >> $LOGFILE
2379 fi
2380
2381 # Finally remove useless stff
2382 (cd $mountpoint ; rm -f `cat $MINDI_TMP/rm.lis`) 2>&1 >> $LOGFILE
2383
2384 # Copy of files mandatory for ssh to automate mount if sshfs is used
2385 cp -rp ~root/.ssh/*.pub ~root/.ssh/config ~root/.ssh/known* $mountpoint/.ssh 2> /dev/null
2386 cat > $mountpoint/bin/myssh << EOF
2387ssh -o StrictHostKeyChecking=no $*
2388EOF
2389 chmod 755 $mountpoint/bin/myssh
2390
2391 # Finally integrate what we provide statically as part of mindi
[2488]2392 (cd $tgz_dir_fname ; LANGUAGE=C tar cf - . ) | (cd $mountpoint ; tar xf - ) 2>&1 | grep -Ev "tar: Removing.*/\'" >> $LOGFILE
[2462]2393
2394 # Extracting devices
2395 (cd $mountpoint/dev ; tar -zxf dev-entries.tgz) || Die "Cannot untar dev-entries.tgz"
2396 rm -f $mountpoint/dev/dev-entries.tgz
2397
[2444]2398 LogFile "---------------------------"
2399 LogFile "Content of initial ramdisk:"
2400 LogFile "---------------------------"
2401 (cd $mountpoint ; ls -Rla ) >> $LOGFILE
2402 LogFile "---------------------------"
2403
[1230]2404 # Determine what filesystem to use for initrd image
[2341]2405 LogFile "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd."
[1230]2406 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2407 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
[2391]2408 if [ "$gvFileSystem" = "ext2fs" ] || [ "$gvFileSystem" = "ext3fs" ]; then
[1230]2409 # say what will be used
[2391]2410 LogFile "Creating an $gvFileSystem initrd image..."
[1230]2411 # kernel expects linuxrc in ext2 filesystem
2412 ( cd $mountpoint && ln -sf sbin/init linuxrc )
2413 # unmount loop filesystem and create image file using the standard approach
2414 umount $mountpoint || Die "Cannot unmount $tempfile"
[1764]2415 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
[1794]2416 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
[2569]2417 MINDI_ADDITIONAL_BOOT_PARAMS="$MINDI_ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
[1799]2418 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
[1764]2419 rm -f ${rdz_fname}.tmp
[1230]2420 # log that we are done
[2341]2421 LogFile "...done."
[2391]2422 elif [ "$gvFileSystem" = "initramfs" ]; then
[1230]2423 # say what will be used
[2341]2424 LogFile "Creating a gzip'ed cpio (AKA initramfs) initrd image..."
[1230]2425 # make sure that cpio is there
2426 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2427 # go into filesystem
2428 cd $mountpoint
2429 # kernel expects init in cpio filesystem
2430 ln -sf sbin/init init
2431 # create cpio image file and unmount loop filesystem
[1929]2432 find . -print | cpio -o -H newc | gzip -9 > $rdz_fname 2> /dev/null
[1230]2433 cd $old_pwd
2434 umount $mountpoint || Die "Cannot unmount $tempfile"
2435 # log that we are done
[2341]2436 LogFile "...done."
[2391]2437 else
[1230]2438 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
[2391]2439 fi
[2488]2440 ls -al $MINDI_TMP/initrd.img > /tmp/initrd.log
[2391]2441
[747]2442 if [ "$res" -eq "0" ] ; then
2443 echo -en "..."
2444 else
2445 echo -en "\rMade an rdz WITH ERRORS. \n"
2446 fi
2447 return 0
2448}
2449
2450
2451##############################################################################
[1021]2452#----------------------------------- Main -----------------------------------#
[747]2453##############################################################################
2454
[1885]2455# Now we can create what we need
2456mkdir -p $MINDI_TMP
[747]2457
[1885]2458# Purge from potential old run
2459if [ _"$MINDI_CACHE" = _"" ]; then
2460 Die "MINDI_CACHE undefined"
2461fi
2462
2463if [ "$1" = "--printvar" ] ; then
2464 shift
2465 if [ _"$1" != _"" ] ; then
2466 set | grep -Ew "^$1" | cut -d= -f2
2467 fi
[2183]2468 exit 0
[1885]2469fi
2470
[747]2471> $LOGFILE
[2341]2472LogFile "mindi v$MINDI_VERSION"
2473LogFile "$ARCH architecture detected"
2474LogFile "mindi called with the following arguments:"
[2446]2475LogFile "$*"
[2341]2476LogFile "Start date : `date`"
2477LogFile "-----------------------------"
[747]2478
[1010]2479# Log some capital variables
2480[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
[2605]2481[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
[2341]2482LogFile "MONDO_SHARE = $MONDO_SHARE"
[2462]2483LogFile "MINDI_DATA = $MINDI_DATA"
[2341]2484LogFile "MINDI_SBIN = $MINDI_SBIN"
2485LogFile "MINDI_CONF = $MINDI_CONF"
[1885]2486if [ -f $MINDI_CONFIG ]; then
[2341]2487 LogFile "-----------------------------"
2488 LogFile " Mindi configuration file "
2489 LogFile "-----------------------------"
[1885]2490 grep -Ev '^#' $MINDI_CONFIG >> $LOGFILE
[2341]2491 LogFile "-----------------------------"
[1885]2492fi
[1010]2493
[1885]2494
[747]2495trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
[1010]2496
2497# Sanity checks
2498which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2499which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2500which 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."
2501which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2502if which awk &> /dev/null ; then
2503 if ! which gawk &> /dev/null ; then
[2341]2504 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]2505 fi
2506fi
2507which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
[2222]2508[ ! -e "$FDISK" ] && Die "Cannot find $FDISK"
[1010]2509
[2293]2510[ "`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]2511
2512# Update the PATH variable if incomplete
2513if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2514 PATH=$PATH:/sbin:/usr/sbin
2515 export PATH
[2341]2516 LogFile "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily."
2517 LogFile "However, you may wish to ask your vendor to provide a permanent fix..."
2518 LogFile " Or you might like to call 'su -' instead of 'su', for example."
[1010]2519fi
2520
[1737]2521if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
[1010]2522 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2523fi
2524
[2605]2525### TODO
[747]2526### Fix as it's not mandatory on ia64
2527if [ "$ARCH" = "ia64" ] ; then
[1010]2528 if which elilo &> /dev/null ; then
2529 LILO_EXE=elilo
2530 else
[2024]2531 LILO_EXE=`which false 2> /dev/null`
[1010]2532 fi
[747]2533else
2534 FindIsolinuxBinary
2535fi
2536trap "Aborted" SIGTERM
2537DONE="\r\t\t\t\t\t\t\t\tDone. "
2538kernelpath=""
2539
2540if [ -d "/proc/lvm" ]; then
2541 # LVM v1
2542 LVMCMD=""
2543 LVM="v1"
2544elif [ -d "/dev/mapper" ]; then
2545 # LVM v2
2546 LVMCMD="lvm"
2547 LVM="v2"
2548else
2549 LVM="false"
2550fi
[2329]2551
2552if [ -e "/proc/cmdline" ]; then
2553 CMDLINE="/proc/cmdline"
2554elif [ -e "/tmp/cmdline" ]; then
2555 CMDLINE="/tmp/cmdline"
2556else
2557 CMDLINE="/dev/null"
2558fi
2559
[2341]2560LogFile "LVM set to $LVM"
2561LogFile "----------"
2562LogFile "mount result:"
2563LogFile "-------------"
[1230]2564mount >> $LOGFILE
[2341]2565LogFile "-------------"
[1315]2566if [ -e /etc/raidtab ]; then
[2341]2567 LogFile "-------------"
2568 LogFile "/etc/raidtab content:"
2569 LogFile "-------------"
[1315]2570 cat /etc/raidtab >> $LOGFILE
2571fi
[2341]2572LogFile "-------------"
2573LogFile "cat $CMDLINE"
2574LogFile "-------------"
[2329]2575cat $CMDLINE >> $LOGFILE
[2341]2576LogFile "-------------"
2577LogFile "cat /proc/swaps:"
2578LogFile "-------------"
[2014]2579cat /proc/swaps >> $LOGFILE
[2341]2580LogFile "-------------"
2581LogFile "cat /proc/partitions:"
2582LogFile "-------------"
[2015]2583cat /proc/partitions >> $LOGFILE
[2341]2584LogFile "-------------"
2585LogFile "cat /proc/filesystems:"
2586LogFile "-------------"
[2015]2587cat /proc/filesystems >> $LOGFILE
[2341]2588LogFile "-------------"
2589LogFile "lsmod result:"
2590LogFile "-------------"
[1021]2591lsmod >> $LOGFILE
[2444]2592MODULES="`cat /proc/modules | $AWK '{print $1}'`"
[1531]2593if [ -x /usr/sbin/esxcfg-module ]; then
[2341]2594 LogFile "-------------"
2595 LogFile "VMWare ESX server detected - Enabling dedicated support"
2596 LogFile "-------------"
2597 LogFile "VMWare modules"
2598 LogFile "-------------"
[1531]2599 /usr/sbin/esxcfg-module -l >> $LOGFILE
[2444]2600 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | $AWK '{print $1}'`"
[1497]2601fi
[2341]2602LogFile "FORCE_MODS:"
2603LogFile "-------------"
2604LogFile $FORCE_MODS
2605LogFile "-------------"
2606LogFile "DENY_MODS:"
2607LogFile "-------------"
2608LogFile $DENY_MODS
2609LogFile "-------------"
2610LogFile "df result:"
2611LogFile "----------"
[1796]2612df -T >> $LOGFILE
[2341]2613LogFile "-------------"
2614LogFile "Liste of extra modules is:"
[2704]2615LogFile "-------------"
[2341]2616LogFile "$EXTRA_MODS"
2617LogFile "-------------"
[747]2618
[1723]2619# Compute libata version
[2651]2620laver=`modinfo libata 2> /dev/null | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
[1723]2621# If libata v2 is used then remove ide-generic as it will perturbate boot
[1726]2622if [ "`echo $MODULES | grep libata`" ]; then
[1727]2623 if [ "$laver" = "2" ]; then
[1726]2624 DENY_MODS="$DENY_MODS ide-generic"
[2341]2625 LogFile "ide-generic removed from module list as your system uses libata v2+"
2626 LogFile "-------------"
[1726]2627 fi
[1723]2628fi
2629
[2460]2630# Check for ISO_CMD command
2631if [ ! -x $ISO_CMD ]; then
2632 echo "NOTE: No CD image (ISO file) utility found" >> $LOGFILE
2633fi
2634
[747]2635FLOPPY_WAS_MOUNTED=""
2636for mtpt in /media/floppy /mnt/floppy /floppy ; do
2637 if mount | grep -w $mtpt &> /dev/null ; then
2638 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
2639 umount $mtpt
2640 fi
2641done
2642
[1684]2643#
2644# If we have a USB device we need to store info
2645# and remove it from the parameters line
2646#
[747]2647if [ "$#" -ne "0" ] ; then
[1684]2648 if [ "$1" = "--usb" ] ; then
2649 shift
2650 USBDEVICE=$1
2651 if [ _"$USBDEVICE" = _"" ]; then
2652 Die "No USB device specified"
2653 fi
2654 shift
2655 fi
2656fi
2657
2658if [ "$#" -ne "0" ] ; then
[747]2659 if [ "$1" = "--findkernel" ] ; then
2660 res=`TryToFindKernelPath`
[1336]2661 # Avoids logfile content for mondo
2662 export MONDO_SHARE=""
[747]2663 if [ "$res" = "" ] ; then
[925]2664 MindiExit -1
[747]2665 else
2666 echo "$res"
[925]2667 MindiExit 0
[747]2668 fi
[1720]2669 elif [ "$1" = "--locatedeps" ] ; then
2670 [ ! "$2" ] && Die "Please specify the binary to look at"
[2444]2671 LocateDeps $*
[1720]2672 # Avoids logfile content for mondo
2673 export MONDO_SHARE=""
2674 MindiExit $?
[1815]2675 elif [ "$1" = "--readalllink" ] ; then
2676 [ ! "$2" ] && Die "Please specify the binary to look at"
[2446]2677 shift
2678 ReadAllLink $*
[1815]2679 # Avoids logfile content for mondo
2680 export MONDO_SHARE=""
2681 MindiExit $?
[747]2682 elif [ "$1" = "--makemountlist" ] ; then
2683 [ ! "$2" ] && Die "Please specify the output file"
2684 MakeMountlist $2
[2444]2685 CheckMountlist $2
[1336]2686 # Avoids logfile content for mondo
2687 export MONDO_SHARE=""
[925]2688 MindiExit $?
2689 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
2690 echo "Mindi v$MINDI_VERSION"
[1336]2691 # Avoids logfile content for mondo
2692 export MONDO_SHARE=""
[925]2693 MindiExit 0
[747]2694 elif [ "$#" -ge "9" ] && [ "$1" = "--custom" ] ; then
[940]2695 MONDO_TMP=$2
2696 # Change MINDI_TMP for the one provided by mondo
2697 # So that it can get back the built files
[2153]2698 if [ _"$MONDO_TMP" = _"" ]; then
2699 Die "MONDO_TMP is empty, aborting"
2700 fi
2701 if [ _"$MONDO_TMP" = _"/" ]; then
2702 Die "MONDO_TMP is /, aborting"
2703 fi
[1010]2704 rmdir $MINDI_TMP
[1486]2705 export MINDI_TMP=$MONDO_TMP
[953]2706 mkdir -p $MINDI_TMP
[2238]2707
[2598]2708 # This is the scratch dir in mondo - subdir images
2709 # Now useless
2710 #MINDI_CACHE=$3
[2238]2711
[925]2712 kernelpath=$4; [ "$kernelpath" = "(null)" ] && kernelpath=""
[2696]2713 [ "$kernelpath" = "" ] && kernelpath=`TryToFindKernelPath`
2714
[747]2715###
2716### Sq-Modification...
2717### Attempt to locate kernel specific module path
2718### if module path is found then use it other wise use uname -r to set it...
2719###
[2635]2720 if [ $KERNEL_IS_XEN = "yes" ]; then
2721 LogAll "xenkernelpath = $xenkernelpath"
2722 LogAll "xenkernelname = $xenkernelname"
2723 fi
[2696]2724 kernelname=`echo $kernelpath | cut -d'-' -f2- | sed 's/.[bg]z[2]*$//'`
[2462]2725 if [ ! -d "/lib/modules/$kernelname" ]
[747]2726 then
[2341]2727 LogAll "Module path for ${kernelpath} not found..."
2728 LogAll "using running kernel\'s modules."
[2293]2729 kernelname=$KERVERRUN
[747]2730 else
[2341]2731 LogAll "Using modules for kernel: ${kernelname}"
[747]2732 fi
[2696]2733 LogAll "kernelname = $kernelname"
2734 LogAll "kernelpath = $kernelpath"
[747]2735###
2736### end of Sq-Modification
2737###
[925]2738 TAPEDEV=$5
2739 TAPESIZE=$6
2740 FILES_IN_FILELIST=$7
2741 USE_LZO=$8
2742 CDRECOVERY=$9
[747]2743 if [ "${10}" = "(null)" ] || [ "${10}" = "" ] ; then
2744 IMAGE_DEVS=""
2745 else
2746 IMAGE_DEVS="`echo "${10}" | tr '|' ' '`"
2747 fi
[925]2748 if [ "${11}" ] ; then
2749 LILO_OPTIONS=""
[2341]2750 # LogAll "LILO will use conservative settings, to be compatible with older BIOSes."
[925]2751 fi
[2462]2752 ESTIMATED_TOTAL_NOOF_SLICES=${12}
[2569]2753 export MINDI_EXCLUDE_DEVS="${13}"
[2462]2754 USE_COMP="${14}"
2755 USE_LILO="${15}"
2756 USE_STAR="${16}"
2757 INTERNAL_TAPE_BLOCK_SIZE="${17}"
2758 DIFFERENTIAL="${18}"
2759 USE_GZIP="${19}"
2760 USE_LZMA="${20}"
[2603]2761 BACKUP_MEDIA_TYPE="${21}"
[747]2762 [ "$USE_COMP" = "" ] && USE_COMP=yes
[998]2763 [ "$USE_GZIP" = "" ] && USE_GZIP=no
[2338]2764 [ "$USE_LZMA" = "" ] && USE_LZMA=no
[2341]2765 [ "$TAPEDEV" ] && LogAll "This is a tape-based backup. Fine."
[2598]2766
2767 MONDO_CACHE=/var/cache/mondo
2768 mkdir -p $MONDO_CACHE
[747]2769 else
[2341]2770 LogScreen "Syntax: mindi (--custom ....)"
[925]2771 MindiExit -1
[747]2772 fi
2773fi
[2238]2774
2775if [ _"$MINDI_CACHE" != _"" ]; then
2776 rm -rf $MINDI_CACHE/* 2> /dev/null
2777 mkdir -p $MINDI_CACHE
2778fi
2779
[747]2780[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
2781
[2462]2782LogAll "Mindi Linux mini-distro generator v$MINDI_VERSION"
2783LogAll "Latest Mindi is available from http://www.mondorescue.org"
2784LogAll "------------------------------------------------------------------------------"
[2341]2785LogFile "DIFFERENTIAL = $DIFFERENTIAL"
2786LogFile "INTERNAL TAPE BLOCK SIZE = $INTERNAL_TAPE_BLOCK_SIZE"
[747]2787
[1690]2788if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[2341]2789 LogAll "Including the generation of a Bootable USB device on $USBDEVICE"
[1684]2790fi
2791
[747]2792if [ "$kernelpath" = "" ] ; then
[1335]2793 [ _"$MONDO_SHARE" != _"" ] && Die "Please use -k <path> to specify kernel."
[966]2794 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
2795 read ch
2796 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
2797 USE_OWN_KERNEL="yes"
[1809]2798 else
2799 USE_OWN_KERNEL="no"
[747]2800 fi
2801 if [ "$USE_OWN_KERNEL" = "yes" ]; then
[925]2802 kernelpath=`TryToFindKernelPath`
2803 if [ "$kernelpath" = "" ] ; then
2804 echo -n "Please enter kernel path : "
2805 read kernelpath
2806 fi
[747]2807 fi
2808fi
[2341]2809LogFile "Mindi's temp dir=$MINDI_TMP"
2810LogFile "Mindi's output dir=$MINDI_CACHE"
2811[ "$(($RANDOM%64))" -eq "0" ] && LogAll "Dude, I've looked inside your computer and it's really dusty..."
[747]2812
[1983]2813PrepareDataDiskImages
2814
[2462]2815export ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
[747]2816
[2341]2817LogFile "Ramdisk will be $ramdisk_size KB"
[2488]2818PrepareBootDiskImage $kernelpath || Die "Failed to create $ramdisk_size MB disk image."
[747]2819
[2462]2820[ -e "$MINDI_DATA/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
[747]2821...Or type 'memtest' to test your PC's RAM thoroughly.\n"
2822
[1684]2823if [ _"$MONDO_SHARE" = _"" ]; then
[1983]2824 ListImagesForUser
2825 OfferToMakeBootableISO
[1684]2826 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
[1983]2827 OfferToMakeBootableUSB
[1684]2828 fi
[2341]2829 LogAll "Finished."
[747]2830elif [ "$TAPEDEV" ] ; then
[2078]2831 if [ "$ARCH" != "ia64" ] ; then
2832 # We need to keep the img file as boot file for ia64 platform
2833 rm -f $MINDI_CACHE/{*img,*iso}
2834 else
2835 rm -f $MINDI_CACHE/*iso
2836 fi
[1898]2837 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1983]2838 OfferToMakeBootableUSB
[1898]2839 fi
[1983]2840 OfferToMakeBootableISO
[1880]2841 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
2842 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
[747]2843 else
[925]2844 Die "Cannot find all.tar.gz, to be written to tape"
[747]2845 fi
[1695]2846elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1983]2847 OfferToMakeBootableUSB
[747]2848else
[1983]2849 OfferToMakeBootableISO
[747]2850fi
2851# cleanup
[2341]2852LogAll "$FRIENDLY_OUTSTRING"
[747]2853for mtpt in $FLOPPY_WAS_MOUNTED ; do
2854 mount $mtpt
2855done
[925]2856MindiExit 0
Note: See TracBrowser for help on using the repository browser.