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