source: MondoRescue/branches/2.2.7/mindi/mindi@ 2010

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