How to Reduce the Size of a VirtualBox Virtual Machine and Boost Disk Space

1267
How to Reduce the Size of a VirtualBox Virtual Machine and Boost Disk Space

Here we can see, “How to Reduce the Size of a VirtualBox Virtual Machine and Boost Disk Space”

VirtualBox creates dynamic drives by default, which grow over time as you add data. If you later delete data from the virtual computer, you’ll find that the disc does not shrink automatically. However, a hidden command can be used to shrink a dynamic disc manually.

Remember that this will only shrink the disc if it has grown in size and you have eliminated data since then. This will not shrink a dynamic disc that you have just made. However, if you construct a dynamic drive, download 10 GB of data into it, and then delete the data, you should be able to decrease the disc by around 10 GB.

Step 1: Double-check that you’re using a dynamic disc.

This method is only applicable to dynamic discs, which can expand and contract in size. Dynamic discs can be up to a given maximum capacity—50 GB, for example—but only when they hold that much data do they truly grow to that amount. Disks with a fixed size will always be at their maximum size.

If you want to shrink a fixed-size disc, convert it to a dynamic disc and follow the methods below. If you have a 50 GB fixed drive with just 20 GB of data on it and you convert it to a dynamic disc, you should be able to reduce it down to only 20 GB of Space.

  • In VirtualBox, right-click the virtual machine that utilizes the disc and select “Settings” to see if it is a dynamic or fixed size. Select the disc from the “Storage” menu. Next to “Details,” you’ll notice what type of disc it is.
  • “Dynamically allocated storage,” for example, indicates that this is a dynamic disc.
Also See:  How to: Fix Windows Defender Error 0x800b0100

Step 2: In the Virtual Machine, write zeros to the disc.

Before continuing, make sure to erase any files you no longer desire from the virtual machine’s drive to free up space. Delete unnecessary files, delete apps you don’t use, and empty your Recycle Bin. After that, you’ll need to fill in the blanks with zeroes.

Guest Operating Systems for Windows

  • If the virtual machine has Windows installed, you should now boot it up and defragment the discs. Search for “Defragment” in the virtual machine’s Start menu and run the “Disk Defragmenter” or “Defragment and Optimize Drives” program.
  • Click “Defragment disc” after selecting the disc you want to shrink.

After the defragmentation procedure is complete, you must write zeros to the virtual machine’s vacant Space. VirtualBox cannot automatically shrink the drive because destroyed data is still saved on the disc when you delete files. However, if you write zeroes over the removed files, VirtualBox will notice a high number of zeroes—Space—and will be able to condense the disc.

  • To do so, go to Microsoft’s website and download the SDelete application. The sdelete.exe File should be extracted to a location on your PC.
  • To get started, open a Command Prompt window. To do so, go to the Start menu and type “Command Prompt” into the search box.
  • By typing cd, pressing Space, entering the path to the directory, then pressing Enter, you may go to the directory containing the sdelete.exe File. If the path contains a space character, it must be enclosed in quotation marks. This is how it should look:
cd "C:\path\to\folder"

If your Windows username is Bob and you extracted the sdelete.exe File to your user account’s download folder, you’d run the following command:

cd "C:\Users\bob\Downloads"

Type cd into the Command Prompt window, press Space, and drag and drop the folder icon from the file manager’s address bar to fill in the directory path.

Execute the command below:

sdelete.exe c: -z
  • This will fill all of the free disc space on drive C: with zeros. If you want to shrink a secondary drive in the virtual machine with a different drive letter, then c: the type that drives letter instead of c: This is exactly what the tool was made for. The -z option is “useful for virtual disc optimization,” according to Microsoft’s SDelete page.
  • Before continuing, you’ll be required to accept the tool’s license agreement. Select “Agree” from the drop-down menu.
  • Wait for the procedure to finish. When it’s finished, use the “Shut Down” option in the virtual machine’s Start menu to shut it down. It’s now time to condense it.

Guest Linux Operating Systems

You can bypass the defragmentation procedure and use built-in instructions to zero the free space on the drive if you have Linux installed in the virtual machine (a Linux guest operating system rather than a Windows guest operating system, in other words). The technique will be comparable to other Linux distributions. However, we’ll use Ubuntu as an example.

You’ll need to install the zero-free utility inside the virtual computer first, and it should be available in the software repository of your Linux system. For example, you may install it on Ubuntu by entering the following command into your virtual machine’s terminal:

sudo apt install zerofree

When you’ve booted into the conventional Linux environment, you can’t utilize zerofree on your / partition. Instead, you’ll want to boot into a unique recovery mode that disables the mounting of your standard root disc.

  • To access the Grub menu on Ubuntu, restart your virtual machine and continually hit the “Esc” key while it is booting. Select “*Advanced options for Ubuntu” from the Grub menu and click Enter.
  • Select the “(recovery mode)” option associated with the most recent Linux kernel—that is, the option towards the top of the list with the highest version number—and press Enter.
  • To boot to a root shell prompt, select “root” from the recovery menu.
  • When the message “Press Enter for maintenance” displays on your screen, press “Enter.” A terminal prompt will appear.

Run the following command from the command line to determine which virtual disc you wish to zero:

df

We can see that /dev/sda1 is our lone physical disc device in the output below. It’s the only disc with /dev/ in the leftmost column, so we know.

  • If you use the default options, your virtual machine will only have /dev/sda1, the first partition on the first hard drive.
  • You may need to zero another partition or many partitions if you’ve set things up differently with numerous discs or partitions.
  • Now it’s time to zero the disc. Replace /dev/sda1 with the partition’s device name you want to write zeros to in the following command. The majority of people will just set the /dev/sda1 device to zero.
zerofree -v /dev/sda1

Run the following command to shut down the virtual machine once the zero process is complete:

halt

The system has ceased, and you can now shut down your virtual machine when you see the “System halted” sign on your screen. Select “Power of the virtual machine” after closing the virtual machine’s window.

Also See:  How to Convert Between Fixed and Dynamic Disks in VirtualBox

Step 3: Locate the VBoxManage command.

The remaining steps will be completed on your host operating system outside of the virtual computer. If you had Windows 10 on your PC and Windows 7 in a virtual machine, for example, you’d complete the rest of the process on Windows 10.

  • The graphical interface of VirtualBox hides this option. You must instead use the VBoxManage.exe command.
  • To proceed, look for this command. It’s in the VirtualBox program directory on Windows, which is C:\Program Files\Oracle\VirtualBox by default. Instead, look in the place where you installed VirtualBox.
  • To get started, open a Command Prompt window. To do so, go to the Start menu and put cmd into the search box.
  • In the Command Prompt, type cd, then the path to the folder where the VBoxManage command is located. You’ll have to put it in quotations.
  • Type cd into the Command Prompt window, then drag and drop the folder icon from the file manager’s address bar into the Command Prompt.

If you’re following the default path, it should look something like this:

cd "C:\Program Files\Oracle\VirtualBox"

Note: These instructions are based on the assumption that you’re running VirtualBox on Windows. If you’re running VirtualBox on macOS or Linux, open a Terminal window and type the vboxmanage command like any other command.

Step 4: Find the path to the disc you’d like to compact.

To get a list of all the virtual hard discs on your computer, type the following command in the command prompt window:

VBoxManage.exe list hdds

Look through the list to find the virtual disc file path you wish to condense. Let’s imagine we wish to change the virtual disc connected with the “Windows 7” virtual machine. The path to that virtual disc on our machine is C:\Users\chris\VirtualBox VMs\Windows 7\Windows 7.vdi.

Step 5: Make the Disk Compact

To compress the disc, run VBoxManage.exe with the appropriate command. Run the command below, replacing the path to the disc VDI file with the disc on your system that you discovered with the command above. If the File’s path contains a space anywhere in it, make sure to wrap it in quotes.

This is how it should look:

VBoxManage.exe modifymedium disk "C:\path\to\disk.vdi" --compact

For example, since the path to the File is C:\Users\chris\VirtualBox VMs\Windows 7\Windows 7.vdi in our example, we’d run the following command:

VBoxManage.exe modifymedium disk "C:\Users\chris\VirtualBox VMs\Windows 7\Windows 7.vdi" --compact

VirtualBox will compact the disc, and, if desired, you can start the virtual computer right away. The amount of space you save is determined by how much vacant Space there was to restore.

Consider deleting snapshots as well.

You may make snapshots for each virtual machine in VirtualBox. These backups provided a complete image of the virtual machine when the snapshot was taken, allowing you to restore it to a previous state. These can eat up a lot of room.

Delete photos you don’t use to free up space. Select a virtual machine in the main VirtualBox window and click the “Snapshots” button to the right of Details on the toolbar to see the snapshots you’ve saved.

If you don’t need a snapshot anymore, right-click it in the list and choose “Delete Snapshot” to clear the Space.

Conclusion

I hope you found this information helpful. Please fill out the form below if you have any queries or comments.

User Questions:

  1. What is the procedure for resizing a VirtualBox disc?

In the main VirtualBox window, go to File> Virtual Media Manager to get there. Select a virtual hard disc from the list and adjust its size using the “Size” slider at the bottom of the window. When you’re finished, click “Apply.”

  1. Is it possible to minimize the size of the VMDK?

Virtual discs can be flattened such that they only take up as much space as the data they contain. VMware Converter and hosted products, such as VMware Workstation, are currently capable of thinning. See the vCenter Converter Standalone Documentation for your VMware product version for further information.

  1. How do I expand the size of my VirtualBox VM?

Go to View in the VM Window menu and ensure the Auto-resize Guest Display option is turned on. Change the size of the VM window by moving the mouse pointer over the corner and pressing the left mouse button.

Also See:  A Fan Created A Justice League Game Because Warner Bros. "Won't"
  1. The dynamically-sized discs in VirtualBox only grow in size.

VirtualBox’s dynamically-sized drives only increase in size from virtualbox

  1. How can I keep the virtual HDD consumption of a Windows 10 VM in VirtualBox to a minimum?

How to minimize virtual HDD usage of Windows 10 VM inside VirtualBox? from windows