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

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

r4323@mzielinski: bruno | 2011-09-29 20:26:04 +0200

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