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

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

r4152@vgiles: bruno | 2011-06-11 20:42:21 +0200

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