Ticket #481: mindi

File mindi, 113.2 KB (added by victor gattegno, 13 years ago)

mindi modified, to detect Ubuntu cached.kmap.gz file

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