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