VirtualBox is a Net Reliant favorite when it comes to virtualization. It is a professional, enterprise grade solution that runs on Windows, Linux, Macintosh, and Solaris hosts.

VirtualBox allows for flexible storage management by allowing for the creation of dynamically allocated guest images. Most users go for the dynamically expanding images in VirtualBox as they do not want to limit themselves to a small virtual disk size and at the same time do not want to waste disk space on their host while the guest doesn't actually need it. Although these images will initially be very small and occupy minimal storage space, over time the images will grow. This is due to the image expanding every time a disk sector (virtual) is written to for the first time.

To help reduce excess disk usage, VirtualBox provides a mechanism for compacting dynamically allocated guest images. Below are the steps to follow if your guest operating system is Linux:

  1. Start the Linux virtual machine;
  2. Clean the free space on the disk of the Linux virtual machine;
  3. Shutdown the Linux virtual machine;
  4. Use the VirtualBox VBoxManage utility to compact the Linux guest image.

Step 1: Start the Linux Virtual Machine

Start the Linux Virtual Machine and log in with administrative rights.

Step 2: Clean any free disk space

The most effective way to clean free disk space on a Linux drive is to use the Linux dd utility which is a bit-stream duplicator. Open up a terminal window and type the following command:

dd if=/dev/zero of=zerofillfile bs=1M

This command will zero-fill any free disk space on the virtual Linux drive.

  • if= specifies the input file;
  • /dev/zero indicates a bit-stream of zeros
  • of= specifies the output file
  • zerofillfile name of the file containing the bit-stream of zeros
  • bs= indicates the block size
  • 1M indicates that the block size will be 1 megabyte

Once the dd has completed, you will see a message in your terminal window indicating that there is no space left on the device:

dd: writing 'zerofillfile': No space left on device

You can now remove zerofillfile using the Linux rm utility:

rm zerofillfile

Step 3: Shutdown the Linux Virtual Machine

 End your session and shutdown the Linux Virtual Machine.

Step 4: Compact the Linux guest image

To compact the Linux guest image, use the VirtualBox VBoxManage utility. Assuming a Windows host, use the following command at the DOS prompt:

VBoxManage modifyhd --compact "[drive]:\[path_to_image_file]\[name_of_image_file].vdi"

Ensure that you replace the items in square brackets with your parameters.

If your Windows host complains that VBoxManage cannot be found or is an invalid command, you may need to explicitly specify the path to the VirtualBox executables. So a complete example for compacting a Linux guest image at the DOS prompt is as follows:

C:\> path C:\Program Files\Oracle\VirtualBox
C:\> VBoxManage modifyhd --compact "C:\netreliant_VMs\linux_001.vdi"

Once the VirtualBox VBoxManage utility is running you will see progress indicators in 10% increments starting from 0% to 100%. And once the process is complete, you should have a smaller disk image file.



source - http://www.netreliant.com/news/8/17/Compacting-VirtualBox-Disk-Images-Linux-Guests.html#.U_oRRnV_sW0






Virtual Machine

# dd if=/dev/zero of=zerofillfile bs=1M

dd: writing `zerofillfile': No space left on device

30776+0 records in

30775+0 records out

32270835712 bytes (32 GB) copied, 834.076 s, 38.7 MB/s


# ll
-rw-r--r--. 1 root  root   31G Jan 14 09:57 zerofillfile

# rm ./zerofillfile 
rm: remove regular file `./zerofillfile'? y


Host Machine
# ll
-rw-------.  1 root root  31G Jan 14 10:11 centOS6.5_64.vdi

# VBoxManage modifyhd --compact centOS6.5_64.vdi 

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%


# ll

-rw-------.  1 root root  15G Jan 14 10:15 centOS6.5_64.vdi


# VBoxHeadless --startvm "centOS6.5_64" --vrde off &








VirtualBox is a Net Reliant favorite when it comes to virtualization. It is a professional, enterprise grade solution that runs on Windows, Linux, Macintosh, and Solaris hosts.

VirtualBox allows for flexible storage management by allowing for the creation of dynamically allocated guest images. Most users go for the dynamically expanding images in VirtualBox as they do not want to limit themselves to a small virtual disk size and at the same time do not want to waste disk space on their host while the guest doesn't actually need it. Although these images will initially be very small and occupy minimal storage space, over time the images will grow. This is due to the image expanding every time a disk sector (virtual) is written to for the first time.

To help reduce excess disk usage, VirtualBox provides a mechanism for compacting dynamically allocated guest images. Below are the steps to follow if your guest operating system is Windows:

  1. Start the Windows virtual machine and delete any unnecessary files;
  2. Defragment the disk of the Windows virtual machine;
  3. Clean the free space on the disk of the Windows virtual machine;
  4. Shutdown the Windows virtual machine;
  5. Use the VirtualBox VBoxManage utility to compact the Windows guest image.

Step 1: Start the Windows Virtual Machine and Delete Unnecessary Files

Start the Windows Virtual Machine and delete any files that you don't need. Places to start are:

  • Empty the recycle bin;
  • Delete files in your temp folders;
  • Clear any web browser caches;
  • Clear any application caches.

Step 2: Defragment the Disk

  • Locate your hard disk drive using Windows Explorer in the virtual machine;
  • Right-click the drive and choose the Properties option;
  • Then select the Tools tab and click the Defragment now ... button.

Follow the steps to defragment the virtual Windows disk.

Step 3: Clean any free disk space

After the disk has been defragmented, the virtual Windows drive will still have unused space containing garbage bits and bytes. These garbage bits and bytes are from the contents of files that used to occupy that space but that are no longer there.

The most effective way to clean free disk space on a Windows drive is to overwrite the unused space with a bitstream of zeros or to zero-fill any free space.

Windows does not come with a native utility to zero-fill unused space but you can find the excellent SDelete tool at Microsoft's TechNet: http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx

SDelete (or Secure Delete) is a command line utility. So to zero-fill the virtual Windows disk, type the following at the DOS prompt:

C:\> sdelete.exe -z

where -z is the SDelete parameter to zero any free space.

Once SDelete is running you will see a message similar to the following:

SDelete is set for one pass.
Cleaning free space on c:: 12%

Step 4: Shutdown the Windows Virtual Machine

When SDelete has finished running and the free space cleaned or zeroed is 100%, shutdown the Windows virtual machine.

Step 5: Compact the Windows guest image

To compact the Windows guest image, use the VirtualBox VBoxManage utility. Assuming a Windows host, use the following command at the DOS prompt:

VBoxManage modifyhd --compact "[drive]:\[path_to_image_file]\[name_of_image_file].vdi"

Ensure that you replace the items in square brackets with your parameters.

If your Windows host complains that VBoxManage cannot be found or is an invalid command, you may need to explicitly specify the path to the VirtualBox executables. So a complete example for compacting a Windows guest image at the DOS prompt is as follows:

C:\> path C:\Program Files\Oracle\VirtualBox
C:\> VBoxManage modifyhd --compact "C:\netreliant_VMs\windowsXP_001.vdi"

Once the VirtualBox VBoxManage utility is running you will see progress indicators in 10% increments starting from 0% to 100%. And once the process is complete, you should have a smaller disk image file.



source - http://www.netreliant.com/news/9/17/Compacting-VirtualBox-Disk-Images-Windows-Guests.html#.VY5Txa3tlBc

Posted by linuxism
,