source: MondoRescue/branches/3.1/mindi/mindi@ 3147

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