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

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