Shrinking Virtual Disks
If you have a virtual disk that grows as data is added, you can shrink it as described in this section.If you allocated all the space for your virtual disk at the time you created it, you
cannot shrink it.(就是说,如果你选择了在建立虚拟机的时候一次性分配硬盘空间,那就不能收缩了)
Note: The maximum benefit occurs when you defragment
a virtual disk before you shrink it. See Defragmenting
Virtual Disks.(最好碎片整理一下)
Shrinking a virtual disk reclaims unused space in the virtual disk. If there is empty space in the disk, this process reduces the amount of space the virtual disk occupies on the host drive.(这就是我要的目的啊啊啊啊)
Shrinking a virtual disk is a convenient way to convert a virtual disk to the format supported by Workstation. Virtual disks created in the new format can be recognized only by VMware Workstation 3.0 and higher.
This section describes the following topics:
Restrictions and Requirements
Shrinking requires free disk space on the host equal to the size of the virtual disk you are shrinking.(收缩空间时,必须硬盘空间有和虚拟机磁盘一样大的空间,当时我就泪奔了。。。尼玛。。我收缩就是因为硬盘没空间了啊。。不过我在绝望的时候又做了一次defragment,然后compatc了一下,这次没报希望的动作居然成功的把物理硬盘空间腾出来30G,这样一来,我的磁盘空余空间就大于虚拟磁盘空间了)
Shrinking applies only to virtual disks. You cannot shrink physical disks or CD-ROMs.
The shrink feature is not enabled if the virtual machine
Contains a snapshot(有快照存在的时候不能shrink)
Is a parent of a linked clone
Is a linked clone
The shrink feature is not enabled for a virtual machine if any of its virtual disks are
Preallocated when created(建虚拟机时分配 好了的磁盘不能收缩)
Not used in independent-persistent mode(意思是 只有independent-persistent模式的才可以收缩)
Legacy disks that are not in persistent mode
Booted as independent disks
Note: You can
change the mode of a virtual disk before the virtual machine is powered on. See Excluding
Disks from Snapshots for a discussion of independent disks.
The Shrinking Process
Shrinking a disk is a two-step process:
In the first step, called wiping, VMware Tools reclaims all unused portions of disk partitions (such as deleted files) and prepares them for shrinking. Wiping takes place in the guest operating system.(第一步,被称为清理,VMware
Tools要求收回所有磁盘分区中未使用的部分(诸如删除的文件)并为收缩作好准备。清理工作在客户机操作系统中进行。 )
The second step is the shrinking process itself, which takes place on the host. Workstation reduces the size of the disk's files by the amount of disk space reclaimed in the wipe process.(第二步,收缩虚拟磁盘,它在宿主机中进行。Workstation通过清理程序回收磁盘空间来减少虚拟磁盘文件的大小。
)
When a virtual machine is powered on, you shrink its virtual disks from the VMware Tools control panel. You cannot shrink virtual disks if a snapshot exists. To remove the snapshot if one exists, choose VM
> Snapshot > Snapshot Manager > Delete. See Unsupported
and Disabled Partitions.
In a Linux or FreeBSD guest operating system, to prepare virtual disks for shrinking, you should run VMware Tools as the root user. This way, you ensure the whole virtual disk is shrunk. Otherwise, if you shrink disks as a nonroot user you cannot wipe the parts
of the virtual disk that require root-level permissions.
To shrink a virtual disk:
1. Launch the control panel.
Windows guest — double-click the VMware Tools icon in the system tray,
or choose Start > Settings > Control Panel, then double-click VMware
Tools.
Linux or FreeBSD
guest — become root (su -), then run vmware-toolbox
.#/usr/bin/vmware-toolbox
2. Click the Shrink tab.

3. Select the virtual disks you want to shrink, then click Prepare to Shrink.
A dialog box tracks the progress of the wiping process.

Note: If you deselect some partitions, the whole disk is still shrunk.
However, those partitions are not wiped for shrinking, and the shrink process does not reduce the size of the virtual disk as much as it could with all partitions selected.
4. Click Yes when VMware Tools finishes wiping the selected disk partitions.

A dialog box tracks the progress of the shrinking process. Shrinking disks may take considerable time.

5. Click OK to finish.

Unsupported and Disabled Partitions
In some configurations, it is not possible to shrink virtual disks. If your virtual machine uses such a configuration, the Shrink tab displays information explaining why you cannot shrink your virtual disks.


For example, you cannot shrink a virtual disk if
You preallocated disk space when you created the disk. Preallocating disk space is the default option for both typical and custom virtual machine creation paths.
The virtual machine has any snapshots. To delete a snapshot, choose VM >
Snapshot >Snapshot Manager > Delete.
The virtual machine contains physical disks.
The virtual disk is not an independent disk in persistent mode.
The virtual disk is stored on a CD-ROM
执行完shrink之后,我的host主机的硬盘可用空间从190G增加到了240G,可见,容量收缩了50多个个G。。。
虚拟机在使用过程中,虚拟磁盘的大小会不断变大。即使你删除了磁盘中的文件,虚拟磁盘的大小仍然不会缩小。VMWare在VMWare Tools中推出了Shrink这个功能。在安装VMWare Tools后,在没有Snapshot的情况下,在Guest操作系统为Windows的情况下,能有效缩小虚拟磁盘大小。但如果在Guest操作系统为Linux时,此方法效果就不好了,而且有些挂载点无法Shrink。
VMWare还推出了vmware-vdiskmanager工具,也能Shrink虚拟磁盘。在Guest操作系统为Linux时,单独用此工具没有什么效果。需要先在Guest系统中把未使用的 空间清零,在使用vmware-vdiskmanager,效果比较好。可以通过以下步骤有些缩小虚拟磁盘。
1、cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
在Shell中运行以上命令,能对未使用空间清零,需要较大的空闲空间(跳过这步也可以,只是压缩效果没有这样好)
2、关闭Guest操作系统,进入VMWare安装目录运行:
vmware-vdiskmanager.exe -k "f:/vmware/Fedora11/Fedora11.vmdk"
就可以有效缩小虚拟磁盘的大小,基本达到你用了多少占用多少的效果。
用此方法分别对Guest系统为Fedora11和OpenSolaris10的VMDK文件进行Shrink,效果明显。