source: MondoRescue/branches/2.2.8/mindi/mindi@ 2797

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

r2168@localhost (orig r2167): bruno | 2009-03-17 16:41:59 +0100
Adds sata_via support to IDE modules list


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