virtualbox压缩vdi硬盘

原址: http://blog.youkuaiyun.com/bbplayers/article/details/7770775

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

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


首先,看 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 ]

 

 

  • Withthe --compact option,can be used to compact disk images, i.e. remove blocks that onlycontains zeroes. This will shrink a dynamically allocated imageagain; it will reduce the physical sizeof the image without affecting the logical size of the virtualdisk. Compaction works both for base images and for diff imagescreated as part of a snapshot.

    For this operation to beeffective, it is required that free space in the guest system firstbe zeroed out using a suitable software tool. For Windows guests,you can use the sdelete toolprovided by Microsoft. Execute sdelete-zin the guest to zero the free disk space beforecompressing the virtual disk image. For Linux, usethe zerofreeutilitywhich supports ext2/ext3 filesystems.

    Please note that compactingis currently only available for VDI images. A similar effect can beachieved by zeroing out free blocks and then cloning the disk toany other dynamically allocated format. You can use this workarounduntil compacting is also supported for disk formats other thanVDI.

 

关键之处正在于 sdelete 应该使用 -z 选项 ,而网上所以的方法都说是使用 -c 选项,这个浪费了近3个小时。


MS的文档也说的明白:

http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx


 

Using SDelete

 

SDelete is acommand line utility that takes a number of options. In any givenuse, it allows you to delete one or more files and/or directories,or to cleanse the free space on a logicaldisk. SDelete acceptswild card characters as part of the directory or filespecifier.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值