虛擬機器裡裝了個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就可能收縮磁碟了。