<分区>
我在 virtualbox 上安装了 CentOS(主机操作系统是 Windows 7)。我创建的磁盘镜像文件是 VDI 文件(动态分配的镜像)。最近,当我在CentOS 中删除大文件时,我磁盘上的VDI 文件并没有减少。为什么?如何解决这个问题?
标签 linux virtualbox
<分区>
我在 virtualbox 上安装了 CentOS(主机操作系统是 Windows 7)。我创建的磁盘镜像文件是 VDI 文件(动态分配的镜像)。最近,当我在CentOS 中删除大文件时,我磁盘上的VDI 文件并没有减少。为什么?如何解决这个问题?
最佳答案
当您在 VM 中删除文件时,VirtualBox 不会自动回收磁盘空间(在主机上)。要缩小磁盘镜像,您需要
首先,将所有可用空间清零(对于 HDD 上的所有分区和逻辑卷),然后关闭虚拟机。
cat/dev/zero > z;sync;sleep 3;sync;rm -f z
然后,使用以下命令压缩VDI。
VBoxManage modifyhd/path/to/image.vdi --compact
With the --compact option, can be used to compact disk images, i.e. remove blocks that only contains zeroes. This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk. Compaction works both for base images and for diff images created as part of a snapshot.
顺便说一句:对于 VMWare (.vmdk),您需要使用 vmware-vdiskmanager -k xxx.vmdk
来执行相同的操作。
关于linux - 为什么我在虚拟机中删除大文件时主机上的磁盘镜像文件不会减少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14921633/