回收VMWare虚拟机占用的磁盘空间


虚拟机里装了个Ubuntu 10.04,是老早以前了的了,由于仅安装了开发环境和Oracle 10g,占用空间在8G左右。

前几天升级了12.04.01,麻烦来了,虚拟机硬盘空间暴增至16G左右,卸载了openoffice等不用的软件,apt-get clean了,apt-get autoremove了。

df -H了一下,OK,磁盘占用8G左右了,可是虚拟机硬盘还是16G大小!

折腾了半天,查了N多资料,终于搞定:

1. 虚拟机设置的硬盘选项中先Compac一下;

2.开虚拟机

Before we try to shrink the virtual disk files, we should try to remove any unneeded files from the virtual machine to free space. For example, on Debian-based VMs, you can run

apt-get clean

to clear out the local repository of retrieved package files.

Next, run

cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

to fill the unused space with zeros.

Then power down the VM and open the command window on the Windows host:

3.宿主机执行命令:vmware-vdiskmanager.exe -k F:\*****\ubuntu-10.04.4-desktop-i386.vmdk

提示 Shrink: 100% done.

Shrink completed successfully.

完成

注意:折腾了多次,就是因为,没有cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill,所以没成,可能是需要wipe吧。

小提示

以下这些情况是无法使用shrink功能的:

★使用默认方式新建的GSX Server虚拟机。

★使用了快照功能的虚拟机。

★使用了物理磁盘为虚拟机磁盘。

★虚拟磁盘保存在CD-ROM或DVD-ROM上。

★你不能收缩预分配的磁盘。

在进行收缩之前,需要删除创建的快照,之后,直接登录虚拟,打开VmwareTools就可能收缩磁盘了。

相关内容