歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 回收VMWare虛擬機占用的磁盤空間

回收VMWare虛擬機占用的磁盤空間

日期:2017/2/28 14:51:00   编辑:Linux教程

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

Copyright © Linux教程網 All Rights Reserved