如何恢复 VMware 映像的 vmx 文件?

如何恢复 VMware 映像的 vmx 文件?

我在 VMware 映像运行时意外地删除了一个 vmx 文件。

我怎样才能恢复它?

答案1

坏消息:我想您必须重新创建它。

好消息:VMDK 拥有整个磁盘 - 因此大多数“重要”的内容都在其中。

因此,创建一个新的虚拟机 - 然后配置磁盘以使用现存的VMDK。

此外,这种问题应该发布在“superuser.com”上 - 而不是“stackoverflow.com”。

答案2

  1. vmx 文件的内容应该记录到 VMware 的图像日志中。

  2. 将如下内容复制到一个文件中(这些内容应该位于 VMware 的图像日志中的 Configuration 和 USER DEFAULT 之间),并将此文件命名为example.vmx.

    config.version = "8"
    virtualHW.version = "4"
    floppy0.present = "true"
    nvram = "VNTco012.nvram"
    deploymentPlatform = "windows"
    virtualHW.productCompatibility = "hosted"
    tools.upgrade.policy = "manual"
    powerType.powerOff = "default"
    powerType.powerOn = "default"
    powerType.suspend = "default"
    powerType.reset = "default"
    displayName = "VNTco012"
    extendedConfigFile = "VNTco012.vmxf"
    scsi0.present = "true"
    scsi0.sharedBus = "none"
    scsi0.virtualDev = "lsilogic"
    memsize = "2048"
    scsi0:0.present = "true"
    scsi0:0.fileName = "VNTco012.vmdk"
    scsi0:0.deviceType = "scsi-hardDisk"
    sched.scsi0:0.shares = "normal"
    ide0:0.present = "true"
    ide0:0.clientDevice = "true"
    ide0:0.fileName = "/usr/lib/vmware/isoimages/windows.iso"
    ide0:0.deviceType = "atapi-cdrom"
    ide0:0.startConnected = "false"
    floppy0.startConnected = "false"
    floppy0.fileName = "/dev/fd0"
    floppy0.clientDevice = "true"
    ethernet0.present = "true"
    ethernet0.networkName = "VM Network 1007"
    ethernet0.addressType = "vpx"
    ethernet0.generatedAddress = "00:50:56:aa:40:b9"
    guestOSAltName = "Microsoft Windows Server 2003, Standard Edition (32-bit)"
    guestOS = "winnetstandard"
    uuid.bios = "50 2a 7f e5 bc 42 27 8b-d0 04 3f 47 3c d8 3a ed"
    log.fileName = "vmware.log"
    snapshot.action = "keep"
    sched.cpu.min = "0"
    sched.cpu.units = "mhz"
    sched.cpu.shares = "normal"
    sched.mem.minsize = "0"
    sched.mem.shares = "normal"
    toolScripts.afterPowerOn = "true"
    toolScripts.afterResume = "true"
    toolScripts.beforeSuspend = "true"
    toolScripts.beforePowerOff = "true"
    scsi0:0.redo = ""
    tools.remindInstall = "FALSE"
    vmware.tools.requiredversion = "7299"
    ethernet0.startConnected = "TRUE"
    tools.deployPkg.fileName = ""
    numvcpus = "2"
    scsi0:1.present = "true"
    scsi0:1.fileName = "VNTco012_1.vmdk"
    scsi0:1.deviceType = "scsi-hardDisk"
    
  3. 通过打开 来启动图像example.vmx

答案3

有一个脚本广告

https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1023880

就我个人而言,我在 Mac OS ElCapitan 上使用它时遇到了麻烦。不幸的是,该脚本的文档记录很差。

我尝试了以下步骤:

#!/bin/bash
# https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1023880
VMXFILENAME=$(sed -n 's/^.*Config file: .*\/\(.\+\)$/\1/p' vmware.log)
echo $VMXFILENAME
exit
echo -e "#\041/usr/bin/vmware" > ${VMXFILENAME}
echo '.encoding = "UTF-8"' >> ${VMXFILENAME}
sed -n '/DICT --- CONFIGURATION/,/DICT ---/ s/^.*DICT \+\(.\+\) = \(.\+\)$/\1 = "\2"/p' vmware.log >> ${VMXFILENAME}

所以首先我想知道配置文件名是否被正确检测到。 grep 显示预期结果

 grep "Config file:"  vmware.log
 2017-01-25T19:35:35.533+01:00| vmx| I125: Config file: /vmware/vm.vmwarevm/vm.vmx

但脚本没有获取正确的文件名,它显示空结果。因此我将获取文件名的行替换为

VMXFILENAME=grep "Config file: " vmware.log | cut -f3 -d"|" | cut -f3 -d ":"

我个人觉得这样更容易理解。首先,我们查找包含“配置文件”的行。在该行中,我们查找用管道符号分隔的第三个字段,然后查找用冒号分隔的第三个字段。是的,这确实决定了配置文件名。

现在让我们看看这是否会创建一个正确的 vmx 文件。首先,我们要确保不会覆盖原始文件,因此最后一行修改为:

>> ${VMXFILENAME}.new

现在我们可以取消注释这部分内容来测试一下。在执行此操作之前,请确保已创建原始 vmx 文件的备份副本(并且仅在需要重新启动此脚本时才创建一次...)

echo "trying to create a new $VMXFILENAME"
today=`date "+%Y-%m-%d"`
if [ -f $VMXFILENAME ]
then
  if [ ! -f $VMXFILENAME.$today ]
  then
    echo "creating backup of $VMXFILENAME as $VMXFILENAME.$today"
    mv $VMXFILENAME $VMXFILENAME.$today
  else
    echo "backup $VMXFILENAME.$today exists"
  fi
else
  echo "$VMXFILENAME not found" 1>&2
  if [ !-f $VMXFILENAME.$today ]
  then
    exit 1
  fi
fi

并且第二个 sed 也没有按预期工作(叹气......)

所以我最终用几行 awk 替换了 sed

#!/bin/bash
# https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1023880
VMXFILENAME=`grep "Config file: " vmware.log | cut -f3 -d"|" | cut -f3 -d ":"`
echo "trying to create a new $VMXFILENAME"
today=`date "+%Y-%m-%d"`
if [ -f $VMXFILENAME ] 
then
  if [ ! -f $VMXFILENAME.$today ]
  then
    echo "creating backup of $VMXFILENAME as $VMXFILENAME.$today"
    mv $VMXFILENAME $VMXFILENAME.$today
  else
    echo "backup $VMXFILENAME.$today exists"
  fi 
else
  echo "$VMXFILENAME not found" 1>&2
  if [ !-f $VMXFILENAME.$today ]
  then
    exit 1
  fi
fi
echo -e "#\041/usr/bin/vmware" > ${VMXFILENAME}
echo '.encoding = "UTF-8"' >> ${VMXFILENAME}
#sed -n '/DICT --- CONFIGURATION/,/DICT ---/ s/^.*DICT \+\(.\+\) = \(.\+\)$/\1 = "\2"/p' vmware.log 
gawk '
# use pipe sign as a field separator
BEGIN { FS="|" }
# check whether we are in the range of lines after DICT --CONFIGURATION
/DICT --- CONFIGURATION/ { inconfig=1;next }
/DICT --- [A-Z+]/        { inconfig=0;next }
/DICT/ && (inconfig==1) { 
          if (match($3,/.*DICT[ \t]+(.*)/,groups)) {
            print groups[1] 
          }
        }
' vmware.log >> ${VMXFILENAME}
echo "please check ${VMXFILENAME}"

相关内容