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

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