How to Increase the Disk Size of a Virtual Machine in VirtualBox

How to Increase the Disk Size of a Virtual Machine in VirtualBox

Virtual machines (VMs) are a fantastic way to run different operating systems on a single machine. One popular tool for creating and running VMs is VirtualBox, an open-source software that’s easy to use and packed with features. However, as you use your virtual machine, you might run out of disk space. Luckily, VirtualBox allows you to increase the disk size of your virtual machine. In this guide, we’ll walk through how to do it step by step.

Step 1: Backup the Virtual Machine

Before you make any changes, it’s essential to back up your virtual machine. Increasing the disk size involves some modifications, and it’s better to be safe than sorry. If something goes wrong, a backup ensures you don’t lose any data. You can simply copy the entire virtual machine folder to a safe location.

  1. Open VirtualBox and locate the virtual machine you want to modify.
  2. Right-click the virtual machine name, and select Show in Explorer (Windows) or Show in Finder (macOS).
  3. Copy the virtual machine folder and store it on another drive for safekeeping.

Step 2: Power Off the Virtual Machine

You cannot resize a virtual disk if the virtual machine is running. Make sure that the virtual machine is completely powered off, not in a saved state.

  1. Select the virtual machine in VirtualBox.
  2. Click on Machine in the top menu.
  3. Choose ACPI Shutdown or click Power Off to ensure it is off.

Step 3: Open VirtualBox Command Prompt (VBoxManage)

VirtualBox doesn’t have an option to resize the disk in the graphical user interface (GUI). Instead, you’ll use the command-line tool called VBoxManage, which comes bundled with VirtualBox.

  1. Open the Command Prompt (Windows) or Terminal (macOS/Linux).
    • On Windows, press Win + R, type cmd, and hit Enter.
    • On macOS or Linux, open Terminal from your Applications folder or system menu.
  2. Navigate to the folder where VirtualBox is installed:
    • On Windows, it’s typically located in C:\Program Files\Oracle\VirtualBox\.
    • On macOS/Linux, the VBoxManage tool should already be available without specifying a directory.

Step 4: Locate the Virtual Disk File

Before resizing, identify the path to your virtual machine’s disk file. The disk file typically has a .vdi or .vmdk extension, depending on the format used.

  1. Go to VirtualBox, right-click your virtual machine, and select Settings.
  2. Click on Storage in the left-hand pane.
  3. Under Controller: SATA, you will see the hard disk file used by your virtual machine. Make note of its location and name.

Step 5: Resize the Virtual Disk Using VBoxManage

Now, you’re ready to resize the virtual disk using the VBoxManage command. This command will increase the size of the disk but not automatically allocate the space to the guest operating system.

1.In the command prompt, type the following command:

VBoxManage modifyhd "[path_to_disk_file]" --resize [new_size_in_MB]

    • Replace [path_to_disk_file] with the full path to your virtual disk file.
    • Replace [new_size_in_MB] with the desired new size in megabytes (e.g., 20480 for 20 GB).

For example:

VBoxManage modifyhd "C:\Users\User\VirtualBox VMs\MyVM\MyVM.vdi" --resize 40960

This command would resize the disk to 40 GB.

  1. Once the command is executed, you should see a confirmation message in the terminal.

Step 6: Extend the Partition in the Guest Operating System

At this point, the virtual disk size has increased, but your guest operating system (the OS running inside the virtual machine) won’t recognize the new space yet. You must extend the partition to use the extra disk space.

For Windows Guests:

  1. Boot the virtual machine.
  2. Once inside, open Disk Management by pressing Win + X and selecting Disk Management.
  3. In the Disk Management window, you will see unallocated space next to your main partition.
  4. Right-click your main partition (usually labeled C:), and select Extend Volume.
  5. Follow the wizard to allocate the unallocated space to the partition.

For Linux Guests (Ubuntu as an Example):

  1. Boot your virtual machine.
  2. Open the terminal.
  3. Check the current disk partitions by typing:
sudo fdisk -l

4. You’ll see the current disk structure. To resize the partition, use a tool like GParted or resize the partition manually.

To install GParted, run:

sudo apt-get install gparted

    • After installation, open GParted and select the main partition.
    • Right-click it, select Resize/Move, and drag to allocate the unallocated space.
  1. After resizing, apply the changes.

Step 7: Confirm the Changes

Once you’ve extended the partition in your guest operating system, verify that the system now recognizes the full disk size.

For Windows Guests:

  1. Open This PC or File Explorer and check the available disk space.

For Linux Guests:

  1. In the terminal, type:
df -h

  1. This command shows disk usage. You should see the newly extended partition listed with the correct size.

Troubleshooting Tips

  • If you encounter errors during the resize process, ensure that the virtual machine is powered off. Resizing won’t work if the machine is running or in a suspended state.
  • If you’re using a snapshot of the VM, you might need to delete or merge it before resizing the disk. Snapshots can complicate the process.
  • If the guest OS doesn’t show the extra space, double-check the partition and make sure you’ve extended it correctly.

Conclusion

Increasing the disk size of a virtual machine in VirtualBox involves several steps, but it’s a manageable process. Start by resizing the virtual disk using the VBoxManage command, then extend the partition within the guest OS to make use of the additional space. Always back up your data before making any significant changes, and remember to power off your virtual machine before starting. By following this guide, you can easily increase your virtual machine’s storage capacity without losing any important files.

This process works for most modern operating systems and can be repeated if more space is needed in the future.

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: