Increase the size of the disk in VirtualBox

From a Windows 10, How to expand the disk of a virtualized Ubuntu Linux (.VDI) using Oracle VM VirtualBox? See how in 2 steps!

virtualboxlogo

Problem

When you have a virtualized operating system, It is common to Miss disk space after successive updates.

This post depicts the following scenario: from a Windows 10, We will expand the virtualized Ubuntu Linux (.VDI) Oracle VM VirtualBox.

Solution

In summary, all you need to do is run a command via Terminal (CMD) for (Step 1) increase the size of the virtual disk and (Step 2) then expand the partition with Gparted. Come on.:

Step 1 | Increase the size of the virtual disk of your VM

1.1 Open the Terminal CMD as administrator
For this, type in the search of Windows “CMD” and when you see the option Command Prompt, click it with the right button and select “Run as administrator“.

1.2 Go to the installation directory of your VirtualBox
In CMD, Select the installation directory of your VirtualBox, by default in (C):\Program FilesOracleVirtualBox:

  CD C:\Program FilesOracleVirtualBox

1.3. Run the command to increase the size of the virtual disk of your VM

Before however, If you don't know where your VM is physically saved on the computer, just take a look at VirtualBox and look for a file .VDI, as follows:

Settings > Storage > SP: SATA > [SuaVM].VDI > Information > Location (Example: (D):\VMUbuntuUbuntu.VDI)

The address for your .VDI It's on the label “Location” ((D):\VMUbuntuUbuntu.vdi):
vmbox2

Now yes! With this file information .VDI, just run the command:

  VBoxManage modifyhd D:\VMUbuntuUbuntu.VDI --resize 20480

Note:
– Replace “(D):\VMUbuntuUbuntu.vdi” the path to your. vdi. In this example I'm increasing the 20 GB disk (20GB x 1024 MB = 20480).
– Note that initially the “Virtual Size” is 12 GB and at the end we will reach the desired 20 GB.

See then how did all the STEP 1:
vmbox1

 

Step 2 | Expand the partition on any disk created

Understand the solution:
It may seem strange, but the fact that you now have a larger disk, does not mean that the file system is taking up all this space available.

Take a look at the picture below and see the disk. Note that has 8 GB free, that is precisely the space that we increase, only that's not busy:

vmbox3

The question here is: How to join those 11 GB with 8 GB if the partition “extended + swap” is right in the Middle?

Well, to solve this, you will delete (and then recreate) the partition swap and extended using the Gparted.

2.1 Install GParted
In search of Ubuntu, look for “Software”. Click the Ubuntu Software and search for Gparted, So, install it!
vmbox4

2.2 Remove the Swap partition + Extended

Without fear, remove the partition Swap and after the Extended that is between the original partition your (full) and the new space created (empty), so that it is a large block of unallocated space, as shown in the figure below:
vmbox5

2.3 Expand the original partition
Using the graphics of GParted (Resize/Move), position the mouse in the division between the partitions, and then drag the original partition (from left to right) about the unallocated space, leaving only a space to later recreate the swap.

In my case, I left at the end of the unallocated space (empty), a 2048 MB space to recreate swap, represented by the light blue outline in figure above.

2.4 Re-create the extended partition + Swap
Click the unallocated space that you reserved and so first create an extended partition and then a Swap.

vmbox7

Checking the result

Comparing the figures of the beginning of the Post with the pictures below, We see that both the Disk Manager of Ubuntu as Virtual Box indicate that we got the expected result.

Ubuntu Disk Manager:
vmbox9

Virtual Box:
vmbox8

And that's, This made!

Total hits: 15653

19 comments on “Increase the size of the disk in VirtualBox

      • Alex said:

        Its because the way (path) of your virtual machines contains white space. I had the same problem and solved it by taking the space, and after the procedure, reattached the space, otherwise the VirtualBox does not see the location of the machines.
        Example:
        (C):\UsersadminVirtualBox VMSWindowsWindows.vdi
        Go to the folder, Rename and remove the blank space. Then leave it the command:
        (C):\UsersadminVirtualBoxVMSWindowsWindows.vdi
        At the end of, Rename again and replace the blank space in the folder.

  1. Fernando Tremonti said:

    This way no roll:

    (D):\Program FilesOracleVirtualBox>VBoxManage modifyhd D:\VirtualBoxVMsDesenvolvimentoDesenvolvimento.vdi –resize 51200
    VBoxManage.exe: error: Cannot register the hard disk ' D:\VirtualBoxVMsDesenvolvimentoDesenvolvimento.vdi’ {0d46624b-3753-40d0-a025-9f1f784e9885} because the hard disk ' D:\VirtualBox VMsDesenvolvimentoDesenvolvimento.vdi’ with UUID {0d46624b-3753-40d0-a025-9f1f784e9885} already exists
    VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component VirtualBoxWrap, IVirtualBox interface, callee IUnknown
    VBoxManage.exe: error: Context: “OpenMedium(BSTR(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pmedium. asOutParam())” at line 179 of file VBoxManageDisk.cpp

    Any tips?

    • Francisco said:

      Try this way:
      VBoxManage modifyhd “(D):\VirtualBoxVMsDesenvolvimentoDesenvolvimento.vdi” –resize 51200

      That's two hyphens for flag “–resize”

  2. Thiago said:

    Here the part of increasing physical HD worked, virtual box shows the selected size, but when I enter the VM HD continues with the old size… Even the GParted does not show the new size for a spare or anything.

  3. Gabriel Garcia said:

    Guys you're having the problem of invalid parameter

    “Syntax error: Invalid parameter ' VMsUbuntuUbuntu.vdi '”

    Just put the path String, IE, double quotation marks!!

    Thanks!

  4. Nilson said:

    Thanks for the help mate, saved me in my work, because the restoration by Acronis I used this 15 GB the detail and I updated all the Windows and the net here in the region of bad…..

  5. Thiago SIlva said:

    Gentlemen,

    I'm trying to perform this procedure and execute pops up the error below:

    (No quotes)
    (C):\Program FilesOracleVirtualBox>VBoxManage modifyhd C:\UsersThiagoDocuments
    \VirtualBoxVMsWindows7Windows7.vdi –resize 102400
    VBoxManage.exe: error: Cannot register the hard disk ' C:\UsersThiagoDocuments
    VirtualBoxVMsWindows7Windows7.vdi’ {b3c1079d-ebde-4a24-b10a-16d41a723da7} Beca
    Use hard Disk'c:\UsersthiagoDocumentsVirtualBox VMsWindows 7 Windows 7. VD
    (I)’ with UUID {b3c1079d-ebde-4a24-b10a-16d41a723da7} already exists
    VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component Virtua
    lBoxWrap, IVirtualBox interface, callee IUnknown
    VBoxManage.exe: error: Context: “OpenMedium(BSTR(pszFilenameOrUuid).raw(), enmDe
    vType, enmAccessMode, fForceNewUuidOnOpen, pmedium. asOutParam())” at line 179 of
    file VBoxManageDisk.cpp

    (With quotes)
    (C):\Program FilesOracleVirtualBox>VBoxManage modifyhd “(C):\UsersThiagoDocument
    sVirtualBoxVMsWindows7Windows7.vdi” –resize 102400
    VBoxManage.exe: error: Cannot register the hard disk ' C:\UsersThiagoDocuments
    VirtualBoxVMsWindows7Windows7.vdi’ {b3c1079d-ebde-4a24-b10a-16d41a723da7} Beca
    Use hard Disk'c:\UsersthiagoDocumentsVirtualBox VMsWindows 7 Windows 7. VD
    (I)’ with UUID {b3c1079d-ebde-4a24-b10a-16d41a723da7} already exists
    VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component Virtua
    lBoxWrap, IVirtualBox interface, callee IUnknown
    VBoxManage.exe: error: Context: “OpenMedium(BSTR(pszFilenameOrUuid).raw(), enmDe
    vType, enmAccessMode, fForceNewUuidOnOpen, pmedium. asOutParam())” at line 179 of
    file VBoxManageDisk.cpp

    and the same error occurs, can help in this case?

    • Francisco said:

      Try this way:

      VBoxManage MODIFYHD "C:\UsersThiagoDocumentsVirtualBoxVMsWindows7Windows7.vdi " –resize 102400

      That's two hyphens for flag “–resize”

Leave a reply

The your email address will not be published. Required fields are marked with *