[Note]How to Compact VitualBox's HardDisk File(.vdi)

if guest OS is Windows, use system defrag tools first, and then goto step 5.

if guest OS is Linux, like Ubuntu for example, follow these steps:

 

1. Download zerofree file from the url below and install it, need gcc libraries and ext2fs library if compile it from source.

wget http://intgat.tigress.co.uk/rmy/uml/zerofree-1.0.1.tgz or sudo apt-get install zerofree

 

2. Start runlevel 1

sudo telinit 1

 

3. Check to see disk names using df command and in left corner of the result there are /dev/... devices, in my case /dev/sda1. Mount this disk as read only:

mount --o remount,ro -t ext3 /dev/sda1 /

 

4. Make zeros and Check if everything is ok with file system

zerofree /dev/sda1
fsck 
-/dev/sda1

 

5. shutdown guest OS.

 

6. use VBoxManage to shrink the space

"C:\Program Files\Sun\VirtualBox\VBoxManage" modifyvdi vdi_file_name.vdi compact

 

posted @ 2010-03-12 13:37  chinajuanbob  阅读(281)  评论(0编辑  收藏  举报