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