source: MondoRescue/branches/stable/mindi/mindi@ 1842

Last change on this file since 1842 was 1842, checked in by Bruno Cornec, 16 years ago
  • Fix lack of /etc/raidtab at restore rime in the right place
  • Adds support for nls_utf8 and pata_serverworks Patches from Dirk Husung (husung_at_tu-harburg.de)
  • Add efibootmgr to deplist.txt in order to be able to modify EFI menu at restore time on ia64
  • Usage of the new testver param of pb 0.8.12 to deliver 2.2.5 packages in a test dir.
  • Update pbcl files for upcoming delivery of 2.2.5
  • Fix an issue on parted output (K instead of KB) in parted2fdisk at restore time
  • Adds support for alb/aft types of bonding on Intel cards (Mark Pinkerton <Mark.Pinkerton_at_emageon.com>)
  • Escape variables in a perl script like mindi-bkphw
  • Better Proliant support at restore time now.
  • Fix a label bug where the variable label should also be re-initialized at each loop
  • start-nfs should NOT do exit => kernel panix as init exits
  • some other fixes for init on denymods
  • Adds boot options denymods (for udev) and forcemods (if not udev)
  • kqemu is denied. Probably should also be done for kvm stuff
  • Fix again the bug on modules link at root of the initrd. Hopefully for good.
  • Wait more around the USB CD emulated by iLO as it takes up to 5 seconds to come up
  • Attempt to fix udev support for RHEL 5.1
  • Better support for automatic iLO Virtual Media with udev
  • Some VMWare support improvements (however, it seems that VMWare support won't be possible anytime soon)
  • during init at restore time, copy all static evices availble for udev, as some distro implementation are no

t yet supported correctly for udev. Not very elegant, but should solve our current issues

  • Fedora 8 now supported as a build target for pb
  • svn.log removed.
  • dependencies reviewd for rhel_3
  • Attempt to fix the lack of modules loaded at restore time - especially fs device drivers
  • removes bkphw dir before potential creation
  • render mount command more vebose at restore time
  • Should fix #217
  • Increase BOOT_SIZE and EXTRA_SIZE to support features such as HW recovery
  • Handles udev.files files which could be symlinks
  • Improve udev support for distro with compressed modules (mdv e.g.)
  • Fix modules.dep copy
  • /sbin/pam_console_apply is needed by mdv udev conf
  • Adds support for nohw boot option to avoid re-setuping the HW conf
  • Improved support for Proliant on cpqacuxe
  • RstHW should be called after driver initialization
  • For debian/ubuntu mindi dpends on mindi-busybox
  • Update mindi-busybox pbcl for correct debian changelog generation, and up2date infos
  • Should fix #215
  • Fix #214 (Thanks to xdelaruelle)
  • Fix again svn.log not used anymore with new pb version
  • Adaptation of build process to upcoming 0.8.12 version of pb
  • Remove MONOTONIC clock to continue to support 2.4 kernels (RHEL 3 e.g. or ESX)
  • Attempt to solve ia64 BMC access through the serial port
  • parted2fdisk binary no more generated
  • do not require perl modules (strict.pm) at restore time
  • try to avoid modprobe messages at restore time
  • on ia64 now use the perl script parted2fdisk at retore time also
  • Also modprobe modules for udev after decompressing the additional ones
  • replace gzip -v9 by gzip -c9. Fix a bug at least on ia64
  • For all modules supported, create symlinks under the mountpoint and extract dev files as some are not automat ically created at the moment
  • Support /vmfs/volumes for ESX
  • Finally do not use vdf for ESX. Only creates issues.
  • Avoids continuing hw support if no product name found
  • Improves ia64 support for bootable image build
  • Fix a potential problem with ramdisk_blocksize param
  • MAKEDEV should also be included in deplist.txt
  • More fixes for udev support for Debian
  • Do not mount /boot if it's already mounted - avoids ESX hang
  • Fix NICs renumbering on Debian at least
  • Udev startup improvement to support iLO + NFS so modprobing all modules seems required as of now
  • Update to version 1.7.3 of busybox for pb
  • Load USB earlier in order to support KBD such as with iLO
  • Do busybox ldd first in order to create a potential /lib64 link correctly and then use it later in the image
  • Use variable DF in mindi to be able to support the ESX vdf
  • Fix mindi for Debian x86_64 where /lib64 is a link
  • Fix issue at restore time for ext2fs params not reused (Fix from Klaus Ade Johnstad <klaus_at_skolelinux.no>)
  • Do not copy udev files if they do not exist In udev case do not insert modules at all (udev should do it alone) May avoid the issue with rhel4.5 kernel ? To be tested
  • Update dependencies for rpm base build as well
  • And also perl is a debian/ubuntu dep
  • Better debian/ubuntu dependecies requirements (mtools)
  • Fix modes on mindi-bkphw (Thanks Phil Walker phil.walker_at_hp.com)
  • Complete rev [1771] for upper case RESTORE cli with syslinux as well
  • Update mindi-busybox to 1.7.3
  • Use RESTORE consistently across mondo to restore without interaction (report from Takeshi Shoji t.shoji_at_tripodw.jp)

(merge -r1769:1841 $SVN_M/branches/2.2.5)

  • Property svn:keywords set to Rev Id
File size: 115.1 KB
RevLine 
[747]1#!/bin/bash
2
3# $Id: mindi 1842 2007-12-15 01:24:34Z bruno $
4#
5#-----------------------------------------------------------------------------
6# mindi - mini-Linux distro based on the user's filesystem & distribution
7#
[1573]8# Mindi can create a multi-image boot/root kit. The first image is the boot
[747]9# disk: it contains a kernel, a ramdisk etc. The second disk is data disk #1;
10# the third disk is data disk #2; and so it goes.
11#
12# See http://www.mondorescue.org for details.
13#-----------------------------------------------------------------------------
14
15### Which arch are we on (useful for ia64 port)
[1570]16ARCH=`/bin/uname -m`
[747]17
[925]18#RUN_AFTER_INITIAL_BOOT_PHASE="echo \"Who lives in a pineapple under the sea?\" > /tmp/spongebob.squarepants.txt"
[1573]19 # after booting from image/CD image but before
[747]20 # accessing auxiliary data disks (or the rest of
21 # the CD), the initscript will run the above command.
22
23RUN_AFTER_BOOT_PHASE_COMPLETE="ide-opt"
24 # after the emergency boot process is complete but
25 # before the init script runs mondorestore, it will
26 # run this command.
27
[1693]28MINDI_REV=PBREV
29MINDI_VER=PBVER
[747]30
31MINDI_VERSION=${MINDI_VER}-r$MINDI_REV
32MINDI_PREFIX=XXX
33MINDI_CONF=YYY
34MINDI_SBIN=${MINDI_PREFIX}/sbin
[934]35MINDI_LIB=LLL
[747]36
[1047]37MINDI_CONFIG_DIST="$MINDI_CONF/mindi.conf.dist"
[1060]38if [ ! -f $MINDI_CONFIG_DIST ]; then
39 echo "Unable to find $MINDI_CONFIG_DIST. Please reinstall mindi"
[1063]40 exit -1
[1047]41fi
[1060]42md5sum --status -c "$MINDI_CONF/mindi.conf.dist.md5"
43if [ $? -ne 0 ]; then
44 echo "$MINDI_CONF/mindi.conf.dist md5 checksum incorrect. Please reinstall mindi"
[1063]45 exit -1
[1060]46fi
[1047]47. $MINDI_CONFIG_DIST
[925]48
[1047]49MINDI_CONFIG="$MINDI_CONF/mindi.conf"
[1097]50if [ ! -f $MINDI_CONFIG ] && [ "_$1" = "_" ]; then
[1060]51 echo "No $MINDI_CONFIG file found using sensible values from $MINDI_CONFIG_DIST"
[1047]52else
[1097]53 if [ "_$1" = "_" ]; then
[1087]54 echo "Using $MINDI_CONFIG as additional config file to $MINDI_CONFIG_DIST"
55 fi
[1047]56 . $MINDI_CONFIG
57fi
58
59#
60# Manages defaults coming from conf files
61#
62INTERACTIVE="$mindi_interactive"
63
[1347]64if [ "$INTERACTIVE" = "yes" ]; then
[747]65 # Ask if you want to make a CD Image to be written?
66 # if this is set to 'no', then the image will be created automatically
[1047]67 PROMPT_MAKE_CD_IMAGE="yes"
[747]68
[1063]69 # Ask if you want to make a USB Image to be written?
70 # if this is set to 'no', then the image will be created automatically
71 PROMPT_MAKE_USB_IMAGE="yes"
72
[747]73 # If set to "no", you will be prompted for whether or not
74 # you want to use your own kernel, or the supplied default.
75 # If "yes" mindi will automatically use your own kernel.
[1047]76 USE_OWN_KERNEL="no"
77fi
[925]78
[1063]79EXTRA_SPACE=$mindi_extra_space
[1600]80MAX_DISKS=$mindi_max_disks
[1281]81BOOT_SIZE=$mindi_boot_size
[1063]82DEPLIST_DIR="$MINDI_CONF/deplist.d"
83DEPLIST_FILE="$MINDI_CONF/$mindi_deplist_file"
84PROMPT_MAKE_CD_IMAGE="$mindi_write_cd"
85PROMPT_MAKE_USB_IMAGE="$mindi_write_usb"
[1087]86PROMPT_MAKE_TAPE_IMAGE="$mindi_write_tape"
[1063]87USE_OWN_KERNEL="$mindi_use_own_kernel"
[1087]88MINDI_CACHE="$mindi_cache_dir"
[1063]89TMPDIR="$mindi_tmp_dir"
[1087]90USBDEVICE="$mindi_usb_device"
91TAPEDEV="$mindi_tape_device"
[1063]92ADDITIONAL_BOOT_PARAMS="$mindi_boot_params"
93MY_FSTAB="$mindi_etc_fstab"
94LOGFILE="$mindi_log_file"
[1060]95TAPE_MODS="$mindi_tape_mods"
96SCSI_MODS="$mindi_scsi_mods"
97IDE_MODS="$mindi_ide_mods"
98PCMCIA_MODS="$mindi_pcmcia_mods"
99USB_MODS="$mindi_usb_mods"
[1573]100CDROM_MODS="$TAPE_MODS $IDE_MODS $mindi_cdrom_mods $USB_MODS $PCMCIA_MODS"
[1060]101NET_MODS="$mindi_net_mods"
[1671]102# BERLIOS: Handle the case where all is passed (cloning mode)
[1060]103EXTRA_MODS="$CDROM_MODS $mindi_extra_mods $mindi_additional_mods"
[1535]104DENY_MODS="$mindi_deny_mods"
105FORCE_MODS="$mindi_force_mods"
106ISO_CMD="$mr_iso_creation_cmd"
107ISO_OPT="$mr_iso_creation_opt"
[925]108
[1047]109BOOT_MEDIA_MESSAGE="$mindi_boot_msg"
[925]110FDISK=$MINDI_SBIN/parted2fdisk
[940]111
[1489]112# Now we can create what we need
113export MINDI_TMP=`mktemp -d $TMPDIR/mindi.XXXXXXXXXX`
114
[747]115# ----------------------------------------------------------------------------
116
117
118AbortHere() {
119 [ "$mountpoint" ] && umount $mountpoint 2>> $LOGFILE
120 Die "Program is terminating in response to signal received from OS/user"
121}
122
123
124HackSyslinuxFile() {
125 local incoming
126 incoming=`ReadLine`
127 while [ "$incoming" ] ; do
128 echo -en "$incoming" | sed s/24000/$1/
129 if [ "`echo "$incoming" | grep append`" ] ; then
130 echo -en " $ADDITIONAL_BOOT_PARAMS"
131 fi
132 echo -en "\n"
133 incoming=`ReadLine`
134 done
135 if [ -e "$MINDI_LIB/memtest.img" ] ; then
136 echo -en "label memtest\n kernel memdisk\n append initrd=memtest.img\n\n"
137 fi
138}
139
140
141Aborted() {
142 trap SIGHUP SIGTERM SIGTRAP SIGINT
[1087]143 [ "$MINDI_CACHE" != "" ] && rm -f $MINDI_CACHE/mindi*img $MINDI_CACHE/*gz $MINDI_CACHE/mindi.iso
[747]144 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
145 Die "User abort."
146}
147
148
149AddFileToDir() {
[1573]150 local filename minidir_root noof_disks diskno res filesize would_occupy zipsize complevel cutoff compressed_fname siz
[747]151 filename=$1
152 minidir_root=$2
153 noof_disks=$3
154
155 diskno=$noof_disks
156 mkdir -p $minidir_root/$diskno
157 [ "$LAST_COMPRESSED_SIZE" = "" ] && LAST_COMPRESSED_SIZE=0
158 if [ ! -e "$filename" ] ; then
[925]159 if [ -h "$filename" ] ; then
[963]160 cp --parents -pRdf $filename $minidir_root/$diskno 2>> $LOGFILE
[925]161 return $noof_disks
162 else
163 Die "AddFileToDir asked me to add $filename, which does not exist. Oops! Did you run out of disk space or is your Linux distro severely broken?"
164 fi
[747]165 fi
[925]166
167 # move to the disk that has room on it (or end up using the last, if all full)
[1600]168 while [ "$diskno" -lt $MAX_DISKS ] ; do
[925]169 mkdir -p $minidir_root/$diskno
[747]170 filesize=`du -sk $filename | cut -f1`
[963]171 cp --parents -Rdf $filename $minidir_root/$diskno 2>> $LOGFILE
[747]172 if [ "$filesize" -le "4" ] ; then
173 siz=$filesize
174 elif [ ! -f "$filename" ] ; then
175 siz=0
176 else
177 siz=`grep -m 1 "$filename.gz$" $minidir_root/compressed/compressed.txt | cut -f1`
178 [ "$siz" = "" ] && Die "FIXME - can't find $filename's size."
179 siz=$(($siz-2));# to allow for sectors & the fact that they round up
180 fi
[925]181 [ ! "$siz" ] && siz=4
182 [ "$siz" -lt "0" ] && siz=0
[747]183 LAST_COMPRESSED_SIZE=$(($LAST_COMPRESSED_SIZE+$siz))
[925]184 [ "$LAST_COMPRESSED_SIZE" -le "$MAX_COMPRESSED_SIZE" ] &&return $diskno
185 echo "disk=$diskno siz=$LAST_COMPRESSED_SIZE" >> $LOGFILE
186 LAST_COMPRESSED_SIZE=0
187 rm -f $minidir_root/$diskno/$filename
[747]188 diskno=$(($diskno+1))
189 done
190 return 0 ; # failed
191}
192
193
194AddKeyboardMappingFile() {
195 local mappath r included_list included_item i res ii sss
196 mappath=$1
197 KBDEPTH=$(($KBDEPTH+1))
198 [ "$KBDEPTH" -gt "128" ] && Die "Edit $MINDI_SBIN/mindi and disable FindAndAddUserKeyboardMappingFile (line 2160, approx.)"
199 if [ -e "$bigdir/$mappath" ] ; then
200 echo "$mappath already added" >> $LOGFILE
201 return
202 elif [ -d "$bigdir/$mappath" ] ; then
203 echo "Cannot add $mappath: it's a directory. Sorry."
204 return
205 fi
206 echo "Added kbd map $mappath" >> $LOGFILE
207 if [ ! -e "$mappath" ] ; then
[1075]208 mappath=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
[747]209 if [ ! -e "$mappath" ] ; then
[963]210 LogIt "Cannot add $mappath: kbd map file not found"
[747]211 return
212 fi
213 else
214 echo -en "`basename $mappath | tr '.' '#' | sed s/#kmap#gz// | sed s/#inc#gz//` " | tr '#' '.'
215 fi
216
217 mkdir -p $bigdir/etc
[963]218 cp --parents -pRdf $mappath $bigdir 2>> $LOGFILE || LogIt "AKMF -- Could not copy $mappath to $bigdir"
[747]219 if [ "`echo $mappath | grep -F ".gz"`" ] ; then
220 included_list=`gzip -dc $mappath | grep -Fi include | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
221 else
222 included_list=`grep -Fi include $mappath | sed s/'"'// | sed s/'"'// | cut -d' ' -f2`
223 fi
224 for included_item in $included_list ; do
[925]225 if [ ! -e "$included_item" ] ; then
[1075]226 sss=`grep -F "${included_item}.inc" $MINDI_TMP/keymaps.find`
227 [ "$sss" = "" ] && sss=`grep -F "$included_item" $MINDI_TMP/keymaps.find`
[925]228 for ii in $sss ; do
[747]229 [ -e "$ii" ] && AddKeyboardMappingFile $ii
[925]230 done
231 else
232 AddKeyboardMappingFile $included_item
233 fi
[747]234 done
235}
236
237
238ChopUpAndCopyFile() {
239 local filename slicesize outdir res biggienumber filesize sliceno noof_slices testfile scratchfile
240 filename=$1
241 outdir=$2
242 slicesize=$3
243 biggienumber=$4
244
[1060]245 [ -d "$filename" ] && Die "Cannot chop up $filename: it's a directory. Please amend $DEPLIST_FILE accordingly."
[747]246 mkdir -p $outdir
247
248 sliceno=0
[940]249 scratchfile=$MINDI_TMP/blah.$$.dat
[963]250 cp -f $filename $scratchfile 2>> $LOGFILE || Die "CUACF -- cannot copy $filename to $scratchfile - did you run out of disk space?"
[747]251 [ "`head $scratchfile -n1 | grep -F "bin/sh"`" != "" ] && StripComments $scratchfile "-$filename-"
252 [ "`echo "$filename" | grep -F "etc/termcap"`" != "" ] && StripComments $scratchfile "-$filename-"
253 if [ "`echo "$filename" | grep -F "lib/modules/" | grep "\.*o\.gz"`" != "" ] ; then
[925]254 mv $scratchfile $scratchfile.gz
[963]255 gunzip -f $scratchfile || LogIt "Cannot gunzip $scratchfile.gz"
[925]256 filename=`echo "$filename" | tr '.' '#' | sed s/#o#gz/#o/ | sed s/#ko#gz/#ko/ | tr '#' '.'`
[747]257 fi
258 filesize=`du -sk $scratchfile | cut -f1`
259 noof_slices=$(($filesize/$slicesize))
260 echo "$filename" > $outdir/slice-$biggienumber.name
261 echo "$filesize" > $outdir/slice-$biggienumber.size
262 [ -x "$scratchfile" ] && StripExecutable $scratchfile "-$filename-"
263 while [ "$sliceno" -le "$noof_slices" ] ; do
[963]264 dd if=$scratchfile skip=$(($sliceno*$slicesize)) of=$outdir/slice-$biggienumber.`printf "%03d" $sliceno` bs=1k count=$slicesize &> /dev/null
[747]265 sliceno=$(($sliceno+1))
266 done
267 rm -f $scratchfile
268}
269
270
271CopyBootBFile() {
272 local copy_to copy_from possible_locations liloc
273 copy_to=$1
274 copy_from=/boot/boot.b
275 liloc=`which lilo.real 2>/dev/null`
276 [ $liloc ] || liloc=`which lilo 2>/dev/null`
277 if [ $liloc ]; then
278 if ! [ `strings $liloc | grep "boot\.b"` ]; then
[963]279 LogIt "boot.b files built into lilo; I'll create a dummy."
[747]280 > $copy_to
281 return 0
282 fi
283 fi
284 if [ ! -f "$copy_from" ] ; then
285 LogIt "OK, you don't have a /boot/boot.b file, which is odd because\n most _good_ Linux distributions come with one, even if it's only a softlink"
286 copy_from=`grep install= /etc/lilo.conf | grep "\.b" | cut -d'=' -f2`
287 if [ ! -f "$copy_from" ] ; then
[963]288 LogIt "Nor can I find it from your /etc/lilo.conf file. This is very odd."
[747]289 copy_from=`FindSensibleBootBFile`
[963]290 LogIt "I'm going to use '$copy_from'"
[747]291 fi
292 fi
[963]293 cp -f $copy_from $copy_to 2>> $LOGFILE || LogIt "CBBF -- warning -- cannot find your boot.b file. That's it, I quit... (j/k)"
[747]294}
295
296
297CopyDependenciesToDirectory() {
[1529]298 local outdir incoming fname filesize counter d found
[747]299 outdir=$1
300 mkdir -p $outdir
301 incoming=`ReadLine`
302 counter=0
303 while [ "$incoming" != "" ] ; do
[1529]304 # Non absolute file names should not arrive till here => skipped
305 if [ `echo "$incoming" | cut -c1` != '/' ]; then
306 LogIt "Unable to handle $incoming"
307 incoming=`ReadLine`
308 continue
309 fi
310 # no parent directory of incoming should be a link, copy is not possible in that case
311 d=`dirname "$incoming"`
312 found="false"
313 while [ $d != "/" -a $found = "false" ]; do
314 [ -h "$d" ] && found="true"
315 d=`dirname "$d"`
316 done
317 if [ -d "$incoming" ] && [ ! -h "$incoming" ]; then
[747]318 find $incoming/* -maxdepth 0 2> /dev/null | CopyDependenciesToDirectory $outdir
[1529]319 elif [ -e "$incoming" ] && [ $found = "false" ]; then
[747]320 filesize=`du -sk $incoming | cut -f1`
321 if [ "$filesize" -gt "$(($CHOPSIZE*2))" ] && [ ! -h "$incoming" ] ; then
322 ChopUpAndCopyFile $incoming $outdir $CHOPSIZE $BIGNO
323 BIGNO=$(($BIGNO+1))
324 else
[953]325 cp --parents -Rdf $incoming $outdir 2> /dev/null || Die "Cannot copy $incoming to $outdir - did you run out of disk space?"
[925]326 if [ "`echo "$incoming" | grep "lib/modules/.*\..*o\.gz"`" != "" ] ; then
[963]327 gunzip -f $outdir/$incoming || LogIt "Cannot gunzip $outdir/$incoming"
[925]328 fi
329 [ -x "$outdir" ] && StripExecutable $outdir "-$filename-"
330 fi
331 counter=$(($counter+1))
332 if [ "$counter" -ge "5" ] ; then
333 counter=0
334 echo -en "."
335 fi
[747]336 fi
337 incoming=`ReadLine`
338 done
339}
340
341
342CopyImageToDisk() {
343 local image dev procno res comment
344 image=$1
345 dev=$2
346 comment=$3
347 [ ! -f "$image" ] && [ ! -b "$image" ] && Die "Image $image does not exist. Did you run out of disk space?"
348 Prompt "About to write $comment. Please press ENTER."
349 echo -en "Formatting disk..."
350 if which fdformat > /dev/null ; then
[925]351 fdformat -n $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"
[747]352 elif which superformat > /dev/null ; then
[925]353 superformat $dev > /dev/null 2> /dev/null || Die "Cannot format $dev - is your Linux distro broken?"
[747]354 else
[925]355 Die "Please install either fdformat or superformat."
[747]356 fi
[1193]357 echo -en "\nWriting $comment"
[747]358 if echo $image | grep "mindi-[r|b]oot\.1440" &> /dev/null ; then
[925]359 cat $image > $dev &
[747]360 else
[925]361 dd if=$image of=$dev &> /dev/null &
[747]362 fi
363 procno=$!
364 ps $procno > /dev/null 2> /dev/null
365 while [ "$?" -eq "0" ] ; do
366 sleep 3
367 echo -en "."
368 ps $procno > /dev/null 2> /dev/null
369 done
370 echo -e "$DONE"
[963]371 LogIt "$comment has been written."
[747]372}
373
374
375CountItemsIn() {
376 local r
377 r=0
378 for q in $1 ; do
379 r=$(($r+1))
380 done
381 echo $r
382}
383
384
385CreateDataDiskImagesFromTarballs() {
386 local tardir outdir diskno noof_disks kp
387 tardir=$1
388 outdir=$2
389 noof_disks=$3
390
391 mkdir -p $outdir
392 diskno=1
393 echo -en "Creating data disk "
394 while [ "$diskno" -le "$noof_disks" ] ; do
[925]395 echo -en "#$diskno..."
[963]396 cp -f $tardir/$diskno.tar.gz $outdir 2>> $LOGFILE || LogIt "[line 424] Cannot copy $tardir/$diskno.tar.gz to $outdir"
[747]397 CreateOneDataDiskImage $tardir/$diskno.tar.gz $outdir/mindi-data-$diskno.img $diskno $noof_disks
398 diskno=$(($diskno+1))
399 done
400 mv -f $tardir/all.tar.gz $outdir
401 du -sk $outdir/*gz >> $LOGFILE
402 echo -e "$DONE"
403}
404
405
406
407CreateOneDataDiskImage() {
408 local tarball imagefile dev diskno noof_disks mountpoint
409 tarball=$1
410 imagefile=$2
411 diskno=$3
412 noof_disks=$4
413
[940]414 mountpoint=$MINDI_TMP/mountpoint.$$
[747]415 mkdir -p $mountpoint
[963]416 dd if=/dev/zero of=$imagefile bs=1k count=1440 &> /dev/null || LogIt "Cannot dd (CODI)"
[1075]417 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
[1770]418 mke2fs -N 12 -F $imagefile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $imagefile"
[747]419 mount -t ext2 -o loop $imagefile $mountpoint || Die "Can't loopmount $imagefile to $mountpoint! The reason may be missing support for loopfs or ext2 (or both) in the running kernel."
420 mv $tarball $mountpoint/
421 if [ "$?" -ne "0" ] ; then
[925]422 umount $mountpoint
[1087]423 rmdir $mountpoint
[1060]424 Die "Tarball $tarball is too big for disk! (CODI)\nAdjust mindi_max_compressed_size in your $MINDI_CONFIG"
[747]425 fi
426 [ "$diskno" -eq "$noof_disks" ] && echo "This is the last disk ($diskno=$noof_disks)" >> $mountpoint/LAST-DISK
[963]427 umount $mountpoint || LogIt "Cannot umount (CODI)"
428 rmdir $mountpoint || LogIt "Cannot rmdir (CODI)"
[747]429}
430
[1842]431
[925]432# Last function called before exiting
433# Parameter is exit code value
[931]434MindiExit() {
[925]435 local my_partitions
[747]436
[925]437 echo "Mindi $MINDI_VERSION is exiting" >> $LOGFILE
438 echo "End date : `date`" >> $LOGFILE
[1337]439 if [ _"$MONDO_SHARE" != _"" ] ; then
[1350]440 echo "------------- mindi logfile included -------------------------" >> /var/log/mondoarchive.log
[1326]441 cat $LOGFILE >> /var/log/mondoarchive.log
[1350]442 echo "--------------------------------------------------------------">> /var/log/mondoarchive.log
[1326]443 fi
[747]444
[925]445 cd /
[1663]446 sync&
[747]447
[1663]448 # Unmount what could remain mounted
[925]449 my_partitions=`mount | grep -F $$ | cut -f1 -d' '`
450 [ "$my_partitions" != "" ] && umount $my_partitions
[940]451 # Clean temporary files only when standalone mindi
[948]452 if [ _"$MINDI_TMP" != _"$MONDO_TMP" ]; then
[940]453 rm -Rf $MINDI_TMP
454 fi
[925]455 exit $1
456}
457
[747]458Die() {
[925]459 local i
[747]460 if [ "$1" = "" ] ; then
[963]461 LogIt "FATAL ERROR"
[747]462 else
[963]463 LogIt "FATAL ERROR. $1"
[747]464 fi
465
[1326]466 LogIt "Please e-mail a copy of $LOGFILE to the mailing list."
[963]467 LogIt "See http://www.mondorescue.org for more information."
[747]468 LogIt "WE CANNOT HELP unless you enclose that file.\n"
[925]469 MindiExit -1
[747]470}
471
472
473DropOptimizedLibraries() {
474 local outdir filelist list_of_optimized_libraries optimized_lib_name vanilla_lib_name reason msg resolved res
475 filelist=$1
476 outdir=$2
477
478 list_of_optimized_libraries=`grep "lib/i[5-7]86/" $filelist`
479 if [ "$list_of_optimized_libraries" = "" ] ; then
[859]480 return 0
[747]481 fi
482 echo -en "Dropping i686-optimized libraries if appropriate"
483 for optimized_lib_name in $list_of_optimized_libraries ; do
[859]484 echo -en "."
485 reason=""
[1489]486 vanilla_lib_name=`echo "$optimized_lib_name" | sed -e 's/i[5-7]86//' -e 's/cmov//' -e 's/nosegneg//' | tr -s '/' '/'`
[859]487 echo "$vanilla_lib_name" >> $filelist
488 resolved=$vanilla_lib_name
[747]489 echo "Adding $resolved to filelist" >> $LOGFILE
[861]490 resolved=`ReadAllLink $resolved`
491 echo "Adding $resolved to filelist" >> $LOGFILE
[859]492 mkdir -p $outdir$optimized_lib_name > /dev/null 2> /dev/null
493 rmdir $outdir$optimized_lib_name > /dev/null 2> /dev/null
494 ln -sf $vanilla_lib_name $outdir$optimized_lib_name
495 echo "Excluding $optimized_lib_name" >> $LOGFILE
[935]496 grep -Fvx "$optimized_lib_name" "$filelist" > $filelist.tmp
[859]497 echo "Replacing it with $vanilla_lib_name" >> $LOGFILE
498 echo "$vanilla_lib_name" >> $filelist.tmp
499 mv -f $filelist.tmp $filelist
[747]500 done
[925]501 $AWK '{ print $1; }' $filelist | sort -u > $filelist.tmp
[747]502 mv -f $filelist.tmp $filelist
503 echo -e "$DONE"
504}
505
506
507FindAndAddUserKeyboardMappingFile() {
508 local r res mapfile mappath included_item included_list keyfile mp locale
[963]509 LogIt "Analyzing your keyboard's configuration."
[747]510 KEYDIR=/lib/kbd
511 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware
512 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
513 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
[1770]514 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
515 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole-setup
[747]516 if [ ! -e "$KEYDIR" ] ; then
[963]517 LogIt "Keyboard mapping directory not found. I shall use default map at boot-time."
[747]518 return 0
519 fi
520 if [ -e "/etc/sysconfig/keyboard" ] ; then
521 echo "Red Hat-style config detected." >> $LOGFILE
522 keyfile=/etc/sysconfig/keyboard
523 elif [ -e "/etc/rc.d/rc.keymap" ] ; then
524 echo "Slackware-style config detected." >> $LOGFILE
525 keyfile=/etc/rc.d/rc.keymap
526 elif [ -e "/etc/rc.config" ] ; then
527 echo "Debian-style config detected." >> $LOGFILE
528 keyfile=/etc/rc.config
529 elif [ -e "/etc/console/boottime.kmap.gz" ] ; then
530 echo "Debian-style config detected." >> $LOGFILE
531 echo -en "Adding the following keyboard mapping tables: "
532 mkdir -p $bigdir/tmp
[1158]533 echo "keymap-lives-here=/etc/console/boottime.kmap.gz" >> $MINDI_TMP/mondo-restore.cfg
[747]534 KBDEPTH=0
535 mkdir -p $bigdir/etc/console
[963]536 cp /etc/console/boottime.kmap.gz $bigdir/etc/console 2>> $LOGFILE
[747]537 echo -e "$DONE"
538 return 0
[1770]539 elif [ -e "/etc/console-setup/boottime.kmap.gz" ] ; then
540 echo "Ubuntu-style config detected." >> $LOGFILE
541 echo -en "Adding the following keyboard mapping tables: "
542 mkdir -p $bigdir/tmp
543 echo "/etc/console-setup/boottime.kmap.gz" > $bigdir/tmp/KEYMAP-LIVES-HERE
544 KBDEPTH=0
545 mkdir -p $bigdir/etc/console-setup
546 cp /etc/console-setup/boottime.kmap.gz $bigdir/etc/console-setup 2>> $LOGFILE
547 echo -e "$DONE"
548 return 0
[1468]549 elif [ -e "/etc/conf.d/keymaps" ] ; then
550 echo "Gentoo-style config detected." >> $LOGFILE
551 keyfile=/etc/conf.d/keymaps
[747]552 else
553 echo -en "Searching for rc.config ..."
554 keyfile=`find /etc -name rc.config | head -n1`
555 if [ "$keyfile" = "" ] || [ ! -e "$keyfile" ] ; then
[963]556 LogIt "Unknown config detected. Default keyboard map will be used."
[747]557 return
558 else
559 echo "Found $keyfile" >> $LOGFILE
560 fi
561 fi
562 if [ ! -e "$KEYDIR/keymaps" ] ; then
[963]563 LogIt "Keyboard mapping directory not found. Default keyboard map will be used."
[747]564 return
565 fi
566 echo "keyfile=$keyfile" >> $LOGFILE
567 locale=`grep -F KEYTABLE "$keyfile" | tr -d '"' |cut -d'=' -f2`
568 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware
[1468]569 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | tr -d '"' |cut -d'=' -f2` # Gentoo
[747]570 echo "locale=$locale" >> $LOGFILE
[1075]571 #
572 # Process the keymaps dir once for all
573 # AddKeyboardMappingFile will use it recursively
574 #
575 find $KEYDIR/keymaps > $MINDI_TMP/keymaps.find
576 mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep -F "/${locale}." | grep -vx " *#.*"`
577 [ ! "$mp" ] && mp=`grep "i[3-8]86" $MINDI_TMP/keymaps.find | grep "$locale[^r][^/]" | grep -vx " *#.*"`
[747]578 # If we have multiple keymaps then log it !!
579 echo "$mp" | grep -q " "
580 if [ $? -eq 0 ]; then
581 echo "WARNING: Multiple keymaps found: $mp" | tee -a $LOGFILE
582 echo "The following one will be used" >> $LOGFILE
583 fi
584 for i in $mp ; do
585 mappath=$i
586 [ -e "$i" ] && [ ! -d "$i" ] && break
587 done
588 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
589 mappath=$(locate */kbd/keymaps/*/$locale)
590 fi
591 echo "mappath = $mappath" >> $LOGFILE
592 if [ ! -e "$mappath" ] || [ -d "$mappath" ] ; then
[963]593 LogIt "Keyboard mapping file not found. Default keyboard map will be used."
[747]594 return
595 fi
596 echo -en "Adding the following keyboard mapping tables: "
597 mkdir -p $bigdir/tmp
[1158]598 echo "keymap-lives-here=$mappath" >> $MINDI_TMP/mondo-restore.cfg
[747]599 KBDEPTH=0
600 AddKeyboardMappingFile $mappath
601 echo -e "$DONE"
[1082]602 rm -f $MINDI_TMP/keymaps.find
[747]603 return 0
604}
605
606
607FindIsolinuxBinary() {
608 ISOLINUX=/usr/lib/isolinux.bin
609 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib/syslinux/isolinux.bin
[1500]610 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/lib64/syslinux/isolinux.bin
[747]611 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/syslinux/isolinux.bin
612 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib/syslinux/isolinux.bin
[1500]613 [ ! -e "$ISOLINUX" ] && ISOLINUX=/usr/share/lib64/syslinux/isolinux.bin
[747]614 [ ! -e "$ISOLINUX" ] && ISOLINUX=`locate isolinux.bin | grep -x "/.*/isolinux.bin"`
615 [ ! -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'"
616 echo "Found isolinux.bin at $ISOLINUX" >> $LOGFILE
617}
618
619
620FindLiloBinary() {
621 if which lilo &> /dev/null ; then
[925]622 if which lilo.real > /dev/null 2> /dev/null ; then
623 LILO_EXE=lilo.real
[963]624 LogIt "lilo.real found; will be used instead of lilo (*grumble* *mutter*)"
[925]625 else
626 LILO_EXE=lilo
627 fi
628 $LILO_EXE -V | grep -F "21.6" > /dev/null && Die "Please upgrade LILO. Your version has a serious bug. If you're not _using_ LILO, fine, uninstall it. :)"
[747]629 else
[925]630 LILO_EXE=`which false`
[747]631 fi
632}
633
[925]634
[747]635FindSensibleBootBFile() {
636 local i out last
637 out=""
638 last=""
639 for i in `find /boot -type f | grep -v chain | grep -v os2 | sort -u` ; do
640 if [ "`strings $i 2> /dev/null | head -n1`" = "LILO" ] ; then
641 out="$out $i"
[925]642 last="$i"
[747]643 fi
644 done
645 echo "$last"
646}
647
648
649FindSpecificModuleInPath() {
650 local modpaths pwd line
651 pwd=`pwd`
652 if [ "$YOUR_KERNEL_SUCKS" ] ; then
[940]653 cd $MINDI_TMP
[747]654 else
655 cd /
656 fi
657 if [ ! -e "$1" ] ; then
[963]658 LogIt "WARNING - cannot search specific path '$1'"
[747]659 return 1
660 fi
661 modpaths=`find $1 -name $2.*o -type f`
[1842]662 #[ "$?" -ne "0" ] && Die "find $1 -name $2.o -type f --- failed"
[747]663 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.o.gz -type f`
664 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2.ko.gz -type f`
665 [ "$modpaths" = "" ] && modpaths=`find $1 -name $2 -type f`
666 echo "$modpaths"
667 cd $pwd
668}
669
670
671GenerateGiantDependencyList() {
672 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
673
674 echo -en "Analyzing dependency requirements"
675 outfile=$1
[940]676 tempfile=$MINDI_TMP/$$.txt
[747]677 incoming=`ReadLine`
678
679 > $tempfile
680 progress=0
681 res=0
682 noof_lines=$2
683 while [ "$incoming" != "" ] ; do
[861]684 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
685 incoming=`ReadLine`
686 continue
687 fi
688 if [ "$incoming" = "LVMFILES:" ] ; then
689 break
690 fi
[747]691 filelist=`GenerateListForFile "$incoming"`
692 r=$?
[963]693 [ "$r" -ne "0" ] && LogIt "$incoming not found"
[747]694 res=$(($res+$r))
[861]695# echo "'$incoming' generates filelist '$filelist'" >> $LOGFILE
[747]696 for fname in $filelist ; do
[861]697 [ "$fname" != "" ] && echo "$fname" >> $tempfile
[747]698 done
699 progress=$(($progress+1))
700 echo -en "\r\t\t\t\t\t\t\t\t"
701 i=$(($progress*100))
702 i=$(($i/$noof_lines))
703 echo -en "$i"
704 echo -en "%"
705 modres=$(($progress%4))
706 [ "$modres" -eq "0" ] && echo -en "\t/"
707 [ "$modres" -eq "1" ] && echo -en "\t-"
708 [ "$modres" -eq "2" ] && echo -en "\t\\"
709 [ "$modres" -eq "3" ] && echo -en "\t|"
710 incoming=`ReadLine`
711 done
[861]712 if [ "$incoming" = "LVMFILES:" ] ; then
713 incoming=`ReadLine`
714 lvmversion=""
715 while [ "$incoming" != "" ] ; do
716 if echo "$incoming" | grep -x " *#.*" &> /dev/null ; then
717 incoming=`ReadLine`
718 continue
719 fi
720 filelist=`GenerateListForFile "$incoming"`
721 for tool in $filelist ; do
722 lvmresolved=`readlink -f $tool`
[1347]723 if [ "$tool" = "$lvmresolved" ]; then
[861]724 echo "$tool" >> $tempfile
725 elif echo "$lvmresolved" | grep "lvmiopversion" &> /dev/null ; then
726 if [ "$lvmversion" = "" ] ; then
727 lvmversion=`$lvmresolved`
728 echo "$lvmresolved" >> $tempfile
729 fi
730 toolstripped=`echo $tool | $AWK -F / '{print $NF;}'`
[1347]731 if [ "$lvmversion" = "200" ]; then
[861]732 # pvdata and lvmcreate_initrd don't exist in LVM2
733 case "$toolstripped" in
734 "pvdata")
735 continue
736 ;;
737 "lvmcreate_initrd")
738 continue
739 ;;
740 esac
741 fi
742 toolpath="/sbin/lvm-"$lvmversion"/"$toolstripped
743 if [ -e "$toolpath" ] ; then
744 echo "$toolpath" >> $tempfile
745 echo "$tool" >> $tempfile
746 else
747 toolpath="/lib/lvm-"$lvmversion"/"$toolstripped
748 fi
749 if [ -e "$toolpath" ] ; then
750 echo "$toolpath" >> $tempfile
751 echo "$tool" >> $tempfile
752 else
753 echo "Where are your LVM-Tools? Couldn't find $tool"
754 fi
755 else
756 echo "$tool" >> $tempfile
757 fi
758 done
759 progress=$(($progress+1))
760 echo -en "\r\t\t\t\t\t\t\t\t"
761 i=$(($progress*100))
762 i=$(($i/$noof_lines))
763 echo -en "$i"
764 echo -en "%"
765 modres=$(($progress%4))
766 [ "$modres" -eq "0" ] && echo -en "\t/"
767 [ "$modres" -eq "1" ] && echo -en "\t-"
768 [ "$modres" -eq "2" ] && echo -en "\t\\"
769 [ "$modres" -eq "3" ] && echo -en "\t|"
770 incoming=`ReadLine`
771 done
[747]772 fi
773 echo -en "$DONE\nMaking complete dependency list"
774
775 tr -s '/' '/' < $tempfile | sort -u > $tempfile.new
776 mv -f $tempfile.new $tempfile
777 > $outfile.pre
778 progress=0
779 noof_lines=`cat $tempfile | wc -l`
780 for fname in `cat $tempfile` ; do
[925]781 echo "$fname" >> $outfile.pre
782 LocateDeps $fname >> $outfile.pre
783 progress=$(($progress+1))
[747]784 echo -en "\r\t\t\t\t\t\t\t\t"
785 i=$(($progress*100))
786 i=$(($i/$noof_lines))
787 echo -en "$i"
788 echo -en "%"
[925]789 modres=$(($progress%4))
[747]790 [ "$modres" -eq "0" ] && echo -en "\t/"
791 [ "$modres" -eq "1" ] && echo -en "\t-"
792 [ "$modres" -eq "2" ] && echo -en "\t\\"
793 [ "$modres" -eq "3" ] && echo -en "\t|"
794 done
[1063]795 if [ _"$MONDO_SHARE" != _"" ]; then
[925]796 mkdir -p $bigdir/tmp
797 mkdir -p $bigdir/sbin
798 mkdir -p $bigdir/bin
[940]799 if [ -e "$MINDI_TMP/post-nuke.tgz" ] ; then
[963]800 LogIt "\nIncorporating post-nuke tarball"
[925]801 old_pwd=`pwd`
802 cd $bigdir
[963]803 tar -zxf $MINDI_TMP/post-nuke.tgz || LogIt "Error occurred when untarring post-nuke tarball"
[925]804 cd $old_pwd
[747]805 fi
[963]806 if cp -f $MINDI_TMP/mondo*restore $bigdir/usr/bin 2>> $LOGFILE ; then
[925]807 LocateDeps $bigdir/usr/bin/mondo*restore >> $outfile.pre
808 else
[963]809 LogIt "Cannot find mondo*restore in mondo's tempdir, $MINDI_TMP"
810 LogIt "I bet you've got a spare copy of Mondo or Mindi floating around on your system."
[925]811 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."
812 Die "Odd."
813 fi
[747]814 fi
[925]815 tr ' ' '\n' < $outfile.pre | tr -s '/' '/' | grep -Fvx "" | sort -u | grep -Ev "/libX11|/libXext|/libXi|/libgtk|/libgdk" > $outfile
[747]816 rm -f $tempfile $outfile.pre
817 [ "$res" -eq "0" ] && echo -e "\r\t\t\t\t\t\t\t\t$DONE" || echo "\nFailed."
818 return $res
819}
820
821
822GenerateListForFile() {
823 local files_found loc fname incoming i res
824 incoming="$1"
825 files_found=""
826 res=0
827
828 for fname in $incoming ; do
829 files_found="$files_found `LocateFile $fname`"
830 done
831
832 echo "$files_found" | tr ' ' '\n' | sort -u | tr '\n' ' '
833}
834
835
836# Returns all disk devices which are part of a raid array
837GetAllRaidMembers() {
838 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*device/ if(\$2) {print \$2}" < /etc/raidtab
839}
840
841
842GetFileSizeList() {
843 local i
844 for i in `find $1 -type d -o -print` ; do
845 du -sk $i
846 done
847}
848
849
850GetHomeDir() {
851 local res loc
852 loc=`which $1 2>/dev/null`
853 res=`file $loc | $AWK '{print $NF;}'`
854 dirname $res
855}
856
857
[1099]858# Check kernel filesystem capabilites for accessing initrd image
859#
860# Interface definition:
861# param #1: absolute path to kernel image
862GetInitrdFilesystemToUse() {
863
864 # interface test: make sure we have one parameter
865 if [ $# -ne 1 ]; then
866 Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
867 fi
868
869 # interface parameters
870 local lvKernelImage=$1
871
872 # local constants (filesystem magic strings)
873 local lcMagicCramfs="<3>cramfs: wrong magic"
874 local lcMagicExt2fs="<3>EXT2-fs: blocksize too small for device."
[1770]875 local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs..."
[1099]876
877 # local variables
878 local lvOffset
879 local lvScanRes
880 local lvUseFilesystem
881
882 # say where we are.
[1167]883 echo " GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n" >> $LOGFILE
[1099]884
885 # verify that file exists
886 [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
887
[1570]888 # Kernel may be gzip compressed
[1770]889 file $lvKernelImage 2>&1 | grep -q gzip
[1570]890 if [ $? -eq 0 ]; then
[1770]891 lvScanRes=`gzip -cd $lvKernelImage | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicInitfs"`
[1570]892 else
893 # get offet of gzip magic "1f8b0800" in file
894 lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "1f8b0800")}'`
895 [ $lvOffset -eq 0 ] && Die "gzip magic not found in file $lvKernelImage. Terminating."
896 lvOffset=`expr $lvOffset / 2`
897 echo " GetInitrdFilesystemToUse(): gzip magic found at lvOffset $lvOffset.\n" >> $LOGFILE
[1099]898
[1570]899 # scan kernel image for initrd filessystem support
[1770]900 lvScanRes=`dd ibs=1 skip=$lvOffset if=$lvKernelImage obs=1M 2>/dev/null | gunzip -c 2> /dev/null | strings | grep -E "$lcMagicCramfs|$lcMagicExt2fs|$lcMagicInitfs"`
[1570]901 fi
[1099]902
903 # determine which filesystem to use for initrd image: ext2fs, gzip'ed cpio (initramfs ) or cramfs
[1770]904 if [ `echo $lvScanRes | grep -Ec "$lcMagicExt2fs"` -eq 1 ]; then
[1099]905 lvUseFilesystem="ext2fs"
[1770]906 elif [ `echo $lvScanRes | grep -Ec "$lcMagicInitfs"` -eq 1 ]; then
[1099]907 lvUseFilesystem="initramfs"
[1770]908 elif [ `echo $lvScanRes | grep -Ec "$lcMagicCramfs"` -eq 1 ]; then
[1099]909 lvUseFilesystem="cramfs"
910 else
911 lvUseFilesystem="UNSUPPORTED"
912 fi
913
914 # say what we are using
[1167]915 echo " GetInitrdFilesystemToUse(): Filesytem to use for initrd is $lvUseFilesystem.\n" >> $LOGFILE
[1099]916
917 # return file system to use
918 echo "$lvUseFilesystem"
919
920}
921
[747]922# Searches parent raid device of given disk device
923# $1: disk device (i.e. /dev/hda1)
924GetParentRaidDev() {
925 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {dev=\$2} /^[[:space:]]*device/ {if(\$2==\"$1\") {print dev; exit}}" < /etc/raidtab
926}
927
928
929# Searches members of raid device
930# $1: raid device (/dev/md...)
931GetRaidDevMembers() {
932 $AWK "/^[[:space:]]*#/ {next} /^[[:space:]]*raiddev/ {if(dev) exit; if(\$2 == \"$1\") dev=\$2} /^[[:space:]]*device/ {if(dev) {print \$2}}" < /etc/raidtab
933}
934
935
936HackPathsToFailsafe() {
937 local incoming newpath kver stub i pwd
938 kver=`uname -r`
939 incoming=`ReadLine`
940 pwd=`pwd`
[940]941 cd $MINDI_TMP
[747]942 while [ "$incoming" != "" ] ; do
[925]943 stub=`basename $incoming`
944 newpath=`FindSpecificModuleInPath lib/modules/$FAILSAFE_KVER $stub`
945 for i in $newpath ; do
946 echo "$i"
947 done
948 read incoming
[747]949 done
950 cd $pwd
951}
952
953
954ListAllPartitions() {
955 local res currline partition all_partitions ap_orig remaining i j
956
[1770]957 grep -vx " *#.*" $MY_FSTAB | grep -vx " *none.*" | $AWK '/^\/dev\/[imhs]d||^LABEL=\/|^UUID=/ && !/fdd|cdr|zip|floppy/ {print $1}'
[747]958 [ -e "/etc/raidtab" ] && $AWK '/^ *device/ {print $2}' /etc/raidtab
[1842]959 if [ -e "/vmfs/volumes" ]; then
960 # For VMWare ESX 3 get the device names of these volumes
961 vdf -P | grep -E '/vmfs/volumes' | awk '{print $1}'
962 fi
[747]963 return
964}
965
966
967ListImagesForUser() {
968 local path fname
969 path=$1
970 echo -en "In the directory '$path' you will find the images:-\n"
971 for fname in `ls $path | grep -F mindi-` ; do
972 printf "%19s " $fname
973 done
974 echo " "
975}
976
977
978ListKernelModulePaths() {
979 local module_list module fname oss r kern
980 oss="/root/oss/modules"
[1408]981 module_list="$MODULES"
[1177]982 # Remove unwanted modules from list
983 for i in $DENY_MODS; do
984 module_list=`echo ${module_list} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1770]985 EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1177]986 done
[747]987###
988### Sq-Modification ... Use kernelname for module search path if specified
989###
990 # kern="`uname -r`"
991 if [ "${kernelname}" != "" -a "${kernelname}" != "FAILSAFE" ]
992 then
993 kern=${kernelname}
994 else
995 kern="`uname -r`"
996 fi
997###
998### Sq-Mod End
999###
1000 for module in $module_list $EXTRA_MODS ; do
1001 r=`find /lib/modules/$kern -type f | grep "/${module}\..*o" | tail -n1`
1002 echo "module $module --> $r" >> $LOGFILE
1003 [ "$r" ] && echo "$r"
1004 [ -f "$oss" ] && find $oss | grep -F $module
1005 done
1006 find /lib/modules/$kern/modules.* -type f 2> /dev/null
1007 [ -f "$oss" ] && find $oss.* 2> /dev/null
1008}
1009
[1842]1010#
1011# Critical function which computes all dependencies (dyn. lib.)
1012# for a list of binaries
1013#
[747]1014LocateDeps() {
1015 local incoming fname deps
[1770]1016 incoming="$*"
[747]1017 for fname in $incoming ; do
1018 if [ ! -e "$fname" ] ; then
[963]1019 echo "WARNING - $fname does not exist; cannot be LDD'd." >> $LOGFILE
[747]1020 if echo $fname | grep lvm &> /dev/null ; then
1021 echo "This warning only affects you if you are using LVM." >> $LOGFILE
[1408]1022 if echo "$MODULES" | grep lvm &> /dev/null ; then
[747]1023 echo "I think you are, so please take heed!" >> $LOGFILE
1024 else
1025 echo "I don't think you are, so don't worry about it." >> $LOGFILE
1026 fi
1027 fi
1028 elif [ -h "$fname" ] && [ -x "$fname" ] ; then
1029 echo "$fname is softlink" >> $LOGFILE
1030 else
[1529]1031 ldd $fname 2> /dev/null | ProcessLDD
[747]1032 fi
1033 done
1034}
1035
[925]1036
[860]1037# Give all symlinks recursively of a full path name
1038ReadAllLink() {
1039 file="$1"
[747]1040
[860]1041 if [ ! -h $file ]; then
1042 echo "$file"
1043 return 0
1044 fi
[747]1045
[1020]1046 link=`readlink -f $file`
[862]1047 d=`dirname $file`
1048 if [ ! -e "$link" -a ! -e "$d/$link" ]; then
1049 echo "Problem with dead link on $file -> $link" >> $LOGFILE
1050 fi
[1059]1051 if [ -h "$d" ]; then
[1842]1052 echo "$link"
1053 echo "$d"
[860]1054 else
[1058]1055 echo "$link"
1056 fi
[860]1057}
1058
[925]1059
[747]1060LocateFile() {
1061 local i path fname_to_find location output resolved tmp stub cache_id loclist
1062 fname_to_find="$1"
[1529]1063 # It's an absolute path
[747]1064 if echo "$fname_to_find" | grep -x "/.*" ; then
[859]1065 output="$fname_to_find"
[860]1066 if [ -h "$output" ] ; then
1067 output="`ReadAllLink $output` $output"
1068 fi
[859]1069 echo "$output"
1070 return 0
[747]1071 fi
[1529]1072 # It's not an absolute path
[747]1073 output=""
[1529]1074 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
1075 #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
1076 [ -h "$path" ] && continue
1077 [ ! -e "$path/$fname_to_find" ] && continue
1078 output="$path/$fname_to_find $output"
1079 if [ -h "$path/$fname_to_find" ] ; then
1080 output="`ReadAllLink $path/$fname_to_find` $output"
1081 fi
[747]1082 done
1083 if [ "$output" = "" ] ; then
[860]1084 return 1
[747]1085 fi
1086 echo "$output"
1087 return 0
1088}
1089
1090
1091LogIt() {
1092 if [ -e /dev/stderr ] ; then
[925]1093 echo -e "$1" >> /dev/stderr
[747]1094 elif [ -e /usr/bin/logger ] ; then
[925]1095 /usr/bin/logger -s $1
[747]1096 fi
[965]1097 echo -e "$1" >> $LOGFILE
[747]1098}
1099
1100
1101MakeModuleLoadingScript() {
1102 local module fname params modpath kver outerloop i modpaths kver searchpath list_to_echo j
1103 tmpmodprobe_flag=$1
1104 outfile=$2
1105 > $outfile || Die "Cannot create empty $outfile"
1106 echo -en "#\041/bin/sh\n\n" >> $outfile
1107 echo "echo -en \"Loading your modules...\"" >> $outfile
1108 if [ "$YOUR_KERNEL_SUCKS" ] ; then
1109 kver=$FAILSAFE_KVER
[940]1110 cd $MINDI_TMP
[747]1111 searchpath=lib/modules/$kver
1112 else
1113###
1114### Sq-Modification ... Use kernelname for module search path if specified
1115###
1116 #kver=`uname -r`
1117 if [ "${kernelname}" != "" ]
1118 then
[925]1119 kver=${kernelname}
[747]1120 else
[925]1121 kver=`uname -r`
[747]1122 fi
1123###
1124### Sq-Modification end
1125###
1126 searchpath=/lib/modules/$kver
1127 fi
1128
1129 echo -en "for outerloop in 1 2 3 4 5 ; do\necho -en \".\"\n" >> $outfile
[1408]1130 list_to_echo="$MODULES"
[1177]1131 # Remove unwanted modules from list
1132 for i in $DENY_MODS; do
1133 list_to_echo=`echo ${list_to_echo} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1770]1134 EXTRA_MODS=`echo ${EXTRA_MODS} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
[1177]1135 done
[925]1136
[747]1137 # Make temporary modprobe.conf file if we are told so
[1347]1138 if [ "$tmpmodprobe_flag" = "Y" ] ; then
[940]1139 infile="$MINDI_TMP/modprobe.conf.mindi"
[747]1140 find /etc/modprobe.d -maxdepth 1 -name "*" -xtype f -print0 | xargs -0 cat > $infile
1141 else
1142 infile="/etc/modules.conf"
1143 fi
[1770]1144
[747]1145 for module in $list_to_echo $EXTRA_MODS ; do
1146 params=`sed -n "s/^options \\+$module \\+//p" $infile`
1147 modpaths=`FindSpecificModuleInPath $searchpath $module`
1148 for i in $modpaths ; do
1149 echo "MyInsmod $i $params > /dev/null 2> /dev/null" \
1150 | tr '.' '#' \
1151 | sed s/#o#gz/#o/ \
1152 | sed s/#o#gz/#o/ \
1153 | sed s/#ko#gz/#ko/ \
1154 | sed s/#ko#gz/#ko/ \
1155 | tr '#' '.' >> $outfile
1156 echo -en "$i added to module list.\n" >> $LOGFILE
1157 done
1158 done
1159 echo -en "done\n" >> $outfile
1160 echo "echo \"Done.\"" >> $outfile
1161 chmod +x $outfile
1162 cd /
1163 # Remove temporary modprobe.conf file if we have created one
[1347]1164 if [ "$tmpmodprobe_flag" = "Y" ] ; then
[747]1165 rm -f $infile
1166 fi
1167}
1168
1169
1170MakeMountlist() {
1171 local scratchdir mountlist all_partitions current_partition \
1172partition_size partition_format outstring partition_number \
1173partition_mountpt c_p lwm_info psz lvm_dev unofficial_outstring \
1174absolute_partition old_partition_fmt current_lvolume
1175
[967]1176 echo "Your raw fstab file looks like this:" >> $LOGFILE
1177 echo "------------------------------------" >> $LOGFILE
[747]1178 cat $MY_FSTAB >> $LOGFILE
[967]1179 echo "Your mountlist will look like this:" | tee -a $LOGFILE
1180 echo "-----------------------------------" >> $LOGFILE
[747]1181
1182# scratchdir, mountlist(OUT)
[940]1183 scratchdir=$MINDI_TMP
[747]1184 mountlist=$1
1185
1186# NB: partition = device
1187# NB: mountpt = where the device is mounted
1188
1189 [ -e "$MY_FSTAB" ] || Die "Cannot find your fstab file ($MY_FSTAB)"
1190
[1087]1191 [ "$mountlist" != "" ] && rm -Rf $mountlist
[747]1192 > $mountlist
1193 all_partitions=""
1194
1195 if [ $LVM != "false" ]; then
[1193]1196 echo -en "Analyzing LVM...\n"
[968]1197 $MINDI_LIB/analyze-my-lvm > $MINDI_TMP/lvm.res
[971]1198 if [ $? -ne 0 ]; then
[963]1199 LVM="false"
1200 fi
[968]1201 all_partitions=`cat $MINDI_TMP/lvm.res | grep -F ">>>" | cut -d' ' -f2-32`
[747]1202 fi
1203 all_partitions="$all_partitions `ListAllPartitions 2> /dev/null`"
1204# echo "all partitions = $all_partitions" > /dev/stderr
1205 for i in $IMAGE_DEVS ; do
1206 mount | grep -F "$i " > /dev/null 2> /dev/null && Die "Sorry, $i is already mounted! CANNOT DO IMAGEDEV on it if it's mounted."
1207 done
1208 [ "$IMAGE_DEVS" != "" ] && all_partitions="`echo "$all_partitions $IMAGE_DEVS" | tr ' ' '\n' | sort -u | tr '\n ' ' '`"
[1770]1209 printf " %-15s %-15s %-15s %-15s %-15s\n" DEVICE MOUNTPOINT FORMAT "SIZE (MB)" LABEL/UUID | tee -a $LOGFILE
[747]1210 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"
1211 for c_p in $all_partitions ; do
1212 [ "`echo "$useless_dev" | grep -F "$c_p"`" != "" ] || [ "`echo "$c_p" | grep ":"`" != "" ] && continue
1213 [ "`echo "$c_p" | grep -x "/dev/cdroms.*"`" ] && continue
1214 if [ -h "$c_p" ] && [ "`echo "$c_p" | grep -F "/dev/hd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/sd"`" = "" ] && [ "`echo "$c_p" | grep -F "/dev/md"`" = "" ] ; then
[861]1215 current_partition=`readlink -f $c_p`
[747]1216 [ "`echo "$current_partition" | grep -F "/dev/mapper"`" != "" ] && current_partition="$c_p"
1217 [ "`echo "$useless_dev" | grep -F "$current_partition"`" ] && continue
1218 else
1219 current_partition="$c_p"
1220 fi
1221 [ "$c_p" = "none" ] && continue
1222 redhat_label=""
[1842]1223 label=""
[957]1224 uuid=""
[861]1225 absolute_partition=`readlink -f $c_p`
[747]1226 partition_mountpt=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $2}' | head -n1`
1227
1228 # Detects noauto partitions not mounted and exclude them
1229 partition_option=`tr -s '\t' ' ' < $MY_FSTAB | /bin/grep -w "$current_partition" | /bin/grep -vx " *#.*" | $AWK '{print $4}' | head -n1`
1230 if [ "`echo "$partition_option" | grep -i noauto`" != "" ] && [ "`mount | grep -w "$partition_mountpt"`" = "" ] ; then
1231 continue
1232 fi
1233
1234 # This part tries to retrieve the correct device from a LABEL line in /etc/fstab
1235 # current_partition contains only first column of /etc/fstab
1236 if [ "`echo "$current_partition" | /bin/grep -i "LABEL="`" != "" ]; then
1237 str_to_find_fmt_with=$current_partition
[980]1238 redhat_label=`echo "$current_partition" | cut -d'=' -f2`
[747]1239 actual_dev=""
[853]1240
1241 # 1st try, findfs - the RHEL way of finding labels and their partitions
1242 if [ -x "/sbin/findfs" ]; then
[855]1243 actual_dev=`/sbin/findfs LABEL=${redhat_label} 2> /dev/null`
[853]1244 fi
[747]1245
[853]1246 # 2nd try : blkid, the good way for all LABEL except swap
1247 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1248 actual_dev=`/sbin/blkid | /bin/grep "$redhat_label" | grep LABEL= | cut -d':' -f1`
[747]1249 # For LVM FS it will give a /dev/dm-# which should then be converted
[748]1250 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1251 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1252 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[747]1253 for dev in `ls /dev/mapper/*`; do
[963]1254 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1255 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[747]1256 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1257 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[747]1258 break
1259 fi
1260 done
1261 fi
1262 fi
1263
[853]1264 # 3rd try, which works on a standard partition (ext2/3), but not on swap
[747]1265 # For LVM gives a /dev/mapper entry
1266 if [ "x$actual_dev" = "x" ]; then
[980]1267 actual_dev=`/bin/mount -l | /bin/grep "\[$redhat_label\]" | cut -d' ' -f1`
[747]1268 fi
1269
[853]1270 # 4th try, with vol_id
[747]1271 # SWAP only
1272 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1273 list_swaps=`cat /proc/swaps | /bin/grep "/dev/" | $AWK '{ print $1 }' `
[747]1274 for dev_swap in $list_swaps ; do
1275 dev_exists=`/sbin/vol_id $dev_swap | /bin/grep "$redhat_label"`
1276 if [ "x$dev_exists" != "x" ]; then
1277 actual_dev=$dev_swap
1278 break;
1279 fi
1280 done
1281 fi
1282
[853]1283 # 5th try : pre-formated LABEL. Format is : LABEL=SWAP-mydevice or SW-mydevice. e.g. : LABEL=SWAP-hda5
[789]1284 # LABEL=SW-cciss/c0d0p3 (RDP)
[853]1285 # or could be a string that isn't a complete device name (eg. LABEL =SWAP-cciss/c0d0p)
[747]1286 # SWAP only
[789]1287 if [ "x$actual_dev" = "x" -a _"`echo $current_partition | /bin/grep -iE 'LABEL=SWAP|LABEL=SW-'`" != _"" ]; then
[853]1288 for try_dev in `tail +2 /proc/swaps | cut -d' ' -f1`
1289 do
1290 # Location of the swap label for kernel 2.6
[1009]1291 try_dev_label=`dd bs=1 count=16 skip=1052 if=$try_dev 2> /dev/null`
[853]1292 if [ "x$try_dev_label" = "x$redhat_label" ]; then
[855]1293 actual_dev=$try_dev
[853]1294 fi
1295 done
[747]1296 fi
[1008]1297
1298 # Check if one of all those tries has known success
1299 if [ "x$actual_dev" != "x" ]; then
1300 current_partition=$actual_dev
1301 else
[1060]1302 Die "Your system uses a LABEL partition ($current_partition), but you lack the tool to support it.\nPlease replace labels with their correct devices in $MY_FSTAB or install findfs|blkid|vol_id"
[1008]1303 fi
[957]1304 # This part tries to retrieve the correct device from a UUID line in /etc/fstab
1305 # current_partition contains only first column of /etc/fstab
[1009]1306 elif [ "`echo "$current_partition" | /bin/grep -i "UUID="`" != "" ]; then
[957]1307 str_to_find_fmt_with=$current_partition
[980]1308 uuid=`echo "$current_partition" | cut -d'=' -f2`
[957]1309 actual_dev=""
1310
1311 # 1st try, findfs - the RHEL way of finding labels and their partitions
1312 if [ -x "/sbin/findfs" ]; then
1313 actual_dev=`/sbin/findfs UUID=${uuid} 2> /dev/null`
1314 fi
1315
[1530]1316 # 2nd try : blkid, the good way for all UUID except swap
[957]1317 if [ "x$actual_dev" = "x" -a -x "/sbin/blkid" ]; then
[980]1318 actual_dev=`/sbin/blkid | /bin/grep "$uuid" | grep UUID= | cut -d':' -f1`
[957]1319 # For LVM FS it will give a /dev/dm-# which should then be converted
1320 if [ $LVM = "v2" ] && [ "`echo $actual_dev | grep '/dev/dm'`" ]; then
[963]1321 major=`/bin/ls -l $actual_dev | $AWK '{print $5}'`
1322 minor=`/bin/ls -l $actual_dev | $AWK '{print $6}'`
[957]1323 for dev in `ls /dev/mapper/*`; do
[963]1324 major1=`/bin/ls -l $dev | $AWK '{print $5}'`
1325 minor1=`/bin/ls -l $dev | $AWK '{print $6}'`
[957]1326 if [ $major1 = $major ] && [ $minor1 = $minor ]; then
[963]1327 actual_dev=`/bin/ls -l $dev | $AWK '{print $10}'`
[957]1328 break
1329 fi
1330 done
1331 fi
1332 fi
1333
1334 # 3th try, with vol_id
1335 if [ "x$actual_dev" = "x" -a -x "/sbin/vol_id" ]; then
[963]1336 list_dev=`mount | /bin/grep -E '^/' | $AWK '{ print $1 }' `
[957]1337 for dev in $list_dev ; do
1338 dev_exists=`/sbin/vol_id $dev | /bin/grep "$uuid"`
1339 if [ "x$dev_exists" != "x" ]; then
1340 actual_dev=$dev
1341 break;
1342 fi
1343 done
1344 fi
1345
[1530]1346 # 4th try, with dumpuuid (VMWare only ?) for swap
1347 if [ "x$actual_dev" = "x" -a -x "/sbin/dumpuuid" ]; then
1348 list_dev=`cat /proc/swaps | /bin/grep -E '^/' | $AWK '{ print $1 }' `
1349 for dev in $list_dev ; do
1350 dev_exists=`/sbin/dumpuuid $dev | /bin/grep "$uuid"`
1351 if [ "x$dev_exists" != "x" ]; then
1352 actual_dev=$dev
1353 break;
1354 fi
1355 done
1356 fi
1357
[747]1358 # Check if one of all those tries has known success
1359 if [ "x$actual_dev" != "x" ]; then
1360 current_partition=$actual_dev
1361 else
[1060]1362 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"
[747]1363 fi
1364 else
1365 str_to_find_fmt_with=$current_partition
1366 fi
1367
1368 partition_format=`$AWK '$1 == "'"$str_to_find_fmt_with"'" {print $3}' $MY_FSTAB`
1369 # Some distributions such as Debian do not put /dev/<VG>/<LV> in fstab
1370 # for LVM partitions but use /dev/mapper/<VG>-<LV> instead. Fortunately,
1371 # the former is then a link to the latter, so we test whether
1372 # $current_partition is actually such a link or not and set
[755]1373 # $current_lvolume accordingly. On Debian you may find more than one answer
1374 # so we remove the one corresponding to /dev/.static
1375 # On RedHat even if the device name is different (/dev/mapper/<VG><LV>), the
1376 # principle is the same and we need to find the link to it as well.
1377 # Note that $current_lvolume may well be an
[747]1378 # ordinary device. It is just to make sure that we feed the right value
1379 # into any of the LVM tools if possible.
1380
1381 current_lvolume="$current_partition"
[763]1382 if [ $LVM = "v2" ] && [ "`echo $current_partition | grep -E '^/dev/mapper/'`" ]; then
[755]1383 # .static dir are a Debian specificity
[763]1384 current_lvolume="`find /dev -lname "$current_partition" | grep -Ev '^/dev/\.static/'`"
[755]1385 echo $current_lvolume | grep -q ' '
[784]1386 if [ $? -eq 0 ]; then
[755]1387 echo "WARNING: Multiple Logical Volumes found. Report to dev team" >> $LOGFILE
1388 fi
[747]1389 fi
1390 #
1391 # End of LVM device style variation code (other than $current_lvolume).
1392
[745]1393 if [ $LVM != "false" ] && [ "`$LVMCMD lvdisplay $current_lvolume 2> /dev/null`" ]; then
1394 # Size computed via LVM not directly
[747]1395 partition_size="lvm"
1396 else
1397 partition_size=`SizeOfPartition $current_partition`
1398 [ "`echo "$current_partition" | grep "[0-9]"`" = "" ] && continue
1399 [ "`echo "$current_partition" | grep -c "^/"`" -ne "1" ] && continue
1400 if [ "$partition_format" = "swap" ] || [ "$partition_mountpt" = "swap" ] ; then
1401 partition_size=`grep -Fv "Priority" /proc/swaps | tr -s '\t' ' ' | grep -F "$current_partition" | $AWK '{print $3}'`
1402 [ "$partition_mountpt" != "swap" ] && partition_mountpt="swap"
1403 [ "$partition_format" != "swap" ] && partition_format="swap"
1404 if [ "$partition_size" = "" ] ; then
1405 totalsize=0
1406 items=0
1407 for i in `tr -s ' ' '\t' < /proc/swaps | grep -Fv "Filename" | cut -f3` ; do
1408 totalsize=$(($totalsize+$i))
1409 items=$(($items+1))
1410 done
1411 [ "$items" -gt "0" ] && partition_size=$(($totalsize/$items)) || partition_size=0
1412 [ "$partition_size" -lt "125000" ] && partition_size=125000
1413 echo "I'm guessing $c_p is $(($partition_size/1024))MB" >> $LOGFILE
1414 fi
1415 fi
1416 fi
1417 [ "$partition_mountpt" = "swap" ] && partition_format="swap"
1418 [ "$partition_format" = "swap" ] && partition_mountpt="swap"
1419 if [ "$partition_mountpt" = "" ] ; then
1420 if [ "`$LVMCMD pvdisplay $current_lvolume 2> /dev/null`" != "" ] ; then
1421 if [ "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
1422 partition_mountpt="raid"
1423 partition_format="raid"
1424 else
1425 partition_mountpt="lvm"
1426 partition_format="lvm"
1427 fi
1428 fi
1429 fi
1430 psz=$partition_size
1431 echo "Examining $current_partition (mount=$partition_mountpt fmt=$partition_format psz=$psz)" >> $LOGFILE
1432 [ "$psz" != "lvm" ] && psz=$(($psz/1024))
1433 if [ "`echo " $IMAGE_DEVS " | grep -F " $current_partition "`" != "" ] ; then
1434 partition_mountpt="image"
1435 old_partition_fmt=$partition_format
1436 partition_format="`$FDISK -l 2>> $LOGFILE | tr '*' ' ' | tr '+' ' ' | tr -s ' ' '\t' | grep -w "$absolute_partition" | cut -f5`"
1437 partition_size=$(($partition_size+1)); # just in case
1438 if [ "$partition_format" = "Linux" ] ; then
1439 echo "Are you imaging a mounted swap partition? Silly..." >> $LOGFILE
1440 echo "Reverting format from $old_partition_fmt to $partition_format" >> $LOGFILE
1441 partition_format=$old_partition_fmt
1442 fi
1443 fi
1444 if [ "$EXCLUDE_DEVS" ] && [ "`echo " $EXCLUDE_DEVS " | grep -F " $current_partition "`" ] || [ "`echo " $EXCLUDE_DEVS " | grep " $current_partition "`" ] ; then
1445 echo "Excluding $current_partition from mountlist" >> $LOGFILE
1446 continue
1447 fi
1448 if [ ! "$partition_mountpt" ] ; then
[965]1449 echo "------- $FDISK -l $qq log ------------" >> $LOGFILE
[747]1450 for qq in "" `find /dev/ida/c*d* ! -name '*p*'` ; do
1451 partition_format=`$FDISK -l $qq 2>> $LOGFILE | grep -w "$c_p" | sed 's/12/|/' | tr -s '\t' ' ' | cut -d'|' -f2 | cut -d' ' -f2-9`
1452 [ "$partition_format" ] && break
1453 done
[965]1454 echo "------- $FDISK log end ------------" >> $LOGFILE
[747]1455 if [ "$partition_format" = "Compaq diagnostics" ] ; then
1456 partition_format="compaq"
1457 elif [ ! "`grep -F device /etc/raidtab 2> /dev/null | grep -w $current_partition`" ] ; then
[963]1458 LogIt "Unable to find mountpoint of $current_partition - ignoring"
[747]1459 continue
1460 fi
1461 fi
[1770]1462 if [ "$redhat_label" ]; then
1463 label="$redhat_label"
1464 elif [ "$uuid" ]; then
1465 label="$uuid"
1466 fi
[747]1467 partition_format="`echo "$partition_format" | cut -d',' -f1`"; # in case user has ext3,ext2 or something dumb like that
[963]1468 [ "$partition_format" = "auto" ] && partition_format="`mount | grep -w $current_partition | $AWK '{print$5;}'`"; # in case user uses 'auto' (dumb!)
[1770]1469 unofficial_outstring=`printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label"`
[747]1470 if [ "$current_partition" = "" ] ; then
1471 echo "Unknown partition (outstring = $unofficial_outstring)" >> $LOGFILE
1472 elif [ "$partition_mountpt" = "" ] && [ -f "/etc/raidtab" ] ; then
1473 if [ "`grep -F device /etc/raidtab 2>/dev/null | grep -F $current_partition`" ] ; then
1474 partition_mountpt=raid
1475 partition_format=raid
[1770]1476 printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1477 printf "%s %s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1478 else
1479 echo "Unknown mountpoint (outstring = $unofficial_outstring)" >> $LOGFILE
1480 fi
1481 elif [ "$partition_format" = "" ] ; then
1482 echo "Unknown format (outstring = $unofficial_outstring)" >> $LOGFILE
1483 elif [ "$partition_size" = "" ] ; then
1484 echo "Unknown partition size (outstring = $unofficial_outstring)" >> $LOGFILE
1485 elif [ "$partition_mountpt" = "/proc" ] || [ "$partition_mountpt" = "/dev/pts" ] ; then
1486 continue
1487 else
1488 if [ "$partition_format" = "dos" ] || [ "$partition_format" = "msdos" ] ; then
1489 echo "Stupid bastard..." >> $LOGFILE
1490 partition_format="vfat"
1491 fi
[1770]1492 printf "\t%-15s %-15s %-15s %7s %-15s\n" $current_partition $partition_mountpt $partition_format $psz "$label" | tee -a $LOGFILE
1493 printf "%s %s %s %s %s\n" $current_partition $partition_mountpt $partition_format $partition_size "$label" >> $mountlist
[747]1494 fi
1495 done
1496}
1497
1498
1499MakeSureNumberIsInteger() {
1500 res=`echo "$1" | tr -s '\-[0-9]' ' '`
1501 if [ "$res" != " " ] && [ "$res" != "" ] ; then
1502 echo "result = '$res'"
1503 Die "$1 should be an integer"
1504 fi
1505}
1506
1507
1508MakeSyslinuxMessageFile() {
1509 mkdir -p $1
1510 rmdir $1
1511 echo -en " " > $1
1512 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
1513 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 /etc/issue.net` `hostname`"% | sed s/KKKKK/"Kernel `uname -r` on a `uname -m`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ >> $1.tmp
1514 else
1515 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" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/KKKKK/"`grep -i "kernel" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ | sed s/' '\\r' 'on' 'an' '\/' '`uname -r`' 'on' 'an' '`uname -m`/ >> $1.tmp
1516 fi
1517 sed s/%r/"`uname -r`"/ $1.tmp | sed s/%t/"`hostname`"/ > $1
1518 rm -f $1.tmp
1519 if [ "$CDRECOVERY" != "yes" ] ; then
[1087]1520 if [ "$NFS_DEV" != "" ] ; then
[747]1521 echo -en "Press <enter> to continue.\n" >> $1
[940]1522 elif [ ! "$MINDI_TMP" ] ; then
[747]1523 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n" >> $1
1524 if [ -e "$MINDI_LIB/memtest.img" ] ; then
1525 echo -en "Type 'memtest' <Enter> to test your PC's memory intensively.\nJust press <Enter> to go to the main test menu.\n" >> $1
1526 fi
1527 else
1528 echo -en "$BOOT_MEDIA_MESSAGE" >> $1
1529 fi
1530 else
1531 echo -en " \
1532To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1533CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n" >> $1
1534 fi
1535}
1536
1537
1538MoveHyperlinkSensibly() {
1539 local filename minidir_root resides_on_diskno noof_disks old_diskno d old_pwd
1540 filename=$1
1541 minidir_root=$2
1542 resides_on_diskno=$3
1543 noof_disks=$4
1544
1545 [ -h "$minidir_root/$resides_on_diskno/$filename" ] || Die "$filename isn't a softlink (or doesn't exist): how can I move it sensibly?"
1546
1547 old_diskno=$resides_on_diskno
1548 d=1
1549 while [ "$d" -le "$noof_disks" ] ; do
1550 if [ "$d" -ne "$old_diskno" ] ; then
1551 old_pwd=`pwd`
1552 cd $minidir_root/$old_diskno
[963]1553 cp --parents -Rdf $filename $minidir_root/$d/ 2>> $LOGFILE || Die "Can't move $filename (sensibly) from $old_diskno to $d"
[747]1554 rm -f $filename
1555 cd $old_pwd
1556 fi
1557# when the softlink is resolvable, our work here is done
1558 [ -e "$minidir_root/$d/$filename" ] && return 0
1559 old_diskno=$d
1560 d=$(($d+1))
1561 done
1562 return 1
1563}
1564
1565
1566OfferToMakeBootableISO() {
1567 local i old_pwd
[1063]1568 if [ "$PROMPT_MAKE_CD_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[966]1569 echo -en "Shall I make a bootable CD image? (y/[n]) "
[747]1570 read i
1571 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
1572 fi
[1087]1573 if [ _"$MINDI_TMP" = _"" ]; then
1574 Die "MINDI_TMP undefined"
[747]1575 fi
[940]1576 rm -Rf $MINDI_TMP/iso
1577 mkdir -p $MINDI_TMP/iso/{images,archives,isolinux}
[963]1578 cp -f $1/*.img $1/*.gz $MINDI_TMP/iso/images 2>> $LOGFILE || LogIt "OfferToMakeBootableISO: Cannot copy $i to $MINDI_TMP/iso/images"
[747]1579 old_pwd=`pwd`
[940]1580 cd $MINDI_TMP/iso
[747]1581 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1582 for i in memdisk memtest.bin memtest.img ; do
[953]1583 j=$MINDI_LIB/$i
1584 k=$MINDI_TMP/iso/isolinux
1585 if [ -e "$j" ] ; then
[963]1586 LogIt "Copying $j to $k"
[953]1587 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1588 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
[1063]1589 if [ _"$MONDO_SHARE" != _"" ]; then
1590 cp -f $j $MONDO_ROOT 2>> $LOGFILE || Die "Failed to copy $j to $MONDO_ROOT"
1591 fi
[953]1592 fi
[747]1593 done
[940]1594 MakeSyslinuxMessageFile $MINDI_TMP/iso/isolinux/message.txt
[1063]1595 cp $kernelpath $MINDI_TMP/iso/isolinux/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/iso/isolinux/vmlinuz). Did you run out of disk space?"
[963]1596 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/iso/isolinux/initrd.img 2>> $LOGFILE
[1063]1597 if [ _"$MONDO_SHARE" != _"" ]; then
1598 cp $kernelpath $MONDO_ROOT/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
[1075]1599 cp $MINDI_TMP/mindi.rdz $MONDO_ROOT/initrd.img 2> /dev/null || Die "Cannot copy mindi.rdz ($MINDI_TMP/mindi.rdz) to mondo root ($MONDO_ROOT/vmlinuz). Did you run out of disk space?"
1600
[1063]1601 fi
[747]1602 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
[940]1603 cd $MINDI_TMP/iso/isolinux
[1075]1604 cat $iso_cfg_file | HackSyslinuxFile $ramdisk_size $MINDI_TMP/iso > isolinux.cfg || Die "Cannot copy isolinux.cfg to $MINDI_TMP/iso/isolinux - did you run out of disk space?"
[1087]1605 if [ "$NFS_DEV" != "" ] ; then
[1063]1606 perl -pi -e 's/interactive/iso/' isolinux.cfg
[747]1607 fi
1608 if [ "$ARCH" != "ia64" ] ; then
[1075]1609 cp $ISOLINUX isolinux.bin 2> /dev/null || Die "Cannot copy isolinux.bin ($ISOLINUX) to $MINDI_TMP/iso/isolinux - did you run out of disk space?"
[963]1610 cp $ISOLINUX ../ 2>> $LOGFILE
[747]1611 fi
[940]1612 cd $MINDI_TMP/iso
[747]1613 if [ "$ARCH" != "ia64" ] ; then
[1063]1614 if [ _"$MONDO_SHARE" != _"" ]; then
[1075]1615 cp -f $MINDI_TMP/iso/isolinux/{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?"
1616 cp -f $MONDO_SHARE/autorun . 2>> $LOGFILE
[1063]1617 fi
[1535]1618 $ISO_CMD -U $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table . > /dev/null 2> $MINDI_TMP/mkisofs.log
[747]1619 else
[1535]1620 $ISO_CMD $ISO_OPT -V Mindi_Image -o $MINDI_CACHE/mindi.iso -b images/mindi-bootroot.$BOOT_SIZE.img -c isolinux/boot.cat -no-emul-boot . > /dev/null 2> $MINDI_TMP/mkisofs.log
[747]1621 fi
1622 if [ "$?" -ne "0" ] ; then
[1535]1623 echo "----------- $ISO_CMD's errors --------------" >> $LOGFILE
[940]1624 cat $MINDI_TMP/mkisofs.log >> $LOGFILE
[1535]1625 echo "$ISO_CMD returned the following errors:-"
[940]1626 cat $MINDI_TMP/mkisofs.log
[963]1627 LogIt "Failed to create ISO image."
[747]1628 else
[1842]1629 echo "Created bootable ISO image at $MINDI_CACHE/mindi.iso" | tee -a $LOGFILE
[747]1630 fi
[940]1631 rm -f $MINDI_TMP/mkisofs.log
[747]1632 cd $old_pwd
1633}
1634
1635
[1063]1636OfferToMakeBootableUSB() {
1637 local i old_pwd
1638 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ _"$MONDO_SHARE" = _"" ]; then
[1842]1639 echo -n "Shall I make a bootable USB image ? (y/[n]) "
[1063]1640 read i
1641 [ "$i" != "y" ] && [ "$i" != "Y" ] && return 0
[1770]1642 if [ "$USBDEVICE" = "" ]; then
1643 echo -en "Please enter the device name of your USB device (e.g. /dev/sda) : "
1644 read dev
1645 USBDEVICE=$dev
1646 fi
1647 echo "WARNING: This will erase all content on $USBDEVICE"
1648 echo -en "Are you sure you want to use $USBDEVICE (y/[n]) "
[1063]1649 fi
[1087]1650 if [ _"$MINDI_TMP" = _"" ]; then
1651 Die "MINDI_TMP undefined"
1652 fi
[1063]1653 rm -Rf $MINDI_TMP/usb
1654 mkdir -p $MINDI_TMP/usb
[1087]1655 USBPART="${USBDEVICE}1"
[1063]1656
[1087]1657 echo -en "Transforming $USBDEVICE in a Bootable device "
[1063]1658 echo -en "."
[1087]1659 echo "Transforming $USBDEVICE in a Bootable device" >> $LOGFILE
1660 echo "Checking $USBDEVICE" >> $LOGFILE
1661 $FDISK -l $USBDEVICE 2>&1 >> $LOGFILE
[1063]1662 if [ $? -ne 0 ]; then
[1087]1663 echo "Unable to access $USBDEVICE" | tee -a $LOGFILE
[1063]1664 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
[1693]1665 exit -1
[1063]1666 fi
1667 echo -en "."
[1693]1668 echo "Unmounting $USBDEVICE just in case" >> $LOGFILE
[1770]1669 umount $USBPART 2>> $LOGFILE 1>> $LOGFILE
[1087]1670 echo "Erasing $USBDEVICE" >> $LOGFILE
[1770]1671 $FDISK $USBDEVICE 2>> $LOGFILE 1>> $LOGFILE << EOF
[1063]1672d
1673d
1674d
1675d
1676n
1677p
16781
1679
1680
1681t
1682b
1683a
16841
1685w
1686EOF
1687 if [ $? -ne 0 ]; then
[1087]1688 echo "Unable to create a vfat Filesystem on $USBDEVICE" | tee -a $LOGFILE
[1063]1689 echo "Make sure your USB device is pluged in" | tee -a $LOGFILE
[1087]1690 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]1691 MindiExit -1
1692 fi
1693 echo -en "."
1694 echo "Creating a vfat filesystem on $USBPART" >> $LOGFILE
[1693]1695 mkdosfs -F 32 $USBPART 2>&1 >> $LOGFILE
[1063]1696 if [ $? -ne 0 ]; then
1697 echo "Unable to create a vfat filesystem on $USBPART" | tee -a $LOGFILE
1698 echo "Make sure your USB device is pluged in and partitioned ($USBPART must exist on it)" | tee -a $LOGFILE
[1087]1699 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]1700 MindiExit -1
1701 fi
1702 echo -en "."
1703 echo "Mounting $USBPART on $MINDI_TMP/usb" >> $LOGFILE
1704 mount $USBPART $MINDI_TMP/usb 2>> $LOGFILE
1705 if [ $? -ne 0 ]; then
1706 echo "Unable to mount $USBPART on $MINDI_TMP/usb" | tee -a $LOGFILE
1707 echo "Make sure your USB device is pluged in, partitioned and formated ($USBPART must exist on it)" | tee -a $LOGFILE
[1087]1708 $FDISK -l $USBDEVICE 2>&1 | tee -a $LOGFILE
[1063]1709 MindiExit -1
1710 fi
1711 echo -en "."
[1693]1712 mkdir -p $MINDI_TMP/usb/images
1713 cp -f $1/*.img $1/*.gz $MINDI_TMP/usb/images 2>> $LOGFILE || LogIt "OfferToMakeBootableUSB: Cannot copy $i to $MINDI_TMP/usb/images"
[1063]1714 echo -en "."
1715 old_pwd=`pwd`
1716 cd $MINDI_TMP/usb
1717 echo "mindi_lib = $MINDI_LIB" >> $LOGFILE
1718 for i in memdisk memtest.bin memtest.img ; do
1719 j=$MINDI_LIB/$i
1720 k=$MINDI_TMP/usb
1721 if [ -e "$j" ] ; then
1722 LogIt "Copying $j to $k"
1723 cp -f $j $k 2> /dev/null || Die "Failed to copy $j to $k"
1724 cp -f $j $MINDI_TMP 2> /dev/null || Die "Failed to copy $j to $MINDI_TMP"
1725 fi
1726 done
1727 echo -en "."
1728 MakeSyslinuxMessageFile $MINDI_TMP/usb/message.txt
1729 echo -en "."
1730 cp $kernelpath $MINDI_TMP/usb/vmlinuz 2> /dev/null || Die "Cannot copy vmlinuz ($kernelpath) to mindi tmp ($MINDI_TMP/usb/syslinux/vmlinuz). Did you run out of disk space?"
1731 echo -en "."
1732 cp $MINDI_TMP/mindi.rdz $MINDI_TMP/usb/initrd.img 2>> $LOGFILE
1733 echo -en "."
1734 [ -e "$iso_cfg_file" ] || Die "FIXME - unable to find $iso_cfg_file - this should never occur"
[1075]1735 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $MINDI_TMP/usb > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to $MINDI_TMP/usb - did you run out of disk space?"
[1063]1736 echo -en "."
[1087]1737 if [ "$NFS_DEV" != "" ] ; then
[1063]1738 perl -pi -e 's/interactive/iso/' syslinux.cfg
1739 fi
1740 cd $old_pwd
1741 echo -en "."
[1770]1742 umount $MINDI_TMP/usb
[1063]1743 if [ "$ARCH" != "ia64" ] ; then
1744 syslinux $USBPART 2>> $MINDI_TMP/syslinux.log
[1544]1745 if [ "$?" -ne "0" ] ; then
1746 echo "----------- syslinux's errors --------------" |tee -a $LOGFILE
1747 cat $MINDI_TMP/syslinux.log |tee -a $LOGFILE
1748 LogIt "Failed to create USB image."
1749 else
1750 echo -e "$DONE"
1751 echo "Created bootable USB image on $USBDEVICE" >> $LOGFILE
1752 fi
1753 rm -f $MINDI_TMP/syslinux.log
[1063]1754 else
1755 echo "No USB boot support for ia64" | tee -a $LOGFILE
1756 MindiExit -1
1757 fi
1758 echo -en "."
1759}
1760
1761
[747]1762PluralOrNot() {
1763 [ "$1" -gt "1" ] && echo -en "s"
1764}
1765
1766
1767MakeMessageFile() {
1768 if [ "`grep -Fi "debian" /etc/issue.net 2> /dev/null`" ] ; then
1769 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 /etc/issue.net` `hostname`"% | sed s/KKKKK/"Kernel `uname -r` on a `uname -m`"/ | sed s/TTTTT/"`LC_TIME=C date`"/
1770 else
1771 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" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/KKKKK/"`grep -i "kernel" /etc/issue.net | head -n1 | tr -s ' ' ' '`"/ | sed s/TTTTT/"`LC_TIME=C date`"/ | sed s/' 'r' 'on' 'an' 'm/' '`uname -r`' 'on' 'an' '`uname -m`/
1772 fi
[1573]1773 if [ _"$MONDO_SHARE" != _"" ]; then
1774 if [ "$CDRECOVERY" != "yes" ] ; then
1775 if [ "$NFS_DEV" != "" ] ; then
1776 echo -en "Press <enter> to continue.\n"
1777 elif [ ! "$MINDI_TMP" ] ; then
1778 echo -en "FYI, this is _not_ a Mondo Rescue CD.\n"
1779 else
1780 echo -en "$BOOT_MEDIA_MESSAGE"
[747]1781 fi
1782 fi
1783 fi
1784 if [ "$CDRECOVERY" = "yes" ] ; then
1785 echo -en "\
1786To restore your disk to factory defaults, type 'RESTORE' <enter>.\n\
1787CAUTION: THIS WILL ERASE YOUR WHOLE DISK !!!\n"
1788 fi
1789 echo -en "\n\n\n"
1790}
1791
1792
1793MakeLiloConfFile() {
[1573]1794 local options i ooo
[747]1795 options=""
[925]1796
1797 if [ "$ARCH" != "ia64" ] ; then
1798 echo -en "boot=/dev/loop0\ndisk=/dev/loop0\n"
1799 echo -en "install=/boot.b\nmap=/boot.map\n"
1800 fi
[747]1801 if [ "$CDRECOVERY" = "yes" ] ; then
1802 echo -en "default=RESTORE\n"
[1573]1803 elif [ _"$MONDO_SHARE" != _"" ]; then
[1087]1804 if [ "$NFS_DEV" != "" ] ; then
[747]1805 echo -en "default=iso\n"
1806 else
1807 echo -en "default=interactive\n"
1808 fi
1809 else
1810 echo -en "default=expert\n"
1811 fi
1812
1813 echo -en "prompt\n"
1814 if [ "$ARCH" != "ia64" ] ; then
1815 echo -en "vga=normal\nbackup=/dev/null\nmessage=/message\n"
1816 fi
1817 if [ "$CDRECOVERY" != "yes" ] ; then
[925]1818 echo -en "timeout=300\n"
[747]1819 fi
1820 echo -en "\n"
1821 if [ "$CDRECOVERY" = "yes" ] ; then
[925]1822 options="RESTORE expert"
[1573]1823 else
[1063]1824 if [ _"$MONDO_SHARE" != _"" ]; then
[1087]1825 if [ "$NFS_DEV" != "" ] ; then
[747]1826 options="iso"
1827 else
1828 options="interactive expert compare iso nuke isonuke"
1829# hda hdb hdc hdd"
1830 fi
1831 else
1832 options="expert"
[925]1833 fi
[747]1834 fi
1835 for i in $options ; do
[925]1836 ooo=$i
1837 [ "$ooo" = "RESTORE" ] && ooo="nuke"
1838 if [ "$ARCH" = "ia64" ] ; then
1839 rootpart="root=/dev/ram0\n\t"
1840 else
1841 rootpart=""
1842 fi
[1072]1843 outstr="image=/vmlinuz\n\tlabel=$i\n\tinitrd=/mindi.rdz\n\t${rootpart}append=\" rw ramdisk=$ramdisksize ramdisk_size=$ramdisksize maxcpus=1 $ooo_mode $ADDITIONAL_BOOT_PARAMS"
[747]1844
[925]1845 outstr=$outstr" $ooo_mode"
1846 outstr=$outstr"\"\n"
[1573]1847 echo -en "$outstr"
[747]1848 done
1849}
1850
1851
1852PrepareBootDiskImage_LILO() {
[1573]1853 local imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size liloconf
[747]1854 imagesdir=$1
[1573]1855 kernelpath=$2
1856 ramdisksize=$3
[747]1857
1858 retval=0
1859 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
[1573]1860 echo -en "Making "$BOOT_SIZE"KB boot disk..."
1861 TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/mindi.rdz $ramdisksize `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into mindi.rdz; are you SURE your kernel supports loopfs?"
[747]1862 echo -en "..."
[1573]1863 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
[940]1864 mountpoint=$MINDI_TMP/mountpoint.$$
[747]1865 mkdir -p $mountpoint
[1573]1866 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[747]1867 if [ "$ARCH" = "ia64" ] ; then
[964]1868 mkdosfs $imagefile >> $LOGFILE 2>> $LOGFILE
1869 t=vfat
[747]1870 else
[1075]1871 echo "Creating ext2 filesystem on $imagefile" >> $LOGFILE
[1255]1872 mke2fs -N 26 -m 0 -F $imagefile &> /dev/null || Die "Unable to create an ext2 file system on $imagefile"
[964]1873 t=ext2
[747]1874 fi
[963]1875 mount -t $t -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
[964]1876 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]1877 mkdir -p $mountpoint/etc
1878 if [ "$ARCH" != "ia64" ] ; then
1879 liloconf=$mountpoint/etc/lilo.conf
1880 else
[925]1881 liloconf=$mountpoint/elilo.conf
[747]1882 fi
1883 old_pwd=`pwd`
1884 cd $mountpoint
1885 if [ "$ARCH" != "ia64" ] ; then
[963]1886 tar -zxf $MINDI_LIB/dev.tgz || LogIt "Cannot untar dev.tgz"
[747]1887 fi
1888 cd $old_pwd
[1312]1889 # BERLIOS : Useless and generating errors on CentOS ? (losetup miss a param)
1890 #losetup /dev/loop0 > /dev/null 2> /dev/null
1891 #[ "$?" -eq "0" ] || losetup /dev/loop0 -d || Die "Please free up /dev/loop0 by typing 'losetup /dev/loop0 -d'.\nReboot if necessary."
[747]1892 CopyBootBFile $mountpoint/boot.b
1893
[1573]1894 MakeLiloConfFile > $liloconf
[747]1895
[1072]1896 # Copy it so that CD-ROM menu entry is satisfied
1897 if [ "$ARCH" = "ia64" ] ; then
1898 mountefi=0
1899 df -T | grep /boot/efi | grep -q vfat
1900 if [ $? -ne 0 ]; then
1901 mount /boot/efi
1902 if [ $? -ne 0 ]; then
1903 echo "You have to mount your EFI partition when using mindi"
1904 MindiExit -1
1905 fi
1906 mountefi=1
1907 fi
[1770]1908 el=`find /boot/efi -name elilo.efi`
1909 cp $el $mountpoint
[1842]1910 cp $liloconf $mountpoint
[1072]1911 if [ $mountefi -eq 1 ]; then
1912 umount /boot/efi 2>&1 > /dev/null
1913 fi
1914 fi
1915
[940]1916 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint..." >> $LOGFILE
1917 cp -f $MINDI_TMP/mindi.rdz $mountpoint 2>> $LOGFILE
[747]1918 if [ "$?" -ne "0" ] ; then
[963]1919 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[940]1920 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[963]1921 LogIt "Please unload some of your modules and try again."
[940]1922 rm -f $MINDI_TMP/mtpt.$$
[963]1923 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[747]1924 retval=$(($retval+1))
1925 fi
[1573]1926 MakeMessageFile > $mountpoint/message
[747]1927
1928 mkdir -p $mountpoint/tmp
[940]1929 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[747]1930 if [ -e "$MINDI_LIB/memtest.img" ] ; then
1931 echo -en "image=/memtest.bin\nlabel=memtest\nn" >> $liloconf
1932 echo -en "image=/memdisk\nlabel=memtest\nappend=\"initrd=memtest.img\"\n" >> $liloconf
1933# echo "Yep, this is a multi-function CD" > $mountpoint/MULTIFUNC
1934 fi
1935
[925]1936 # copy the kernel across
[1087]1937 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]1938 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
1939 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1940 cp -f $kernelpath $mountpoint/vmlinuz > /dev/null 2> /dev/null
[1573]1941 if [ "$?" -ne "0" ] ; then
[925]1942 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
1943 du -sk $mountpoint/* >> $LOGFILE
1944 echo "--- end of list of files ---" >> $LOGFILE
1945 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
[1573]1946Sorry, your kernel is too big for your image.\n" >> $LOGFILE
[747]1947 rm -f $mountpoint/vmlinuz
[925]1948 cd $old_pwd
[747]1949 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[963]1950 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[925]1951 # losetup /dev/loop0 -d
1952 rm -f $imagefile
[1573]1953 return 0
[747]1954 fi
1955 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
1956 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
[1573]1957 echo "Free space left on image = $free_space KB" >> $LOGFILE
1958 echo "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K" >> $LOGFILE
[1842]1959 # make it bootable
[747]1960 rm -f $mountpoint/zero
[963]1961 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[1573]1962 if [ ! "$KERN_DISK_MADE" ] ; then
[747]1963 if [ "$ARCH" != "ia64" ] ; then
[1573]1964 $LILO_EXE -r $mountpoint >> $LOGFILE 2>> $LOGFILE
[1842]1965 else
1966 /bin/true
[747]1967 fi
1968 else
[925]1969 echo "Not running LILO. It's not that kind of disk." >> $LOGFILE
[747]1970 fi
[925]1971
1972 # BERLIOS does not test necessarily what it expects
[747]1973 if [ $? -ne "0" ] ; then
[925]1974 if [ "`grep -F "/tmp/dev.0" $LOGFILE`" ] ; then
[963]1975 LogIt "The '/tmp/dev.0' error is NOT Mindi's fault. It is LILO's."
1976 LogIt "Please reboot your PC as a workaround."
1977 Die "LILO sneezed and Mindi caught a cold. Please read the README / FAQ."
[925]1978 fi
1979 echo "$LILO_EXE -r $mountpoint ...failed."
1980 echo -en "Press ENTER to continue."; read line
[963]1981 LogIt "Cannot run lilo on $mountpoint\nPlease upgrade/downgrade your version of LILO. It has a bug."
[925]1982 retval=$(($retval+1))
[747]1983 fi
[963]1984 cp -f $liloconf $MINDI_TMP/lilo.conf 2>> $LOGFILE
[747]1985 if [ "$ARCH" = "ia64" ] ; then
[963]1986 cp `dirname $kernelpath`/*.efi $mountpoint 2>> $LOGFILE
[747]1987 fi
1988 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
1989 echo -en "..."
[963]1990 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]1991 if [ "$retval" -eq "0" ] ; then
[1193]1992 echo -en "...$DONE\n"
[747]1993 if [ "$KERN_DISK_MADE" ] ; then
[1573]1994 LogIt "$BOOT_SIZE KB boot disks were created OK\n"
[747]1995 fi
1996 else
[1193]1997 echo -en "...failed\n"
[1573]1998 LogIt $BOOT_SIZE"KB boot disk was NOT created\n"
[747]1999 rm -f $imagefile
2000 fi
[963]2001 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[747]2002 return $retval
2003}
2004
2005
2006PrepareBootDiskImage_SYSLINUX() {
[1573]2007 local imagesdir dev imagefile mountpoint fname i kernelpath ramdisksize cfg_file testpath options retval outstr old_pwd ooo max_kernel_size bootimage
[747]2008 imagesdir=$1
[1573]2009 kernelpath=$2
2010 ramdisksize=$3
[747]2011 do_boot_root_thingy=""
2012 local retval old_pwd
2013 retval=0
[925]2014
[747]2015 [ ! -e "$kernelpath" ] && Die "PBDI - cannot find $kernelpath kernel"
[1573]2016 echo -en "Making "$BOOT_SIZE"KB boot disk..."
2017 TurnTgzIntoRdz $MINDI_LIB/rootfs $MINDI_TMP/mindi.rdz $ramdisksize `du -sk $kernelpath | cut -f1` || Die "Could not turn rootfs into mindi.rdz; are you SURE your kernel supports loopfs?"
[747]2018 echo -en "..."
[1573]2019 imagefile=$imagesdir/mindi-bootroot.$BOOT_SIZE.img
[940]2020 mountpoint=$MINDI_TMP/mountpoint.$$
[747]2021 mkdir -p $mountpoint
[1573]2022 dd if=/dev/zero of=$imagefile bs=1k count=$BOOT_SIZE &> /dev/null || Die "Cannot dd blank file"
[1121]2023 echo "Creating vfat filesystem on $imagefile" >> $LOGFILE
2024 mkfs.vfat $imagefile >> $LOGFILE 2>> $LOGFILE
2025 syslinux $imagefile >> $LOGFILE 2>> $LOGFILE
2026
[963]2027 mount -t vfat -o loop $imagefile $mountpoint || LogIt "Cannot mount (PBDI)"
[925]2028
2029 # copy Mindi's skeleton fs & lilo/syslinux/whatever stuff into it
[747]2030 old_pwd=`pwd`
2031 MakeSyslinuxMessageFile $mountpoint/message.txt
2032 cd $mountpoint
2033 [ -e "$sys_cfg_file" ] || Die "Obi Wan, word up?"
2034 cat $sys_cfg_file | HackSyslinuxFile $ramdisk_size $mountpoint > syslinux.cfg || Die "Cannot copy syslinux.cfg from mindi_home to tmp_root"
[1087]2035 if [ "$NFS_DEV" != "" ] ; then
[1063]2036 perl -pi -e 's/interactive/iso/' syslinux.cfg
[747]2037 fi
2038 cd $old_pwd
[940]2039 echo "Copying $MINDI_TMP/mindi.rdz to $mountpoint/initrd.img..." >> $LOGFILE
2040 cp -f $MINDI_TMP/mindi.rdz $mountpoint/initrd.img 2>> $LOGFILE
[747]2041 if [ "$?" -ne "0" ] ; then
[963]2042 LogIt "Failed to copy $MINDI_TMP/mindi.rdz to $mountpoint"
[940]2043 cat $MINDI_TMP/mtpt.$$ >> $LOGFILE
[963]2044 LogIt "Please unload some of your modules and try again."
[940]2045 rm -f $MINDI_TMP/mtpt.$$
[963]2046 LogIt "Cannot incorporate mindi.rdz in bootdisk (kernel / modules too big?)"
[747]2047 retval=$(($retval+1))
2048 fi
2049
2050 mkdir -p $mountpoint/tmp
[940]2051 cp -f $MINDI_TMP/mondo-restore.cfg $mountpoint/tmp &> /dev/null
[747]2052
[925]2053 # copy the kernel across
[1087]2054 [ "$mountpoint" != "" ] && rm -Rf $mountpoint/lost+found
[747]2055 dd if=/dev/zero of=$mountpoint/zero bs=1k count=16 &> /dev/null
2056 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2057 cp -f $kernelpath $mountpoint/vmlinuz &> /dev/null
[1573]2058 if [ "$?" -ne "0" ] ; then
[747]2059 echo "Files at mountpoint ($mountpoint) :-" >> $LOGFILE
2060 du -sk $mountpoint/* >> $LOGFILE
2061 echo "--- end of list of files ---" >> $LOGFILE
2062 echo -en "Kernel size = `du -sk $kernelpath | cut -f1` K\nRamdisk free = $free_space K\n\
[1573]2063Sorry, your kernel is too big for your image.\n" >> $LOGFILE
[747]2064 rm -f $mountpoint/vmlinuz
2065 cd $old_pwd
2066 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
[963]2067 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]2068
2069 rm -f $imagefile
[1573]2070 return 0
[747]2071 fi
2072 free_space=`df -k -P $mountpoint | tail -n1 | tr -s ' ' '\t' | cut -f4`
2073 max_kernel_size=$(($free_space+`du -sk $kernelpath | cut -f1`))
[1573]2074 echo "Free space left on image = $free_space KB" >> $LOGFILE
2075 echo "Max kernel size on $BOOT_SIZE KB image (est'd) = $max_kernel_size K" >> $LOGFILE
[925]2076
2077 # make it bootable
[747]2078 rm -f $mountpoint/zero
2079 mkdir -p $mountpoint/etc
[963]2080 [ -e "$MINDI_LIB/memdisk" ] && cp -f $MINDI_LIB/memdisk $mountpoint 2>> $LOGFILE
[747]2081 umount $mountpoint || Die "Cannot unmount mountpoint ($mountpoint)"
2082 echo -en "..."
[963]2083 rmdir $mountpoint || LogIt "Cannot rmdir (PBDI)"
[747]2084
2085 if [ "$retval" -eq "0" ] ; then
[1193]2086 echo -en "...$DONE\n"
[747]2087 if [ "$KERN_DISK_MADE" ] ; then
2088 rm -f $imagefile
[1573]2089 LogIt "$BOOT_SIZE KB boot disks were created OK\n"
[747]2090 fi
2091 else
[1193]2092 echo -en "...failed\n"
[1573]2093 LogIt $BOOT_SIZE"KB boot disk was NOT created\n"
[747]2094 rm -f $imagefile
2095 fi
[963]2096 [ "$retval" -ne "0" ] && LogIt "PrepareBootDiskImage() is returning nonzero"
[747]2097 return $retval
2098}
2099
2100
2101PrepareDataDiskImages() {
[1060]2102 local needlist bigdir minidir_root tardir diskdir imagesdir res i j k old_pwd lines lfiles
[747]2103
2104 imagesdir=$1
2105 rm -f $imagesdir/mindi-*.img $imagesdir/[0-9]*.tar.gz $imagesdir/mindi.iso
[940]2106 needlist=$MINDI_TMP/what-we-need.txt
2107 bigdir=$MINDI_TMP/bigdir
2108 minidir_root=$MINDI_TMP/minidir
[747]2109 mkdir -p $minidir_root
2110 mkdir -p $bigdir/usr/bin
[940]2111 tardir=$MINDI_TMP/tardir
[747]2112
[1060]2113 if [ -e "$DEPLIST_FILE" ]; then
2114 lfiles="$DEPLIST_FILE $DEPLIST_DIR/*"
2115 else
2116 lfiles="$DEPLIST_DIR/*"
2117 fi
2118 lines=`grep -vx " *#.*" $lfiles | grep -vx "" | wc -l`
2119 cat $lfiles | GenerateGiantDependencyList $needlist $lines
[747]2120 res=$?
2121 if [ "$YOUR_KERNEL_SUCKS" ]; then
[925]2122 pwd=`pwd`
[940]2123 cd $MINDI_TMP
[747]2124 for i in `ListKernelModulePaths | HackPathsToFailsafe` ; do
[963]2125 cp --parents -pRdf ./$i $bigdir 2>> $LOGFILE || Die "PDDI can't cp $i->$bigdir"
[925]2126 if [ "`du -sk $i | cut -f1`" -lt "$(($CHOPSIZE*2))" ] ; then
[963]2127 cp --parents -pRdf $i $bigdir 2>> $LOGFILE
[925]2128 else
2129 ChopUpAndCopyFile $i $bigdir $CHOPSIZE $BIGNO
2130 BIGNO=$(($BIGNO+1))
2131 fi
[747]2132 done
[925]2133 for i in $EXTRA_MODS ; do
[1842]2134 j=`find lib/modules/$FAILSAFE_KVER -name $i.*o.gz 2> /dev/null`
2135 [ ! "$j" ] && echo "WARNING - cannot find failsafe module $i.o.gz" >> $LOGFILE
[925]2136 for k in $j ; do
2137 if [ "`du -sk $k | cut -f1`" -lt "$CHOPSIZE" ] ; then
[963]2138 cp --parents -pRdf $k $bigdir 2>> $LOGFILE
[925]2139 else
2140 ChopUpAndCopyFile $k $bigdir $CHOPSIZE $BIGNO
2141 BIGNO=$(($BIGNO+1))
2142 fi
2143 echo "Added failsafe module $k to ramdisk" >> $LOGFILE
2144 done
2145 done
2146 cd $pwd
[747]2147 else
[925]2148 ListKernelModulePaths >> $needlist
[747]2149 fi
2150 if [ "$res" -ne "0" ] ; then
2151 Die "You have $res file`PluralOrNot $res` present in dependency list\nbut absent from filesystem."
2152 fi
2153 FindAndAddUserKeyboardMappingFile
2154 mkdir -p $bigdir/tmp
[1063]2155 if [ _"$MONDO_SHARE" != _"" ]; then
[1163]2156 cp -f $MONDORESTORECFG $bigdir/tmp &> /dev/null
[747]2157 fi
2158 [ -d "/mnt/.boot.d" ] && echo "Oh Jebus" > $bigdir/tmp/DUMBASS-GENTOO
2159 DropOptimizedLibraries $needlist $bigdir
2160 echo -en "Assembling dependency files"
2161 CopyDependenciesToDirectory < $needlist $bigdir
2162
[925]2163 # also copy io.sys and msdos.sys, if we can find them
[747]2164 for i in `mount | cut -d' ' -f3` ; do
[925]2165 for j in io.sys msdos.sys ; do
[963]2166 [ -e "$i/$j" ] && cp -f $i/$j $bigdir 2>> $LOGFILE
[925]2167 done
[747]2168 done
2169
[925]2170 # master boot record, too
[1141]2171 if [ _"$MONDORESTORECFG" != _"" ]; then
[1158]2172 i=`grep bootloader.device $MONDORESTORECFG | cut -d'=' -f2 2> /dev/null`
[1141]2173 if [ "$i" ] ; then
2174 LogIt "Backing up $i's MBR"
2175 dd if=$i of=$bigdir/BOOTLOADER.MBR bs=446 count=1 >> $LOGFILE 2>> $LOGFILE
2176 sleep 1
2177 sync
2178 j=$i
2179 [ -h "$j" ] && j=`readlink -f $j`
2180 LogIt "Creating /dev/boot_device ($j)"
2181 mkdir -p $bigdir/dev
2182 cp -pRdf $j $bigdir/dev/boot_device 2> /dev/null || Die "Unable to create /dev/boot_device on ramdisk"
2183 fi
[747]2184 fi
2185
2186 old_pwd=`pwd`
2187 cd $bigdir
2188
2189 [ -e "$MINDI_LIB/aux-tools" ] || Die "aux-tools not found in Mindi's home dir. Do you have multiple copies of Mindi lying around? Please delete them. No, don't e-mail me and ask how. ;) Use 'rm'."
[963]2190 cp -Rdf $MINDI_LIB/aux-tools/* . 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping aux-tools"
[747]2191 if [ -e "$MINDI_LIB/x11-tools.tgz" ] ; then
[963]2192 tar -zxf $MINDI_LIB/x11-tools.tgz 2>> $LOGFILE || LogIt "WARNING - error occurred while unzipping x11-tools.tgz"
[747]2193 fi
[1063]2194 if [ -e "$MONDO_SHARE/restore-scripts" ]; then
[747]2195 cp -Rdf $MONDO_SHARE/restore-scripts/* . 2>> $LOGFILE
[1337]2196 [ "$?" -ne "0" ] && [ _"$MONDO_SHARE" != _"" ] && Die "Cannot find/install $MONDO_SHARE/restore-scripts"
[747]2197 fi
[963]2198 [ -d "/lib/dev-state" ] && cp --parents -pRdf /lib/dev-state . 2>> $LOGFILE
[747]2199 cd $old_pwd
2200 echo -e "$DONE"
2201 TOTAL_BIGDIR_SIZE=`du -sk $bigdir | cut -f1`
2202 SplitDirectoryIntoMinidirs $bigdir $minidir_root
2203 noof_disks=$?
2204 [ "$noof_disks" -eq "0" ] && Die "Too much stuff!"
[940]2205 MakeMountlist $MINDI_TMP/mountlist.txt
[747]2206 mkdir -p $minidir_root/$noof_disks/tmp
[953]2207 cp -f $MINDI_TMP/mountlist.txt $minidir_root/$noof_disks/tmp/mountlist.txt 2> /dev/null || Die "Cannot copy mountlist.txt from $MINDI_TMP to data disk"
[1063]2208 if [ _"$MONDO_SHARE" != _"" ]; then
2209 cp -f $minidir_root/$noof_disks/tmp/mountlist.txt $MINDI_TMP/. 2>> $LOGFILE
2210 fi
[964]2211 [ $LVM != "false" ] && $MINDI_LIB/analyze-my-lvm > $minidir_root/$noof_disks/tmp/i-want-my-lvm || LVM="false"
[747]2212 cat $minidir_root/$noof_disks/tmp/mountlist.txt >> $LOGFILE
2213 ZipMinidirsIntoTarballs $minidir_root $tardir $noof_disks
2214 CreateDataDiskImagesFromTarballs $tardir $imagesdir $noof_disks
2215 FRIENDLY_OUTSTRING="Boot and data disk images were created."
[925]2216 # One 1.72MB boot disk, one 2.88MB boot disk and $noof_disks data disk images
[747]2217 rmdir $tardir $bigdir
2218 rm -f $needlist
2219 return $noof_disks
2220}
2221
2222
2223ProcessLDD() {
[1842]2224 local incoming f d nd bd bnd
[747]2225 read incoming
[1842]2226 while [ "$incoming" != "" ]; do
[859]2227 # We take the full path name of the dyn. lib. we want
[1529]2228 incoming=`echo "$incoming" | awk '{if (match($1,/\//)) {print $1} else {if (match($3,/\//)) print $3} fi}'`
2229 for f in $incoming ; do
[1842]2230 # echo modified file name if one of the parent dir is a link
2231 # by replacing the original dirname by the destination of the link
2232 d="`dirname $f`"
2233 found="false"
2234 while [ "$d" != "/" ]; do
2235 if [ -h "$d" ]; then
2236 nd=`readlink -f $d`
2237 bd=`basename $d`
2238 bnd=`basename $nd`
2239 f=`echo $f | sed "s~/$bd/~/$bnd/~"`
2240 echo $d
2241 fi
2242 d="`dirname $d`"
2243 done
2244
[1770]2245 echo "$f"
2246 echo "`ReadAllLink $f`"
[747]2247 done
2248 read incoming
2249 done
2250}
2251
2252
2253Prompt() {
2254 echo -en "$1"
2255 read line
2256}
2257
2258
2259ReadLine() {
2260 local i incoming
2261 read incoming
2262 i=0
2263 while [ "$i" -le "32" ] && [ "$incoming" = "" ] ; do
[925]2264 i=$(($i+1))
2265 read incoming
[747]2266 done
2267 echo "$incoming"
2268}
2269
2270
2271RejigHyperlinks() {
2272 local minidir_root noof_disks fname path diskno old_pwd awk_loc gawk_loc dir i
2273 minidir_root=$1
2274 noof_disks=$2
2275
2276 old_pwd=`pwd`
2277 diskno=1
2278 while [ "$diskno" -le "$noof_disks" ] ; do
[859]2279 mkdir -p $minidir_root/$diskno
[747]2280 cd $minidir_root/$diskno
2281 for fname in `find -type d -o -print` ; do
2282 [ -h "$minidir_root/$diskno/$fname" ] && MoveHyperlinkSensibly $fname $minidir_root $diskno $noof_disks
2283 done
[925]2284 diskno=$(($diskno+1))
[747]2285 done
2286
2287 cd $old_pwd
2288 return
2289}
2290
2291
2292ReplaceIndividualLine() {
2293 local orig_file new_file lino newstring lines_total lines_remaining
[925]2294
[747]2295 orig_file=$1.orig
2296 mv -f $1 $orig_file || Die "Cannot move $1 to $orig_file"
2297 new_file=$1
2298 lino=$2
2299 newstring="$3"
2300 if [ "$lino" = "" ] || [ "$lino" -lt "1" ] ; then
[925]2301 echo "Can't find string" >> $LOGFILE
2302 return 1
[747]2303 fi
[963]2304 lines_total=`wc -l $orig_file | $AWK '{print $1;}'`
[747]2305 lines_remaining=$(($lines_total-$lino))
2306 head -n$(($lino-1)) $orig_file > $new_file
2307 echo "$newstring" >> $new_file
2308 echo "# The above line was added by Mindi, at the user's instruction" >> $new_file
2309 tail -n$lines_remaining $orig_file >> $new_file
2310 echo "Replace line $lino of $new_file with user-specified line, '$newstring'" >> $LOGFILE
2311 [ -x "$orig_file" ] && chmod +x $new_file
2312 rm -f $orig_file
2313 return 0
2314}
2315
2316
2317ScanCDandTape() {
2318 local i
2319
2320 for i in /dev/st0 /dev/ht0 /dev/cdrom /dev/cdrom0 /dev/cdrom 1 ; do
2321 dd if=$i of=/dev/null bs=64k count=1 &> /dev/null
2322 done
2323}
2324
2325
2326SizeOfPartition() {
2327 local devpath drive res stub
2328 device=$1
2329 if [ "`echo "$device" | grep -F "/dev/md"`" != "" ] ; then
[925]2330 res=`SizeOfRaidPartition $device`
2331 [ "$res" = "" ] && Die "Cannot find $device's size - is your /etc/raidtab sane?"
2332 echo "$res"
2333 return 0
[747]2334 fi
[925]2335 # patch from Bill <bill@iwizard.biz> - 2003/08/25
[960]2336 res=`$FDISK -s $device 2>> $LOGFILE`
[925]2337 # end patch
[747]2338 [ "$res" = "" ] && res=`df -k -P -x supermount | tr -s '\t' ' ' | grep -F "$device " | cut -d' ' -f2`
2339 [ "$res" = "" ] && res="-1"
2340 echo $res
2341 return 0
2342}
2343
2344
2345SizeOfRaidPartition() {
2346 local real_dev smallest_size silly tmp
2347
2348 silly=999999999
2349 smallest_size=$silly
2350
2351 for real_dev in `GetRaidDevMembers $1` ; do
[925]2352 tmp=`SizeOfPartition $real_dev`
2353 [ "$tmp" -lt "$smallest_size" ] && smallest_size=$tmp
[747]2354 done
2355
2356 if [ "$smallest_size" = "$silly" ] ; then
[925]2357 echo "-1"
2358 return 1
[747]2359 else
[925]2360 echo "$smallest_size"
2361 return 0
[747]2362 fi
2363}
2364
2365
2366StripComments()
2367{
2368 local tempfile
[925]2369
[940]2370 tempfile=$MINDI_TMP/$$.strip.txt
[963]2371 cp -f $1 $tempfile 2>> $LOGFILE
[747]2372 $AWK '{if (substr($0,0,1)!="#" || substr($0,0,3)=="#!/") {print $0;};}' $tempfile > $1
2373 rm -f $tempfile
2374 echo "Stripped comments from $2" >> $LOGFILE
2375}
2376
2377
2378SplitDirectoryIntoMinidirs() {
2379 local bigdir minidir_root i noof_disks old_pwd res
[925]2380
[747]2381 bigdir=$1
2382 minidir_root=$2
[1087]2383 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/*
[747]2384
2385 TryToFitDataIntoSeveralDirs $bigdir $minidir_root
2386 noof_disks=$?
2387 if [ "$noof_disks" -eq "0" ] ; then
[925]2388 echo "Failed to fit data into several dirs."
[747]2389 return 0
2390 fi
2391 RejigHyperlinks $minidir_root $noof_disks
[1087]2392 [ "$bigdir" != "" ] && rm -Rf $bigdir/*
[925]2393 return $noof_disks
[747]2394}
2395
2396
2397StripExecutable()
2398{
2399 local tmpfile
[925]2400
[940]2401 tmpfile=$MINDI_TMP/stripped.$$.dat
[747]2402 [ -d "$1" ] || [ -h "$1" ] && return
[963]2403 cp -f $1 $tmpfile 2>> $LOGFILE
[747]2404 strip $tmpfile 2> /dev/null
2405 if [ "$?" -eq "0" ] ; then
[963]2406 cp -f $tmpfile $1 2>> $LOGFILE
[925]2407 echo "Stripped binary $2" >> $LOGFILE
[747]2408 fi
2409 rm -f $tmpfile
2410}
2411
2412
2413TemporarilyCompressAllFiles() {
2414 local i orig_fname out_fname out_list
2415
2416 i=0
2417 out_list=$2/compressed/compressed.txt
2418 mkdir -p $2/compressed
2419 > $out_list
2420 for orig_fname in $1 ; do
2421 out_fname=$2/compressed/$orig_fname.gz
2422 mkdir -p $out_fname 2> /dev/null
2423 rmdir $out_fname 2> /dev/null
2424 gzip -c6 $orig_fname > $out_fname 2> /dev/null
2425 i=$(((($i+1))%15))
2426 [ "$i" -eq "0" ] && echo -en "."
2427 du -sk $out_fname >> $out_list
2428 done
2429}
2430
2431
2432TryToFindKernelPath() {
2433 local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
[925]2434
[747]2435 we_want_version=`uname -r`
2436 possible_kernels=""
2437 duff_kernels=""
2438
2439 if [ "$ARCH" = "ia64" ] ; then
2440 root="/boot/efi/efi"
2441 else
2442 root="/"
2443 fi
[1685]2444 for fname in `find $root -maxdepth 2 -type f | grep -E 'lin|kern' | grep -Ev '^/proc/|^/net/'` ; do
[925]2445 [ ! -e "$fname" ] && continue
[747]2446 [ "$fname" = "/boot/vmlinuz.shipped" ] && [ -f "/boot/vmlinuz" ] && continue; # ignore SuSE's extra kernel
[925]2447 file $fname | grep -q gzip
2448 if [ "$?" -eq "0" ] ; then
2449 # Used by ia64
[747]2450 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[925]2451 else
[747]2452 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
[925]2453 fi
[747]2454 [ "$fkern_ver" = "" ] && continue
2455 [ "`echo "$fkern_ver" |grep -F "$we_want_version "`" = "" ] && continue
[925]2456 [ -f "$fname" ] || continue
2457 [ -h "$fname" ] && continue
2458 kdate=`uname -v | $AWK '{for(i=1;i<NF;i++){if(index($i,":")){print $i;};};}' | $AWK '{print $NF;}'`
2459 file $fname | grep -q gzip
2460 if [ "$?" -eq "0" ] ; then
2461 # Used by ia64
2462 if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[963]2463 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
[925]2464 duff_kernels="$fname $duff_kernels"
2465 else
[747]2466 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2467 possible_kernels="$fname $possible_kernels"
[925]2468 fi
[747]2469 else
[925]2470 if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
[963]2471 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
[925]2472 duff_kernels="$fname $duff_kernels"
2473 else
[747]2474 [ "`echo "$fname" | grep -F "vmlinux"`" ] && continue
2475 possible_kernels="$fname $possible_kernels"
[925]2476 fi
[747]2477 fi
2478 done
2479 if [ ! "$possible_kernels" ] && uname -a | grep Knoppix > /dev/null ; then
[925]2480 possible_kernels=`find /boot/vmlinuz-2.* | tail -n1`
[747]2481 fi
2482 if [ ! "$possible_kernels" ] ; then
[963]2483 LogIt "No kernel matches exactly. Are there any duff kernels?"
[747]2484 possible_kernels="$duff_kernels"
2485 if [ ! "$possible_kernels" ] ; then
[963]2486 LogIt "Sorry, no duff kernels either"
[747]2487 else
[963]2488 LogIt "I bet you're running Debian or Gentoo, aren't you?"
2489 LogIt "Your kernel doesn't have a sane builddate. Oh well..."
[747]2490 fi
2491 fi
2492 possible_kernels=`echo "$possible_kernels" | tr -s ' ' '\n' | sort -u | tr '\n' ' '`
2493 noof_kernels=`CountItemsIn "$possible_kernels"`
2494 if [ "$noof_kernels" -eq "0" ] ; then
[963]2495 LogIt "Could not find your kernel."
[925]2496 if [ -e "/boot/vmlinuz" ] ; then
[963]2497 LogIt "Using /boot/vmlinuz as a last resort."
[925]2498 output=/boot/vmlinuz
[747]2499 else
[925]2500 output=""
2501 fi
[747]2502 elif [ "$noof_kernels" -eq "1" ] ; then
2503 kernelpath=`echo "$possible_kernels" | sed s/' '//`
2504 echo "Your kernel is $kernelpath (v`uname -r`)" >> $LOGFILE
2505 output="$kernelpath"
2506 else
2507 for i in $possible_kernels ; do
2508 if echo $i | grep "`uname -r`" ; then
[925]2509 LogIt "OK, I used my initiative and found that "
[963]2510 LogIt "$i is probably your kernel. "
[925]2511 output="$i"
2512 return
2513 fi
[747]2514 done
[925]2515 if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
2516 output=/boot/vmlinuz
2517 echo "Schlomo, this one's for you." >> $LOGFILE
2518 else
[963]2519 LogIt "Two or more possible kernels found. You may specify any one of them and the "
2520 LogIt "boot disks will still work, probably. If one does not work, try another."
2521 LogIt "$possible_kernels"
[747]2522 echo ""
[925]2523 fi
[747]2524 fi
2525 echo "$output" | tr -s ' ' '\n' | sort -u | tr '\n' ' '
2526}
2527
2528
2529TryToFitDataIntoSeveralDirs() {
2530 local bigdir minidir_root noof_disks diskno list_of_files filename old_pwd progress
2531 local i retval noof_disks total_files list_of_devs
[925]2532
[747]2533 bigdir=$1
2534 minidir_root=$2
2535 BIG_CLUNKY_SIZE_COUNTER=0
2536 retval=0
2537 noof_disks=1
2538
2539 echo -en "\r \rDividing data into several groups..."
2540 old_pwd=`pwd`
2541 cd $bigdir
2542 list_of_files=`GetFileSizeList . | sort -nr | cut -f2 | grep -Fv "/dev/"`
2543 progress=0
2544 total_files=`CountItemsIn "$list_of_files"`
2545 if [ "`echo "$filename" | grep -x "/dev/.*"`" ] ; then
2546 filesize=1
2547 fi
2548 mkdir -p $minidir_root/$noof_disks
2549 if [ -e "dev" ] ; then
2550 echo "Copying dev/* to $minidir_root/$noof_disks" >> $LOGFILE
[963]2551 cp --parents -pRdf dev $minidir_root/$noof_disks 2>> $LOGFILE
[747]2552 fi
2553 TemporarilyCompressAllFiles "$list_of_files" $minidir_root
2554 for filename in $list_of_files ; do
2555 AddFileToDir $filename $minidir_root $noof_disks
[925]2556 i=$?
2557 if [ "$i" -gt "$noof_disks" ] ; then
2558 noof_disks=$i
2559 echo -en "\r\t\t\t\t\t\t($noof_disks disks)"
2560 fi
2561 if [ "$i" -eq "0" ] ; then
[963]2562 LogIt "Cannot add file $filename to minidir $minidir_root"
[925]2563 retval=$(($retval+1))
2564 fi
[747]2565 progress=$(($progress+1))
[925]2566 echo -en "\r\t\t\t\t\t\t\t\t$(($progress*100/$total_files))% complete\r"
[747]2567 done
2568 cd $old_pwd
2569 echo -en "\rThe files have been subdivided into $noof_disks directories. \r"
[1087]2570 [ "$minidir_root" != "" ] && rm -Rf $minidir_root/compressed
[747]2571 if [ "$retval" -gt "0" ] ; then
[925]2572 return 0
[747]2573 else
[925]2574 return $noof_disks
[747]2575 fi
2576}
2577
2578
2579TurnTgzIntoRdz() {
[1573]2580 local tgz_dir_fname rdz_fname ramdisksize tempfile mountpoint old_pwd nodes kernelsize maxsize res currsize not_copied j k s w
[925]2581
[747]2582 tgz_dir_fname=$1
2583 rdz_fname=$2
2584 ramdisksize=$3
[1573]2585 kernelsize=$4
2586 maxsize=$(($BOOT_SIZE-$kernelsize))
[747]2587 maxsize=$(($maxsize*2)); # to allow for compression of 50%
[940]2588 tempfile=$MINDI_TMP/temp.rd
2589 mountpoint=$MINDI_TMP/mnt1
[747]2590 res=0
2591 echo -en "..."
2592 dd if=/dev/zero of=$tempfile bs=1k count=$ramdisk_size &> /dev/null || Die "Not enough room for temporary ramdisk (TurnTgzIntoRdz)"
2593 echo -en "..."
[1075]2594 echo "Creating ext2 filesystem on $tempfile" >> $LOGFILE
[1770]2595 mke2fs -b 1024 -m 1 -i 2048 -F $tempfile >> $LOGFILE 2>> $LOGFILE || Die "Unable to create an ext2 file system on $tempfile"
[747]2596 echo -en "..."
2597 mkdir -p $mountpoint
2598 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."
2599 echo -en "..."
2600 old_pwd=`pwd`
2601 cd $mountpoint
[959]2602 cp -Rdf $tgz_dir_fname/* . 2>&1 >> $LOGFILE
[747]2603 tar -zxf symlinks.tgz || Die "Cannot untar symlinks.tgz"
2604 cd dev || Die "Can't cd to dev"
2605 tar -zxf dev-entries.tgz || Die "Cannot untar dev-entries.tgz"
2606 rm -f dev-entries.tgz
2607 cd ..
2608
2609 for w in insmod.static insmod.static.old ; do
[925]2610 s=`which $w 2> /dev/null`
2611 if [ -e "$s" ] ; then
[963]2612 cp --parents -af $s . 2>> $LOGFILE
[925]2613 fi
[747]2614 done
2615
2616 mkdir -p tmp
2617 [ -e "/dev/.devfsd" ] && echo "/dev/.devfsd found" > tmp/USE-DEVFS
[1770]2618
[1842]2619 # Handle the case where busybox is dynamically linked
2620 # Should be done first so that if /lib64 is a link, it's
2621 # created first like that, instead of as a real dir later on
2622 file $MINDI_LIB/rootfs/bin/busybox 2>&1 | grep -q "dynamically"
2623 if [ $? -eq 0 ]; then
2624 LocateDeps $MINDI_LIB/rootfs/bin/busybox > $MINDI_TMP/busy.lis
2625 cp --parents -Rdf `sort -u $MINDI_TMP/busy.lis` .
2626 rm -f $MINDI_TMP/busy.lis
2627 fi
2628
[1770]2629 # Management of udev (which includes modprobe in rules)
2630 ps auxww | grep -v grep | grep -qw udevd
2631 if [ $? -eq 0 ]; then
2632 echo "udev device manager found" > tmp/USE-UDEV
2633 LogIt "udev device manager found"
2634 cp --parents -Rdf /etc/udev . 2> /dev/null
[1842]2635 # This avoids NIC remapping if on another machine at restore time on Debian at least
2636 rm -f ./etc/udev/rules.d/z25_persistent-net.rules
[1770]2637 cp --parents -Rdf /lib/udev /lib64/udev . 2> /dev/null
2638 if [ -x /sbin/udevd ]; then
[1842]2639 lis2=`grep -Ev '^#' $MINDI_CONF/udev.files`
2640 lis=""
2641 # Get only the files which exist in that list
2642 # and potentially their symlink structure
2643 for i in $lis2; do
2644 if [ -h $i ]; then
2645 j=$i
2646 while [ -h $j ]; do
2647 lis="$lis $j"
2648 j=`readlink $j`
2649 done
2650 lis="$lis $j"
2651 elif [ -f $i ]; then
2652 lis="$lis $i"
2653 fi
2654 done
2655 # And their deps
[1770]2656 LocateDeps $lis > $MINDI_TMP/udev.lis
2657 for i in $lis; do
2658 if [ "`echo $i | cut -c1`" = "/" ]; then
2659 j=`echo $i | cut -c2-`
2660 rm -f $j
2661 fi
2662 done
2663 cp --parents -Rdf $lis `sort -u $MINDI_TMP/udev.lis` .
2664 rm -f $MINDI_TMP/udev.lis
2665 else
2666 echo "udevd daemon not in standard place (/sbin)" 2>&1 | tee -a $LOGFILE
2667 echo "mindi will use static devices which may cause problems" 2>&1 | tee -a $LOGFILE
2668 rm -f tmp/USE-UDEV
2669 fi
2670 fi
[1842]2671
[1770]2672 # Management of potential HW info (Proliant only at the moment)
[1842]2673 rm -rf $MINDI_CACHE/bkphw
[1770]2674 mindi-bkphw $MINDI_CACHE $MINDI_CONF | tee -a $LOGFILE
2675 if [ -d $MINDI_CACHE/bkphw ]; then
2676 LogIt "Hardware Information found and saved ..."
2677 cp -rp $MINDI_CACHE/bkphw .
2678 lis=`grep -Ev '^#' $MINDI_CACHE/tools.files`
2679 LocateDeps $lis > $MINDI_TMP/tools.lis
2680 cp --parents -Rdf $lis `sort -u $MINDI_TMP/tools.lis` .
2681 if [ -f $MINDI_CACHE/mindi-rsthw ]; then
2682 mv -f $MINDI_CACHE/mindi-rsthw .
2683 chmod 755 ./mindi-rsthw
2684 fi
2685 rm -f $MINDI_TMP/tools.lis $MINDI_CACHE/tools.files
2686 fi
2687
[747]2688 for w in cdrom floppy groovy-stuff ; do
2689 mkdir -p mnt/$w
2690 done
[925]2691 #if [ "$RUN_AFTER_INITIAL_BOOT_PHASE" ] ; then
2692 #ReplaceIndividualLine sbin/init `grep -n "#WHOLIVESINAPINEAPPLEUNDERTHESEA#" sbin/init | cut -d':' -f1` "$RUN_AFTER_INITIAL_BOOT_PHASE"
2693 #fi
[747]2694 if [ "$RUN_AFTER_BOOT_PHASE_COMPLETE" ] ; then
[925]2695 ReplaceIndividualLine sbin/init `grep -n "#ABSORBENTANDYELLOWANDPOROUSISHE#" sbin/init | cut -d':' -f1` "$RUN_AFTER_BOOT_PHASE_COMPLETE"
[747]2696 fi
2697
2698 cp --parents -Rdf /dev/fd0*[1,2][4,7,8]* . 2> /dev/null
[1770]2699
[747]2700 cd $old_pwd
2701 echo -en "..."
2702 MakeModuleLoadingScript $TMPMODPROBE_FLAG $mountpoint/sbin/insert-all-my-modules
2703 echo -en "..."
2704 old_pwd=`pwd`
2705 if [ "$YOUR_KERNEL_SUCKS" ] ; then
[940]2706 cd $MINDI_TMP
[1573]2707 needed_modules_path=lib/modules/$FAILSAFE_KVER
[747]2708 else
2709 cd /
2710 if [ "${kernelname}" != "" ]
2711 then
[1573]2712 needed_modules_path=lib/modules/${kernelname}
[747]2713 else
[1573]2714 needed_modules_path=lib/modules/`uname -r`
[747]2715 fi
2716 fi
[1573]2717
2718 needed_modules=""
2719 list_of_groovy_mods="$CDROM_MODS $FORCE_MODS `WhichOfTheseModulesAreLoaded "$SCSI_MODS"`"
[1087]2720 if [ "$NFS_DEV" != "" ] ; then
[747]2721 # For PXE boot
2722 list_of_groovy_mods="$list_of_groovy_mods $NET_MODS"
2723 fi
[1770]2724 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
2725 list_of_groovy_mods="$list_of_groovy_mods $EXTRA_MODS"
2726 fi
2727 for i in $DENY_MODS; do
2728 echo "Removing $i from the list of modules to load" >> $LOGFILE
2729 list_of_groovy_mods=`echo ${list_of_groovy_mods} | tr ' ' '\n' | grep -Ev "^${i}$" | tr '\n' ' '`
2730 done
2731
2732 [ -e "$floppy_modules_path" ] || LogIt "path $floppy_modules_path does not exist.\n If you're not using a modular kernel then you're NUTS."
[747]2733 for i in $list_of_groovy_mods ; do
[1573]2734 needed_modules="$needed_modules `FindSpecificModuleInPath $needed_modules_path $i`"
[747]2735 done
[1573]2736 for i in $needed_modules ; do
[747]2737 [ -e "$i" ] && s=`du -sk $i | cut -f1` || s=""
[940]2738 [ "$YOUR_KERNEL_SUCKS" ] && i=$MINDI_TMP/$i
[747]2739 echo "Adding $i ($s KB) to the rootfs" >> $LOGFILE
[1770]2740 cp --parents -pdf $i $mountpoint 2>/dev/null || LogIt "Unable to copy $i to $mountpoint"
[1842]2741 # Uncompress modules if not useing udev and native modprobe
2742 if [ ! -f $mountpoint/tmp/USE-UDEV ]; then
2743 if [ "`echo "$i" | grep -F ".gz"`" ]; then
[1770]2744 gunzip -f $mountpoint/$i
[1842]2745 #i=`echo $i | sed 's/.gz//'`
2746 fi
[1770]2747 fi
[1842]2748 done
2749
2750 # Also copy modules.dep in case of udev so that normal modprobe works
2751 cp --parents -pdf /$floppy_modules_path/modules.dep $mountpoint 2>/dev/null || LogIt "Unable to copy modules.dep to $mountpoint"
2752
2753 # For all modules supported, create symlinks under the mountpoint
2754 for i in $EXTRA_MODS $NET_MODS $SCSI_MODS; do
2755 all_modules="$all_modules `FindSpecificModuleInPath $mountpoint $i | sed 's~^$mountpoint/~~g'`"
2756 done
2757 for i in $all_modules; do
[1770]2758 (cd $mountpoint ; ln -s $i . 2>/dev/null)
[747]2759 done
[1573]2760 if [ ! -e "/sbin/devfsd" ] || [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] ; then
[747]2761 echo "Deleting devfsd daemon from ramdisk" >> $LOGFILE
2762 [ ! -e "/sbin/devfsd" ] && echo "...because /sbin/devfsd not found" >> $LOGFILE
2763 [ "$kernelpath" = "$MINDI_LIB/vmlinuz" ] && echo "...because kernel is failsafe" >> $LOGFILE
2764 rm -f $mountpoint/sbin/devfsd
2765 fi
2766 cd $old_pwd
[1087]2767 [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && echo -en "$TAPEDEV" > $mountpoint/tmp/TAPEDEV-LIVES-HERE
[747]2768 dd if=/dev/zero of=$mountpoint/zero &> /dev/null
2769 rm -f $mountpoint/zero
[1087]2770 mkdir -p $mountpoint/tmp
[1063]2771 if [ _"$MONDO_SHARE" != _"" ]; then
[1087]2772 cp -f $MONDO_CACHE/mondo-restore.cfg $mountpoint/tmp &> /dev/null || Die "Cannot copy mondo-restore.cfg to ramdisk"
[953]2773 cp -f $MINDI_TMP/mountlist.txt $mountpoint/tmp/ 2>/dev/null || Die "Cannot copy mountlist to ramdisk"
[747]2774 fi
2775 mkdir -p $mountpoint/proc
[1573]2776 echo "$BOOT_SIZE" > $mountpoint/tmp/$BOOT_SIZE.siz
[747]2777 find $mountpoint -name CVS -exec rm -rf '{}' \;
[1099]2778 # Determine what filesystem to use for initrd image
[1142]2779 echo "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd." >> $LOGFILE
[1099]2780 gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
2781 [ -z gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
2782 case "$gvFileSystem" in
2783 "ext2fs")
2784 # say what will be used
[1842]2785 echo "Creating an ext2 initrd image..." >> $LOGFILE
[1099]2786 # kernel expects linuxrc in ext2 filesystem
[1142]2787 ( cd $mountpoint && ln -sf sbin/init linuxrc )
[1099]2788 # unmount loop filesystem and create image file using the standard approach
2789 umount $mountpoint || Die "Cannot unmount $tempfile"
[1312]2790 dd if=$tempfile bs=1k 2> /dev/null > ${rdz_fname}.tmp 2> /dev/null
[1842]2791 bs=`tune2fs -l ${rdz_fname}.tmp | grep -E '^Block size:' | cut -d: -f2 | sed 's/^ *//'`
[1312]2792 ADDITIONAL_BOOT_PARAMS="$ADDITIONAL_BOOT_PARAMS ramdisk_blocksize=$bs"
[1842]2793 gzip -c9 ${rdz_fname}.tmp > $rdz_fname
[1312]2794 rm -f ${rdz_fname}.tmp
[1099]2795 # log that we are done
[1842]2796 echo "...done." >> $LOGFILE
[1099]2797 ;;
2798 "initramfs")
2799 # say what will be used
[1842]2800 echo "Creating a gzip'ed cpio (AKA initramfs) initrd image..." >> $LOGFILE
[1099]2801 # make sure that cpio is there
2802 which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
2803 # go into filesystem
2804 cd $mountpoint
2805 # kernel expects init in cpio filesystem
[1142]2806 ln -sf sbin/init init
[1099]2807 # create cpio image file and unmount loop filesystem
2808 find . -print | cpio -o -H newc | gzip -9 > $old_pwd/$rdz_fname 2> /dev/null
2809 cd $old_pwd
2810 umount $mountpoint || Die "Cannot unmount $tempfile"
2811 # log that we are done
[1142]2812 echo "...done." >> $LOGFILE
[1099]2813 ;;
2814 *)
2815 Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
2816 ;;
2817 esac
[747]2818 if [ "$res" -eq "0" ] ; then
2819 echo -en "..."
2820 else
2821 echo -en "\rMade an rdz WITH ERRORS. \n"
2822 fi
2823 return 0
2824}
2825
2826
2827WhichOfTheseModulesAreLoaded() {
2828 local modname loaded_modules
[1408]2829 loaded_modules="$MODULES"
[747]2830 for modname in $1 ; do
[1508]2831 [ "`echo "$loaded_modules" | grep -w "$modname"`" ] && echo "$modname"
[747]2832 done
2833}
2834
2835
2836ZipMinidirsIntoTarballs() {
2837 local minidir_root tardir noof_disks diskno old_pwd i
2838 minidir_root=$1
2839 tardir=$2
2840 noof_disks=$3
2841
2842 echo -en "Tarring and zipping the group`PluralOrNot $noof_disks`..."
2843 mkdir -p $tardir
2844 mkdir -p $minidir_root/all
2845 old_pwd=`pwd`
2846 diskno=1
2847 while [ "$diskno" -le "$noof_disks" ] ; do
[963]2848 cd $minidir_root/$diskno || LogIt "WARNING - cannot cd to $minidir_root/$diskno"
[747]2849 tar -cf - . 2>> $LOGFILE | gzip -9 > $tardir/$diskno.tar.gz || Die "Can't tar/gzip disk#$diskno; please tell Dev Team -exactly- what the errors where."
2850 diskno=$(($diskno+1))
2851 echo -n "..."
[963]2852 cp -pRdf * $minidir_root/all 2>> $LOGFILE
[747]2853 done
2854 mkdir -p $minidir_root/all/tmp
2855 cd $minidir_root/all
2856 size_of_all_tools=`du -sk . | cut -f1`
[1063]2857 if [ _"$MONDO_SHARE" != _"" ]; then
[747]2858 for q in filelist.full.gz biggielist.txt ; do
[940]2859 [ ! -e "$MINDI_TMP/$q" ] && Die "Cannot find $MINDI_TMP/$q"
[963]2860 cp -pRdf $MINDI_TMP/$q tmp/ 2>> $LOGFILE
[747]2861 done
2862 mkdir -p $minidir_root/all/tmp
2863 fi
2864 tar -b 4096 -cf - * 2> /dev/null | gzip -9 > $tardir/all.tar.gz
2865 dd if=/dev/zero bs=1k count=64 >> $imagesdir/all.tar.gz 2> /dev/null
2866 [ "`du -sm $imagesdir/all.tar.gz | cut -f1`" -ge "30" ] && Die "You have too many tools in your shed"
2867 cd $old_pwd
[1087]2868 [ "$minidir_root" != "" ] && rm -Rf $minidir_root
[747]2869 echo -e "$DONE"
2870}
2871
2872
2873##############################################################################
[1020]2874#----------------------------------- Main -----------------------------------#
[747]2875##############################################################################
2876
[1087]2877# Now we can create what we nedd
2878mkdir -p $MINDI_TMP
[747]2879
[1087]2880# Purge from potential old run
2881if [ _"$MINDI_CACHE" = _"" ]; then
2882 Die "MINDI_CACHE undefined"
2883fi
[1408]2884rm -rf $MINDI_CACHE/* 2> /dev/null
[1087]2885mkdir -p $MINDI_CACHE
2886
2887
[1063]2888if [ "$1" = "--printvar" ] ; then
[1047]2889 shift
2890 if [ _"$1" != _"" ] ; then
[1535]2891 set | grep -Ew "^$1" | cut -d= -f2
[1047]2892 fi
[1063]2893 MindiExit 0
[1047]2894fi
2895
[747]2896> $LOGFILE
2897echo "mindi v$MINDI_VERSION" >> $LOGFILE
2898echo "$ARCH architecture detected" >> $LOGFILE
2899echo "mindi called with the following arguments:" >> $LOGFILE
2900echo "$@" >> $LOGFILE
[800]2901echo "Start date : `date`" >> $LOGFILE
[1087]2902echo "-----------------------------" >> $LOGFILE
[747]2903
2904if [ -e "/etc/conf.modules" ] && [ ! -e "/etc/modules.conf" ] ; then
[963]2905 LogIt "WARNING - Ancient distro detected." 1
[747]2906 ln -sf /etc/conf.modules /etc/modules.conf
2907fi
2908[ -e "/sbin/mkdosfs" ] && [ ! -e "/sbin/mkfs.vfat" ] && ln -sf /sbin/mkdosfs /sbin/mkfs.vfat
2909
[1010]2910# Log some capital variables
2911[ "$MINDI_PREFIX" = "XXX" ] && Die "Mindi has not been installed correctly."
[1087]2912echo "MONDO_SHARE = $MONDO_SHARE" >> $LOGFILE
[1010]2913echo "MINDI_LIB = $MINDI_LIB" >> $LOGFILE
2914echo "MINDI_SBIN = $MINDI_SBIN" >> $LOGFILE
2915[ "$MINDI_CONF" = "YYY" ] && Die "Mindi has not been installed correctly."
2916echo "MINDI_CONF = $MINDI_CONF" >> $LOGFILE
[1087]2917if [ -f $MINDI_CONF ]; then
2918 echo "-----------------------------" >> $LOGFILE
2919 echo " Mindi configuration file " >> $LOGFILE
2920 echo "-----------------------------" >> $LOGFILE
[1685]2921 grep -Ev '^#' $MINDI_CONF >> $LOGFILE
[1087]2922 echo "-----------------------------" >> $LOGFILE
2923fi
[1010]2924
[1087]2925
[747]2926trap AbortHere SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
[1010]2927
2928# Sanity checks
2929which which > /dev/null 2> /dev/null || Die "Please install 'which'."
2930which strings > /dev/null 2> /dev/null || Die "Please install binutils and libbinutils; you have no 'strings' executable."
2931which 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."
2932which gawk > /dev/null 2> /dev/null && AWK=`which gawk 2>/dev/null` || AWK="`which awk 2>/dev/null`"
2933if which awk &> /dev/null ; then
2934 if ! which gawk &> /dev/null ; then
2935 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"
2936 fi
2937fi
2938which mke2fs > /dev/null 2> /dev/null || Die "Please put mke2fs in system path"
2939[ ! -e "$FDISK" ] && Die "Cannot find (s)fdisk"
2940
[747]2941[ "`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"
2942# If we have a 2.6 kernel, the system uses module-init-tools which means that we
2943# may have the modprobe configuration spread out across multiple files in
2944# directory /etc/modprobe.d. If this is the case we concatenate these files into
2945# a temporary file for further processing. Otherwise we continue in the standard
2946# way. Note further that in case /etc/modprobe.d exists, we use it and ignore
2947# /etc/modprobe.conf which is exactly what module-init-tools does. The temporary
2948# modprobe.conf file is created in MakeModuleLoadingScript. AL041128.
[1347]2949if [ -d "/etc/modprobe.d" ] && [ "`uname -r | cut -c1-3`" = "2.6" ] ; then
[925]2950 TMPMODPROBE_FLAG="Y"
[747]2951else
[925]2952 TMPMODPROBE_FLAG="N"
2953 [ -e "/etc/modprobe.conf" ] && [ ! -e "/etc/modules.conf" ] && ln -sf /etc/modprobe.conf /etc/modules.conf
2954 [ ! -e "/etc/modules.conf" ] && Die "/etc/modules.conf not found; you may have to create a softlink from /etc/conf.modules to /etc/modules.conf; of course, all good distros use modules.conf anyway..."
[747]2955fi
[1010]2956
2957# Update the PATH variable if incomplete
2958if [ -e "/sbin/mkfs" ] && ! which mkfs &> /dev/null ; then
2959 PATH=$PATH:/sbin:/usr/sbin
2960 export PATH
2961 echo "Your PATH did not include /sbin or /usr/sbin. I have fixed that, temporarily." >> $LOGFILE
2962 echo "However, you may wish to ask your vendor to provide a permanent fix..." >> $LOGFILE
2963 echo " Or you might like to call 'su -' instead of 'su', for example." >> $LOGFILE
2964fi
2965
[1062]2966# If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
2967if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ] && [ "$kernelpath" = "FAILSAFE" ]; then
2968 source $MINDI_LIB/FindDistroFailsafe
2969 # Log kernel image
2970 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
2971else
2972 [ -f "$MINDI_LIB/vmlinuz" ] && FAILSAFE_KVER=`strings $MINDI_LIB/vmlinuz 2> /dev/null | grep -E "2\.[46]" | cut -d' ' -f1`
2973fi
[1010]2974
[1770]2975if ! which mkfs.vfat 1> /dev/null 2> /dev/null ; then
[1010]2976 Die "mkfs.vfat missing from your filesystem - please install your dosfstools RPM or DEB package. Perhaps your PATH environmental variable is broken, too?"
2977fi
2978
[925]2979### BERLIOS
[747]2980### Fix as it's not mandatory on ia64
2981if [ "$ARCH" = "ia64" ] ; then
[1010]2982 if which elilo &> /dev/null ; then
2983 LILO_EXE=elilo
2984 else
2985 LILO_EXE=`which false`
2986 fi
[747]2987else
2988 FindIsolinuxBinary
2989 FindLiloBinary
2990fi
2991trap "Aborted" SIGTERM
2992DONE="\r\t\t\t\t\t\t\t\tDone. "
2993CHOPSIZE=240
2994BIGNO=0
[1060]2995MAX_COMPRESSED_SIZE="$mindi_max_compressed_size"
[1087]2996
2997#
2998# Kernel management: Attempt to locate kernel specific module path
2999# if module path is found then use it other wise use uname -r to set it...
3000#
3001#
[1060]3002kernelpath="$mindi_kernel"
3003if [ "$kernelpath" = "NATIVE" ]; then
3004 kernelpath=""
3005fi
[1087]3006if [ "$kernelpath" = "" ]; then
3007 kernelpath=`TryToFindKernelPath`
3008fi
3009kernelname=`echo $kernelpath | cut -d'-' -f2-`
[1097]3010echo "kernelname = $kernelname" >> $LOGFILE
3011echo "kernelpath = $kernelpath" >> $LOGFILE
[1087]3012if [ ! -d "/lib/modules/$kernelname" ] && [ "$kernelpath" != "FAILSAFE" ]
3013then
[1097]3014 echo "Module path for ${kernelpath} not found..." >> $LOGFILE
3015 echo "using running kernel\'s modules." >> $LOGFILE
[1087]3016 kernelname=`uname -r`
[1073]3017else
[1097]3018 echo "Using modules for kernel: ${kernelname}" >> $LOGFILE
[1073]3019fi
[747]3020
3021if [ -d "/proc/lvm" ]; then
3022 # LVM v1
3023 LVMCMD=""
3024 LVM="v1"
3025elif [ -d "/dev/mapper" ]; then
3026 # LVM v2
3027 LVMCMD="lvm"
3028 LVM="v2"
3029else
3030 LVM="false"
3031fi
[1020]3032echo "LVM set to $LVM" >> $LOGFILE
3033echo "----------" >> $LOGFILE
[1124]3034echo "mount result:" >> $LOGFILE
3035echo "-------------" >> $LOGFILE
3036mount >> $LOGFILE
3037echo "-------------" >> $LOGFILE
[1326]3038if [ -e /etc/raidtab ]; then
3039 echo "-------------" >> $LOGFILE
3040 echo "/etc/raidtab content:" >> $LOGFILE
3041 echo "-------------" >> $LOGFILE
3042 cat /etc/raidtab >> $LOGFILE
3043fi
3044echo "-------------" >> $LOGFILE
[1420]3045echo "cat /proc/cmdline:" >> $LOGFILE
3046echo "-------------" >> $LOGFILE
3047cat /proc/cmdline >> $LOGFILE
3048echo "-------------" >> $LOGFILE
[1020]3049echo "lsmod result:" >> $LOGFILE
3050echo "-------------" >> $LOGFILE
3051lsmod >> $LOGFILE
[1408]3052MODULES="`cat /proc/modules | awk '{print $1}'`"
[1530]3053if [ -x /usr/sbin/esxcfg-module ]; then
[1842]3054 echo "-------------" >> $LOGFILE
[1500]3055 echo "VMWare ESX server detected - Enabling dedicated support" >> $LOGFILE
3056 echo "-------------" >> $LOGFILE
3057 echo "VMWare modules" >> $LOGFILE
3058 echo "-------------" >> $LOGFILE
[1530]3059 /usr/sbin/esxcfg-module -l >> $LOGFILE
[1770]3060 MODULES="$MODULES `/usr/sbin/esxcfg-module -l | awk '{print $1}'`"
[1500]3061fi
[1020]3062echo "-------------" >> $LOGFILE
[1842]3063echo "df result:" >> $LOGFILE
3064echo "----------" >> $LOGFILE
3065df -T >> $LOGFILE
3066echo "-------------" >> $LOGFILE
[1060]3067echo "Liste of extra modules is:" >> $LOGFILE
3068echo "$EXTRA_MODS" >> $LOGFILE
3069echo "-------------" >> $LOGFILE
[747]3070
[1770]3071# Compute libata version
[1842]3072laver=`modinfo libata | grep -Ei '^Version:' | cut -d: -f2 | cut -d. -f1 | sed 's/ *//g' 2> /dev/null`
[1770]3073# If libata v2 is used then remove ide-generic as it will perturbate boot
3074if [ "`echo $MODULES | grep libata`" ]; then
3075 if [ "$laver" = "2" ]; then
3076 DENY_MODS="$DENY_MODS ide-generic"
3077 echo "ide-generic removed from module list as your system uses libata v2+" >> $LOGFILE
3078 echo "-------------" >> $LOGFILE
3079 fi
3080fi
[747]3081
3082FLOPPY_WAS_MOUNTED=""
3083for mtpt in /media/floppy /mnt/floppy /floppy ; do
3084 if mount | grep -w $mtpt &> /dev/null ; then
3085 FLOPPY_WAS_MOUNTED="$FLOPPY_WAS_MOUNTED $mtpt"
3086 umount $mtpt
3087 fi
3088done
3089
[1075]3090#
3091# If we have a USB device we need to store info
3092# and remove it from the parameters line
3093#
[747]3094if [ "$#" -ne "0" ] ; then
[1075]3095 if [ "$1" = "--usb" ] ; then
3096 shift
[1087]3097 USBDEVICE=$1
3098 if [ _"$USBDEVICE" = _"" ]; then
[1075]3099 Die "No USB device specified"
3100 fi
3101 shift
3102 fi
3103fi
3104
3105#
[1087]3106# Default value for parameters coming from mondo potentially
3107#
3108if [ "$ARCH" = "ia64" ] ; then
3109 USE_LILO=yes
3110else
3111 USE_LILO=no
3112fi
3113
3114#
3115# These variables are normaly only significant in a mondo environment
3116# Not enforced yet
3117#
3118CDRECOVERY="no"
3119NOT_BOOT="no"
3120EXCLUDE_DEVS=""
3121IMAGE_DEVS=""
3122NFS_DEV=""
3123
3124#
[1075]3125# Deal with parameters
3126#
3127if [ "$#" -ne "0" ] ; then
[747]3128 if [ "$1" = "--findkernel" ] ; then
3129 res=`TryToFindKernelPath`
[1337]3130 # Avoids logfile content for mondo
3131 export MONDO_SHARE=""
[747]3132 if [ "$res" = "" ] ; then
[925]3133 MindiExit -1
[747]3134 else
3135 echo "$res"
[925]3136 MindiExit 0
[747]3137 fi
[1770]3138 elif [ "$1" = "--locatedeps" ] ; then
3139 [ ! "$2" ] && Die "Please specify the binary to look at"
3140 LocateDeps $2
3141 # Avoids logfile content for mondo
3142 export MONDO_SHARE=""
3143 MindiExit $?
[1842]3144 elif [ "$1" = "--readalllink" ] ; then
3145 [ ! "$2" ] && Die "Please specify the binary to look at"
3146 ReadAllLink $2
3147 # Avoids logfile content for mondo
3148 export MONDO_SHARE=""
3149 MindiExit $?
[747]3150 elif [ "$1" = "--makemountlist" ] ; then
3151 [ ! "$2" ] && Die "Please specify the output file"
3152 MakeMountlist $2
[1337]3153 # Avoids logfile content for mondo
3154 export MONDO_SHARE=""
[925]3155 MindiExit $?
3156 elif [ "$1" = "-V" ] || [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "-version" ] ; then
3157 echo "Mindi v$MINDI_VERSION"
[1337]3158 # Avoids logfile content for mondo
3159 export MONDO_SHARE=""
[925]3160 MindiExit 0
[1087]3161 elif [ "$1" = "--custom" ] ; then
[1063]3162 if [ _"$MONDO_SHARE" = _"" ]; then
3163 Die "--custom is reserved for mondoarchive calls"
3164 fi
[940]3165 MONDO_TMP=$2
3166 # Change MINDI_TMP for the one provided by mondo
3167 # So that it can get back the built files
[1010]3168 mv $MINDI_TMP/* $MINDI_TMP/.??* $MONDO_TMP 2> /dev/null
3169 rmdir $MINDI_TMP
[1489]3170 export MINDI_TMP=$MONDO_TMP
[953]3171 mkdir -p $MINDI_TMP
[1770]3172 # This is the scratch dir in mondo - subdir images
[1087]3173 MINDI_CACHE=$3
3174 if [ _"$MINDI_CACHE" != _"" ]; then
3175 mkdir -p $MINDI_CACHE
[938]3176 fi
[1087]3177
3178 if [ ! -e "$MONDORESTORECFG" ]; then
3179 Die "MONDORESTORECFG undefined. Use an uptodate mondoarchive version"
[1075]3180 fi
[1087]3181
3182 if [ ! -e "$MONDO_CACHE" ]; then
3183 Die "MONDO_CACHE undefined. Use an uptodate mondoarchive version"
[747]3184 else
[1087]3185 #
3186 # Get from mondo our additional configuration
3187 #
3188 echo "Using $MONDO_CACHE/mindi.conf as additional config file"
3189 if [ -f $MONDO_CACHE/mindi.conf ]; then
3190 . $MONDO_CACHE/mindi.conf
3191 echo "-----------------------------" >> $LOGFILE
3192 echo " Mondo configuration file " >> $LOGFILE
3193 echo "-----------------------------" >> $LOGFILE
3194 cat $MONDO_CACHE/mindi.conf >> $LOGFILE
3195 echo "-----------------------------" >> $LOGFILE
3196 else
3197 Die "No mindi.conf file created by mondo. Aborting"
3198 fi
[747]3199 fi
[1087]3200
[1143]3201 echo "Here is your $MONDORESTORECFG file:" >> $LOGFILE
[1087]3202 echo "------------------------------------" >> $LOGFILE
3203 cat $MONDORESTORECFG >> $LOGFILE
3204 echo "-----------------------------------" >> $LOGFILE
3205
[1158]3206 CDRECOVERY=`grep use-cdrecovery $MONDORESTORECFG | cut -d'=' -f2`
3207 NOT_BOOT=`grep non-bootable $MONDORESTORECFG | cut -d'=' -f2`
3208 USE_LILO=`grep use-lilo $MONDORESTORECFG | cut -d'=' -f2`
3209 EXCLUDE_DEVS=`grep excluded-devs $MONDORESTORECFG | cut -d'=' -f2`
3210 NFS_DEV=`grep nfs-dev $MONDORESTORECFG | cut -d'=' -f2`
3211 VALUE=`grep image-devs $MONDORESTORECFG | cut -d'=' -f2`
[1087]3212 if [ "$VALUE" = "(null)" ] || [ "$VALUE" = "" ] ; then
[747]3213 IMAGE_DEVS=""
3214 else
[1087]3215 IMAGE_DEVS="`echo "$VALUE" | tr '|' ' '`"
[747]3216 fi
[1087]3217 [ "$CDRECOVERY" = "yes" ] && [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] && Die "Sorry, you can't use --cd-recovery and --write-tapes at the same time"
[1770]3218 # MONDO_ROOT is the real scratchdir
[1087]3219 MONDO_ROOT=`echo $MINDI_CACHE | sed 's/\(.*\)\/.*/\1/'`
[938]3220 if [ _"$MONDO_ROOT" != _"" ]; then
3221 mkdir -p $MONDO_ROOT
3222 else
3223 Die "MONDO_ROOT is undefined"
3224 fi
[747]3225 else
[925]3226 echo "Syntax: mindi (--custom ....)" >> /dev/stderr
3227 MindiExit -1
[747]3228 fi
3229fi
3230#ScanCDandTape
3231[ "$CDRECOVERY" = "yes" ] || CDRECOVERY=no
3232if [ "$CDRECOVERY" = "yes" ] ; then
3233 iso_cfg_file=$MINDI_LIB/isolinux-H.cfg
3234 sys_cfg_file=$MINDI_LIB/syslinux-H.cfg
3235else
3236 iso_cfg_file=$MINDI_LIB/isolinux.cfg
3237 sys_cfg_file=$MINDI_LIB/syslinux.cfg
3238fi
3239
3240[ -e "$iso_cfg_file" ] || Die "Cannot find $iso_cfg_file"
[1063]3241if [ _"$MONDO_SHARE" = _"" ]; then
[963]3242 LogIt "Mindi Linux mini-distro generator v$MINDI_VERSION"
3243 LogIt "Latest Mindi is available from http://www.mondorescue.org"
3244 LogIt "BusyBox sources are available from http://www.busybox.net"
[1685]3245 LogIt "------------------------------------------------------------------------------"
[747]3246else
[1326]3247 echo "You are using Mindi-Linux v$MINDI_VERSION to make boot+data disks" >> $LOGFILE
[747]3248fi
[1005]3249if [ -f $MINDI_LIB/rootfs/bin/busybox ]; then
3250 LogIt "Mindi-`$MINDI_LIB/rootfs/bin/busybox 2>&1 | head -1`"
3251else
3252 LogIt "Unable to find mindi-busybox, please install it"
3253 MindiExit -1
3254fi
[747]3255
3256# for Mandrake 9.2, which comes with two aes.o.gz modules :-/
3257insmod /lib/modules/`uname -r`/*/*/misc/aes.*o.gz >> $LOGFILE 2>> $LOGFILE
3258for i in loop cdrom ide-cd isofs linear raid0 raid1 raid5 ; do
3259 insmod $i >> $LOGFILE 2>> $LOGFILE
3260done
3261
3262KERN_DISK_MADE=""
3263
[1087]3264if [ "$NOT_BOOT" = "yes" ]; then
3265 LogIt "Just creating a small all.tar.gz for Mondo. Nothing else."
[940]3266 mkdir -p $MINDI_TMP/small-all/tmp
[1087]3267 MakeMountlist $MINDI_TMP/small-all/tmp/mountlist.txt
3268 cp -f $MINDI_TMP/{filelist.full.gz,biggielist.txt} $MONDO_CACHE/mondo-restore.cfg $MINDI_CACHE/small-all/tmp 2>/dev/null || Die "Cannot copy small all.tar.gz"
[940]3269 cd $MINDI_TMP/small-all
[1087]3270 tar -cv tmp | gzip -9 > $MINDI_CACHE/all.tar.gz || Die "Cannot make small all.tar.gz"
3271 sync
[963]3272 LogIt "Done. Exiting."
[925]3273 MindiExit 0
[747]3274fi
3275
[1693]3276if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1087]3277 LogIt "Including the generation of a Bootable USB device on $USBDEVICE"
[1075]3278fi
[1685]3279
[747]3280if [ "$kernelpath" = "" ] ; then
[1063]3281 if [ _"$MONDO_SHARE" != _"" ]; then
3282 Die "Please use -k <path> to specify kernel."
[1842]3283 else
3284 USE_OWN_KERNEL="no"
[747]3285 fi
[1347]3286 if [ "$INTERACTIVE" = "yes" ]; then
[1063]3287 echo -en "Do you want to use your own kernel to build the boot disk ([y]/n) ?"
3288 read ch
3289 if [ "$ch" != "n" ] && [ "$ch" != "N" ] ; then
3290 USE_OWN_KERNEL="yes"
3291 fi
3292 fi
[747]3293 if [ "$USE_OWN_KERNEL" = "yes" ]; then
[925]3294 YOUR_KERNEL_SUCKS=""
3295 kernelpath=`TryToFindKernelPath`
3296 if [ "$kernelpath" = "" ] ; then
3297 echo -n "Please enter kernel path : "
3298 read kernelpath
3299 fi
[747]3300 else
[925]3301 YOUR_KERNEL_SUCKS="That's why you're using mine, dude. :-)"
[747]3302 fi
3303fi
[1347]3304if [ _"$MONDO_SHARE" = _"" ] && [ "$INTERACTIVE" = "yes" ] && [ "$ARCH" != "ia64" ] ; then
[1581]3305 echo -en "Would you like to use LILO (instead of syslinux)\nfor your boot image (y/[n]) ?"
[747]3306 read ch
[1060]3307 if [ "$ch" = "y" ] || [ "$ch" = "Y" ] ; then
[747]3308 USE_LILO=yes
3309 fi
3310fi
3311if [ "$YOUR_KERNEL_SUCKS" != "" ] || [ "$kernelpath" = "" ] || [ "$kernelpath" = "SUCKS" ] || [ "$kernelpath" = "FAILSAFE" ] ; then
[1062]3312 # If we have a distribution-specific script for finding a FAILSAFE kernel, use it.
3313 if [ -f "$MINDI_LIB/FindDistroFailsafe" ] && [ ! "$1" = "--makemountlist" ]; then
3314 source $MINDI_LIB/FindDistroFailsafe
3315 # Log kernel image
3316 LogIt "FAILSAFE kernel image to be used is: $FAILSAFE_KBIN ($FAILSAFE_KVER)"
3317 kernelpath="$FAILSAFE_KBIN"
3318 LogIt "I shall include a failsafe kernel, not your kernel, in the boot disks.\n"
3319 LogIt "The failsafe kernel is $kernelpath.\n"
3320 LogIt "However, you are still running your kernel. If Mindi fails to create your\n"
3321 LogIt "disks then it may still be a result of a problem with your kernel.\n"
3322 pwd=`pwd`
[1163]3323 cd $MINDI_TMP
[1062]3324 mkdir -p lib/modules
3325 cp -a "/lib/modules/$FAILSAFE_KVER" "lib/modules/$FAILSAFE_KVER" || Die "Cannot copy kernel modules."
3326 cd $pwd
3327 else
3328 kernelpath=$MINDI_LIB/vmlinuz
3329 LogIt "I shall include Mindi's failsafe kernel, not your kernel, in the boot disks."
3330 LogIt "However, you are still running your kernel. If Mindi fails to create your"
3331 LogIt "disks then it may still be a result of a problem with your kernel."
3332 pwd=`pwd`
3333 cd $MINDI_TMP
3334 bzip2 -dc $MINDI_LIB/lib.tar.bz2 | tar -x || Die "Cannot unzip lib.tar.bz2"
3335 cd $pwd
3336 fi
[747]3337 YOUR_KERNEL_SUCKS="Your kernel sucks"
3338fi
[1087]3339echo -e "Mindi's temp dir = $MINDI_TMP \nMindi's output dir=$MINDI_CACHE" >> $LOGFILE
[963]3340[ "$(($RANDOM%64))" -eq "0" ] && LogIt "Dude, I've looked inside your computer and it's really dusty..."
[747]3341
[965]3342[ "$YOUR_KERNEL_SUCKS" ] && [ ! "$FAILSAFE_KVER" ] && Die "Please install mindi-kernel package. You need it.\nGo to http://www.mondorescue.org and download it, then install it."
[747]3343
[1087]3344PrepareDataDiskImages $MINDI_CACHE
[747]3345noof_disks=$?
3346ramdisk_size=$(($size_of_all_tools+$EXTRA_SPACE))
3347rds=$(($ramdisk_size-$((ramdisk_size%4096))))
3348ramdisk_size=$rds
3349
3350echo "Ramdisk will be $ramdisk_size KB" >> $LOGFILE
[1570]3351if [ "$ARCH" = "ia64" ] ; then
[1573]3352 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create ia64 image disk image."
[1570]3353else
3354 if [ "$USE_LILO" = "yes" ] ; then
[1573]3355 PrepareBootDiskImage_LILO $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
[747]3356 else
[1573]3357 PrepareBootDiskImage_SYSLINUX $MINDI_CACHE $kernelpath $ramdisk_size || Die "Failed to create $BOOT_SIZE MB disk image."
[747]3358 fi
3359fi
3360
3361[ -e "$MINDI_LIB/memtest.img" ] && BOOT_MEDIA_MESSAGE="$BOOT_MEDIA_MESSAGE\n\
3362...Or type 'memtest' to test your PC's RAM thoroughly.\n"
3363
[1063]3364if [ _"$MONDO_SHARE" = _"" ]; then
[1087]3365 ListImagesForUser $MINDI_CACHE
3366 OfferToMakeBootableISO $MINDI_CACHE
3367 if [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ]; then
3368 OfferToMakeBootableUSB $MINDI_CACHE
[1063]3369 fi
[963]3370 LogIt "Finished."
[1087]3371elif [ "$PROMPT_MAKE_TAPE_IMAGE" = "yes" ] ; then
3372 rm -f $MINDI_CACHE/{*img,*gz,*iso}
3373 OfferToMakeBootableISO $MINDI_CACHE
3374 if [ -e "$MINDI_CACHE/all.tar.gz" ] ; then
3375 cp -f $MINDI_CACHE/all.tar.gz $MINDI_TMP/ 2>> $LOGFILE
[747]3376 else
[925]3377 Die "Cannot find all.tar.gz, to be written to tape"
[747]3378 fi
[1770]3379elif [ "$PROMPT_MAKE_USB_IMAGE" = "yes" ] && [ "$USBDEVICE" != "" ]; then
[1087]3380 OfferToMakeBootableUSB $MINDI_CACHE
[747]3381else
[1087]3382 OfferToMakeBootableISO $MINDI_CACHE
[747]3383fi
3384# cleanup
[963]3385LogIt "$FRIENDLY_OUTSTRING"
[747]3386for mtpt in $FLOPPY_WAS_MOUNTED ; do
3387 mount $mtpt
3388done
[925]3389MindiExit 0
Note: See TracBrowser for help on using the repository browser.