Reduce the size of virtualbox virtual hard disk files

Source: Internet
Author: User
Tags compact

After a virtual machine is used for a long time, it will find that the virtual hard disk is getting bigger and bigger. However, after reading the system commands in the virtual machine, the occupied space is far from the size of the virtual hard disk, this is unpleasant and inconvenient for sharing Virtual Machine images. Virtualbox does not seem to provide a graphical interface for us to compress the virtual hard disk size, but it can be achieved through the command line. According to actual tests, a 30 GB virtual hard disk can be compressed to 13 Gb, the space that can be compressed depends on the actual space occupied by your virtual machine.

Virtualbox virtual hard disk

 

Directory [-]

  • 1. Fragment
  • 2. compress the disk

Virtualbox supports both its own virtual hard disk format VDI and VMWare's vmdk format. The compression of the two formats is slightly different.

1. Fragment

The first step is to fragment, open the virtual machine, and execute the following command:

Linux:

12 sudo dd if=/dev/zero of=/EMPTY bs=1Msudo rm -f /EMPTY

 

In Windows, you need to download sysinternals suite and execute:

1 sdelete –z

 

2. compress the disk

Shut down the Virtual Machine. Now you can compress the virtual hard disk.

If your virtual hard disk is in the VDI format of virtualbox, find your virtual hard disk file and run the following command:

1 VBoxManage modifyhd mydisk.vdi --compact

 

If your virtual hard disk is in the vmdk format of VMware, It is troublesome, because virtualbox does not support direct compression of the vmdk format, but it can be changed to VDI and compressed first, switch back to vmdk. Run the following command:

123 VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdiVBoxManage modifyhd cloned.vdi --compactVBoxManage clonehd "cloned.vdi" "compressed.vmdk" --format vmdk

 

In fact, when executing the command, we can find that the conversion from vmdk to VDI seems to have been compressed, and the file size has been greatly reduced, the second command did not see any changes in the file size, so the second command should be omitted here.

Reference: http://my.oschina.net/tsl0922/blog/188276

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.