首先,看 vbox的官方文档:

http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi

VBoxManage modifyhd |

[--type normal|writethrough|immutable|shareable|

readonly|multiattach]

[--autoreset on|off]

[--compact]

[--resize |--resizebyte ]

1

2

3

4

5

6

VBoxManagemodifyhd|

[--typenormal|writethrough|immutable|shareable|

readonly|multiattach]

[--autoreseton|off]

[--compact]

[--resize|--resizebyte]

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.For this operation to be effective, it is required that free space in the guest system first be zeroed out using a suitable software tool. For Windows guests, you can use the sdelete tool provided by Microsoft. Executesdelete -z in the guest to zero the free disk space before compressing the virtual disk image. For Linux, use the zerofree utility which supports ext2/ext3 filesystems.Please note that compacting is currently only available for VDI images. A similar effect can be achieved by zeroing out free blocks and then cloning the disk to any other dynamically allocated format. You can use this workaround until compacting is also supported for disk formats other than VDI.

关键之处正在于 sdelete 应该使用 -c -z  两个选项 ,而网上所以的方法都说是使用 -c 选项。

Using SDelete

SDelete is a command line utility that takes a number of options. In any given use, it allows you to delete one or more files and/or directories, or to cleanse the free space on a logical disk. SDelete accepts wild card characters as part of the directory or file specifier.

usage: sdelete [-p passes] [-s] [-q] ...

sdelete [-p passes] [-z|-c] [drive letter] ...

-a Remove Read-Only attribute

-c Clean free space

-p passes Specifies number of overwrite passes (default is 1)

-q Don't print errors (Quiet)

-s or -r Recurse subdirectories

-z Zero free space (good for virtual disk optimization)

1

2

3

4

5

6

7

8

usage:sdelete[-ppasses][-s][-q]...

sdelete[-ppasses][-z|-c][driveletter]...

-aRemoveRead-Onlyattribute

-cCleanfreespace

-ppassesSpecifiesnumberofoverwritepasses(defaultis1)

-qDon'tprinterrors(Quiet)

-sor-rRecursesubdirectories

-zZerofreespace(goodforvirtualdiskoptimization)

所以,总结一下,正确的方法应该是这样:

在guest os 中清理系统, windows的话可以再硬盘碎片整理一下

在 guest os 中 Windows 执行 sdelete -z -c ; Linux/Debian/Ubuntu 启动到Recovery Mode执行 zerofree /dev/sdaX

VBoxManage modifyhd |  --compact

如果磁盘空间不足,使用如下命令调整(增大/加大)磁盘空间

# 调整到30G,由于默认单位是M,因此数字是 30960

$ VBoxManage modifymedium Debian.vdi --resize 30960 --compact

# 如果存在快照的话,需要删除全部快照,否则系统中看不到磁盘空间变化

# 系统中调整磁盘空间大小

$ sudo apt-get install gparted

$ sudo gparted

1

2

3

4

5

6

7

8

9

10

# 调整到30G,由于默认单位是M,因此数字是 30960

$VBoxManagemodifymediumDebian.vdi--resize30960--compact

# 如果存在快照的话,需要删除全部快照,否则系统中看不到磁盘空间变化

# 系统中调整磁盘空间大小

$sudoapt-getinstallgparted

$sudogparted

参考链接

android+system+disk.vdi,VirtualBox压缩VDI格式硬盘/调整磁盘大小相关推荐

  1. VirtualBox压缩VDI文件 VDI文件瘦身方法

    VirtualBox压缩VDI文件 VDI文件瘦身方法 一.WINDOWS 下压缩 VDI 文件 1.在虚拟机中: 右键计算机->管理->磁盘管理 2.右键所有磁盘,压缩卷,把所有磁盘压缩 ...

  2. virtualbox主机网络管理 未能创建_如何在 VirtualBox 中增加现有虚拟机的磁盘大小 | Linux 中国...

    导读:你可以在 VirtualBox 中扩大虚拟硬盘,即使在创建之后也可以. 本文字数:1434,阅读时长大约:2分钟https://linux.cn/article-12869-1.html作者:D ...

  3. linux动态压缩硬盘,VirtualBox 压缩VDI硬盘

    今天清理了guest系统之后,发现应该压缩一下虚拟硬盘,在网上找了了一下,都是用 vboxmanage 工具,然而照做下来,就是不成功. 最后找了了官方文档,才发现原因. 首先,看 vbox的官方文档 ...

  4. Oracle的vdi文件在哪里,VirtualBox 压缩vdi文件

    1. 碎片整理 打开虚拟机,执行下面的命令: 虚拟机系统为 Linux 系统:sudo dd if=/dev/zero of=/EMPTY bs=1M sudo rm -f /EMPTY 2. 压缩磁 ...

  5. VirtualBox压缩vdi方法

    1.linux虚拟机中: dd if=/dev/zero of=junk sync rm junk poweroff 2.win中打开cmd: C:\Program Files\Oracle\Virt ...

  6. VirtualBox压缩VDI文件 VDI文件瘦身方法(cenos7)

    virtualbox虚拟机运行久了之后就会发现,磁盘镜像vdi文件越来越大.即使你把虚拟机中的大文件删除,这个vdi文件占用的空间还是不变.也就是说动态扩展的vdi文件只会大,不会小.那么大的文件对于 ...

  7. [转]调整 VirtualBox 虚拟机的磁盘大小

    本文转自:https://cnzhx.net/blog/resizing-lvm-centos-virtualbox-guest/ 发表于 2013-08-20 作者 H Zeng  更新于 2016 ...

  8. VirtualBox之vdi、vhd、vmdk虚拟硬盘格式相互转换

    Windows7的引导程序能够引导vhd格式的虚拟硬盘,而VirtualBox创建的虚拟硬盘文件是vdi格式的,怎么办呢? 以前要借助其他软件才能实现,但是VirtualBox早就悄悄为我们带来了一个 ...

  9. 【Android 内存优化】Android 原生 API 图片压缩代码示例 ( PNG 格式压缩 | JPEG 格式压缩 | WEBP 格式压缩 | 动态权限申请 | Android10 存储策略 )

    文章目录 一. 图片质量压缩 二. 图片尺寸压缩 三. Android 10 文件访问 四. 完整源码示例 上一篇博客 [Android 内存优化]图片文件压缩 ( Android 原生 API 提供 ...

  10. VirtualBox的vdi文件复制

    使用VirtualBox时遇到一个问题,我复制一个原来安装好OS的VDI文件,并用它来当作新虚拟机的系统磁盘. 但当我通过Virtual Disk Manager添加新虚拟磁盘时,VirtualBox ...

最新文章

  1. matlab2013 a/b 找不到vs2013 c++ 编译器 解决方案
  2. 全面远程办公还有多远?用智办事很方便!
  3. .a 文件 和 so 文件
  4. python中可变参数args_python 可变参数 *args, **kwds
  5. Jenkisn之JDK-MVN-ANT-GRADLE
  6. java hashmap value_Java HashMap values() 方法
  7. python中如何删除字典中的元素_python中字典删除元素
  8. 前端面试题——HTML基础篇
  9. c语言软件幻化,python字符串处理
  10. Python测试转岗网络安全测试,挑战年薪30W+
  11. GitLab访问403问题
  12. android studio for android learning (八)开机启动界面splashActivity
  13. 500VIP源码下载
  14. ASP.NET 基于asp.net设计项目框架
  15. putty永久设置session
  16. cPanel里的 Addon Domain/Subdomains/Parked domain 区别
  17. flutter显示图标_flutter 引入第三方 Icon 图标(以阿里图标库为例)
  18. PDF文档工具箱Stirling-PDF
  19. 聚焦·洞察 家有矿(HOME MINE)共识生态全球行圆满召开
  20. Extreme Picture Finder(网络图片下载器)官方中文版V3.53.3 | 下载网页图片的软件 | 图片助手批量图片下载器

热门文章

  1. Hibernate Session.get()和Session.laod()的区别
  2. stm32刷linux固件,STM32 固件烧录指南
  3. sql1428N错误
  4. TcaplusDB X 黎明觉醒,探索不止,黎明将至
  5. 关于网络异常的英文词汇总结
  6. 红警战网服务器端源码,红色警戒2战网平台完整版
  7. MSP430 G2553 Launchpad实现电容测量
  8. android 360短信拦截,Android版360卫士更威武
  9. OSU双足步行机器人 Cassie利用强化学习站立的源码实现
  10. HTML超链接标签—链接QQ在线聊天