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