linux - 为什么我在虚拟机中删除大文件时主机上的磁盘镜像文件不会减少?

标签 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

VBox Doc

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/

相关文章:

windows - 允许在全屏的 guest Virtualbox session 中弹出主机通知

networking - virtualbox 客户端机器 : host name lookup failure in telnet while the same hostname lookup success in ping

linux - 即使使用安全启动 - bash 脚本,如何在 Linux 上安装 VirtualBox

linux - 如果无法 ping 通目的地,我如何获取网络延迟?

c - 文件阅读作为一种资源

ubuntu - 带有ubuntu的Windows虚拟机无法启动

linux - 带有桥接适配器的 VirtualBox 上的 Debian guest 无法访问互联网

linux - AWK命令打印反转

linux - diff:根据缩进显示整个部分

c - linux线程和内存/变量