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

Last change on this file since 2444 was 2444, checked in by Bruno Cornec, 15 years ago
  • priority given to env var for tmpdir
  • fuse FS excluded from tmpdir computation
  • Improves udev timeout handling
  • fuse device is needed at restore time for sshfs
  • Avoids comment analysis in the new code handling deplist.d
  • Avoids error message if some ssh conf files do not exist
  • Improvements on sshfs/ssh management in restore mode
  • Include now all minimal requirements for sshfs
  • Fix udev support in init for Mandriva 2009.1 (udevadm settle is blocking)
  • Improve deplist.d/* files
  • adds libnss for ssh support in boot disk
  • Solve a memory management issue in DSF module (strtok => mr_strtok)
  • DSF now also supports partitions in addition to full disks
  • Adds debug in open_and_list_dir
  • Improve user management for NetFS cases
  • ssh in the restore env needs some dlopened libs (libnss_compat|files)
  • Warning emited in case of duplicate mountpoints or devices in fstab found
  • Use only the AWK veriable everywhere and not the awk command
  • Simplify GetInitrdFilesystemToUse which doesn't need to detect everything, but just know if it's initramfs (new mode) or a compressed FS ext2/3 (older mode) as initrd is anyway re-made by mindi. Should fix #353

(Backport from 2.2.9)

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