今天清理了guest系统之后,发现应该压缩一下虚拟硬盘,在网上找了了一下,都是用 vboxmanage 工具,然而照做下来,就是不成功。

最后找了了官方文档,才发现原因。

首先,看 vbox的官方文档:

VBoxManage modifyhd         |

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

readonly|multiattach]

[--autoreset on|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. Execute sdelete -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 应该使用 -z 选项 ,而网上所以的方法都说是使用 -c 选项,这个浪费了近3个小时。

MS的文档也说的明白:

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,  在guest os 中清理系统, windows的话可以再硬盘碎片整理一下

2,  在 guest os 中 使用 sdelete -z  ; linux 使用 zerofree

3,  VBoxManage modifyhd |  --compact

linux动态压缩硬盘,VirtualBox 压缩VDI硬盘相关推荐

  1. linux 设备直通,使用virtualbox运行物理硬盘的系统 USB设备直通,支持网银、刷...

    有些人使用虚拟机的时候遇到了些问题,所以我就发个帖子说下几个解决方法,希望能对刚刚接触的人有些帮助. 安装virtualbox: 如果是ubuntukylin,那么可以在ubuntu软件中心或者ubu ...

  2. 怎么在虚拟机上安装linux mint,如何在VirtualBox上安装Linux Mint?

    本文概述 在VirtualBox上安装Linux Mint的分步指南. Linux Mint是社区驱动的基于ubuntu的开源操作系统.它是免费使用的:这就是为什么它受到全球数百万用户的喜爱和采用的原 ...

  3. VirtualBox压缩vdi方法

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

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

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

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

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

  6. VirtualBox的虚拟硬盘vdi扩容

    本文完全拷贝自    http://blog.csdn.net/njchenyi/article/details/17611915 进入命令行,以Windows系统为例 运行:cmd C:\Users ...

  7. 服务器2012系统磁盘压缩,windows xp系统对硬盘进行压缩增加磁盘可用空间的方法...

    熟悉windows 9X操作系统的用户应该知道,该系统可以通过系统工具"磁盘空间管理"压缩硬盘,增加磁盘可用的空间.对于windows xp系统用户来说,xp系统中没有" ...

  8. linux 压缩文件夹格式,Linux下常见文件格式的压缩、解压小结

    Linux下常见文件格式的压缩.解压小结 .tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ...

  9. linux 目录结构+常用命令+压缩命令+vim使用+及一些基础知识(非常好)

    linux目录架构 / 根目录 /bin 常用的命令 binary file 的目录 /boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内 /boot/grub/menu.lst ...

最新文章

  1. SAP 预制发票报错 -Material 20000000 D119223073 in valuation area VNSM has inconsistant ML data- 之对策
  2. 【HDU 5402】Travelling Salesman Problem(构造)
  3. 数据库密码过期 怎么修改
  4. php拒绝服务,CVE-2015-7803
  5. (转)怎样完全用 GNU/Linux 工作
  6. 我心目中未来的计算机200字,我心目中未来的计算机.doc
  7. ORACLE数据库常用命令总结
  8. linux软件包管理 pdf,vSphere Storage Appliance 安装和管理 PDF
  9. Ubuntu下安装配置JDK1.7
  10. redis学习与入门~~~
  11. Vue指令之v-show
  12. arcmap shp导出cad无反应_软件技巧如何利用OSM提取场地CAD以及LANDUSE属性
  13. arm解锁 j-flash_jlink驱动下载(SEGGER J-FlASH ARM)
  14. ESP8266WiFi模块资料整理
  15. 科研的常用软件高效神器
  16. 多项式秦九韶算法c语言
  17. 2014年5月欧洲地区SAT写作真题及解题技巧
  18. 图形学实验三 图形几何变换
  19. 学习笔记-应用光学 第一章 几何光学的基本定律
  20. 还在用QQ邮箱?教你如何创建自己的高逼格邮箱

热门文章

  1. 《Unity开发实战》——2.4节自定义镜头光晕效果
  2. 几何光学基础(1):基本定律
  3. 用cJSON解析心知天气返回的数据包
  4. oracle11g GI+RAC卸载
  5. [软考]挣值管理EVM详细解释及应用,实例讲解收集(信息系统项目管理师-成本管理)...
  6. 卡路里与脂肪重量的换算
  7. html左右滑轮标签,css样式支持左右滑动要点
  8. 【BZOJ】1535: [POI2005]Sza-Template
  9. Newton-Raphson切线法解高次方程近似根
  10. Understanding Human Behaviors in Crowds by Imitating the Decision-Making Process