加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 为什么当我删除虚拟机中的大文件时,主机上的磁盘映像文

发布时间:2020-12-14 01:04:11 所属栏目:Linux 来源:网络整理
导读:我在虚拟机上安装了CentOS(主机操作系统是 Windows 7).我创建了磁盘映像文件,即VDI文件(动态分配的映像).最近,当我删除CentOS中的大文件时,我磁盘上的VDI文件不会减少.为什么?如何解决这个问题? 解决方法 删除VM中的文件时,VirtualBox不会自动回收磁盘空间
我在虚拟机上安装了CentOS(主机操作系统是 Windows 7).我创建了磁盘映像文件,即VDI文件(动态分配的映像).最近,当我删除CentOS中的大文件时,我磁盘上的VDI文件不会减少.为什么?如何解决这个问题?

解决方法

删除VM中的文件时,VirtualBox不会自动回收磁盘空间(在主机上).要缩小磁盘映像,您需要

首先,将所有可用空间(对于HDD上的所有分区和逻辑卷)清零,然后关闭VM.

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来执行相同操作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读