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

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