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

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

参考链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值