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.
- Open VirtualBox and locate the virtual machine you want to modify.
- Right-click the virtual machine name, and select Show in Explorer (Windows) or Show in Finder (macOS).
- 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.
- Select the virtual machine in VirtualBox.
- Click on Machine in the top menu.
- 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.
- 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.
- 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.
- On Windows, it’s typically located in
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.
- Go to VirtualBox, right-click your virtual machine, and select Settings.
- Click on Storage in the left-hand pane.
- 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).
- Replace
For example:
VBoxManage modifyhd "C:\Users\User\VirtualBox VMs\MyVM\MyVM.vdi" --resize 40960
This command would resize the disk to 40 GB.
- 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:
- Boot the virtual machine.
- Once inside, open Disk Management by pressing Win + X and selecting Disk Management.
- In the Disk Management window, you will see unallocated space next to your main partition.
- Right-click your main partition (usually labeled C:), and select Extend Volume.
- Follow the wizard to allocate the unallocated space to the partition.
For Linux Guests (Ubuntu as an Example):
- Boot your virtual machine.
- Open the terminal.
- 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.
- 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:
- Open This PC or File Explorer and check the available disk space.
For Linux Guests:
- In the terminal, type:
df -h
- 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.
Thank you for reading the article! If you found the information useful, you can donate using the buttons below:
Donate ☕️ with PayPalDonate 💳 with Revolut