Contact Info

Atlas Cloud LLC 600 Cleveland Street Suite 348 Clearwater, FL 33755 USA

[email protected]

Client Area
Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3

VirtualBox does not automatically reduce the size of Linux guest disks. However, you can manually free up disk space by clearing unnecessary data and compressing the disk.

It is advisable to activate dynamic allocation within VirtualBox and ensure you have a backup of your data before you start the disk compression procedure.

Utilize the “dd” command to clear unused space on the Linux guest, followed by the VBoxManage command to reduce the size of the virtual disk image.

Running Linux in a VirtualBox virtual machine often results in the virtual disks growing larger over time, despite deleting unnecessary files. I will guide you through the process to efficiently shrink and compress these volumes, thereby conserving disk space.

If you’ve been using VirtualBox with Windows as your guest operating system, you might notice that your disk volumes tend to decrease in size when files are deleted, ensuring they only occupy as much space in your physical disk as the actual content they hold.

However, this feature known as dynamic allocation does not function similarly with Linux guests. For those operating Linux in a virtual environment, the disk space often expands to the maximum allotted size and fails to condense, regardless of data deletion inside them.

This behavior is primarily due to Linux’s approach to file management within its filesystems, which does not incorporate zeroing out (purging with blank data) deleted files, mainly to boost performance. Consequently, VirtualBox struggles to differentiate between active and deleted data within the virtual disk.

To rectify this, you can manually zero out this data and instruct VirtualBox to compact the disk to accurately reflect its real usage, thereby reclaiming unused space.

The initial step in recovering disk space on virtual disks within your Linux guests is to verify that dynamic allocation is active. Should this feature be deactivated, you’ll have to convert your disk to a dynamically allocated disk.

Then, it’s critical to back up your virtual disk. Any error during the process, such as an incorrect command or a power outage, could lead to a complete loss of data stored on your Linux guest.

Following this, in your Linux guest, you need to run the following command in the terminal:

This command will continuously write zeroed data to the file /var/deleteme until the disk is full. This action permanently removes previously deleted files, addressing the issue that Linux does not automatically overwrite deleted data.

Exercise caution when using the dd command, as it can permanently overwrite data without any prior alert. Always double-check your commands and file paths before execution.

The completion time for this operation varies based on the volume size. Remain patient and avoid interrupting the procedure. After completion, you might encounter an error message stating it ran out of space. At this point, you can remove the file that was zeroed out and power off your Linux system:

sudo shutdown now -h

With the unreferenced space within your virtual disk zeroed, VirtualBox can now compress the virtual disk on your host machine. To compact the virtual disk, use the following command:

You must update /path/to/image.vdi to represent the actual location of the virtual disk you wish to compress. For Windows users, this involves utilizing VBoxManage.exe as described:

If VBoxManage.exe is unreachable from the command prompt on your Window system, further instructions are provided below on how to incorporate it into your system’s path.

The compression of a VirtualBox Linux guest file through this technique involves the use of the dd command, which helps in creating a zero-filled file on the disk allowing VirtualBox to recognize the free space.

The dd command (data duplicator) is effective for converting and copying files and also supports writing data streams. The “if” parameter is used to define the source of the data (where /dev/zero provides an uninterrupted stream of zeros or null data). The “of” parameter defines the destination for this data, which will write null data until the storage is full because /dev/zero continuously outputs null data.

By default, VBoxManage.exe isn’t available on the Windows command line. You can make it accessible by updating your Windows system path to include the VirtualBox installation directory, or by specifying the full path to the executable when using it.

The “&” symbol, known as the call operator, executes the command enclosed in quotes. This allows for the inclusion of spaces in the path to the executable.

As your virtual machines grow, you can increase the size of their virtual disks or reduce their capacity. Snapshotting allows you to save the state of your virtual machine at a certain point, allowing for easy reversion to that state later—for example, after testing a new configuration.

VirtualBox is a robust virtualization tool used by professionals and hobbyists alike to build and test software, run older programs and games on modern systems, or operate additional operating systems without the need for a second physical machine. You can run various operating systems such as Windows, Linux, ChromeOS, and Android on MacOS, Windows, and Linux hosts.


Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.

Share this Post
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x