VMware 虚拟机磁盘文件合并
在创建 VMware workstation 虚拟机时,在磁盘选项上会提示选择创建单个虚拟磁盘文件或分割为多个文件。我喜欢使用单个文件,因为选择多个文件会在虚拟机目录下建立许多类似的 vmdk 文件,不太方便复制到其他地方。而且在导入 macOS 下的 VMware fusion 时会报错,所以推荐使用单个磁盘文件。
当现有的虚拟机已经是使用多个文件形式的话,可以使用 VMware workstation 附带的 vmware-vdiskmanager.exe 工具来进行合并。
vmware-vdiskmanager.exe 是一个命令行工具,工具的位置在 VMware 安装路径下,如:C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe
在 PS 命令行下调用此工具查看帮助:
PS C:\Users\Marco Nie> &"vmware-vdiskmanager.exe"
VMware Virtual Disk Manager - build 16894299.
Usage: vmware-vdiskmanager.exe OPTIONS <disk-name> | <mount-point>
Offline disk manipulation utility
Operations, only one may be specified at a time:
-c : create disk. Additional creation options must
be specified. Only local virtual disks can be
created.
-d : defragment the specified virtual disk. Only
local virtual disks may be defragmented.
-k : shrink the specified virtual disk. Only local
virtual disks may be shrunk.
-n <source-disk> : rename the specified virtual disk; need to
specify destination disk-name. Only local virtual
disks may be renamed.
-p : prepare the mounted virtual disk specified by
the mount point for shrinking.
-r <source-disk> : convert the specified disk; need to specify
destination disk-type. For local destination disks
the disk type must be specified.
-x <new-capacity> : expand the disk to the specified capacity. Only
local virtual disks may be expanded.
-R : check a sparse virtual disk for consistency and attempt
to repair any errors.
-e : check for disk chain consistency.
-D : make disk deletable. This should only be used on disks
that have been copied from another product.
-U : delete/unlink a single disk link.
Other Options:
-q : do not log messages
Additional options for create and convert:
-a <adapter> : (for use with -c only) adapter type
(ide, buslogic, lsilogic). Pass lsilogic for other adapter types.
-s <size> : capacity of the virtual disk
-t <disk-type> : disk type id
Disk types:
0 : single growable virtual disk
1 : growable virtual disk split into multiple files
2 : preallocated virtual disk
3 : preallocated virtual disk split into multiple files
4 : preallocated ESX-type virtual disk
5 : compressed disk optimized for streaming
6 : thin provisioned virtual disk - ESX 3.x and above
The capacity can be specified in sectors, KB, MB or GB.
The acceptable ranges:
ide/scsi adapter : [1MB, 8192.0GB]
buslogic adapter : [1MB, 2040.0GB]
ex 1: vmware-vdiskmanager.exe -c -s 850MB -a ide -t 0 myIdeDisk.vmdk
ex 2: vmware-vdiskmanager.exe -d myDisk.vmdk
ex 3: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
ex 4: vmware-vdiskmanager.exe -x 36GB myDisk.vmdk
ex 5: vmware-vdiskmanager.exe -n sourceName.vmdk destinationName.vmdk
ex 6: vmware-vdiskmanager.exe -k myDisk.vmdk
ex 7: vmware-vdiskmanager.exe -p <mount-point>
(A virtual disk first needs to be mounted at <mount-point>)
VMware 生成的磁盘多个文件名称命名规则是如下:
- 根磁盘文件 - 如:Windows7.vmdk
- 分割磁盘文件 - 如:Windows7-s001.vmdk Windows7-s002.vmdk Windows7-s003.vmdk ...
使用命令合并多文件时只需要指定跟磁盘文件名称即可。
根据帮助文档,使用 -r
指令指定多文件,-t 0
指令指定输出为单文件。示例如下:
&"vmware-vdiskmanager.exe" -r Windows7.vmdk -t 0 merge.vmdk
Creating disk 'merge.vmdk'
Convert: 100% done.
Virtual disk conversion successful.
命令执行后,在对应目录下会生成 merge.vmdk 虚拟磁盘文件,可以使用此文件建立新的虚拟机。
标签:无