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.
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):
Now yes! With this file information .VDI, just run the command:
VBoxManage modifyhd D:\VMUbuntuUbuntu.VDI --resize 20480
– 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:
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:
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!
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:
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.
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:
And that's, This made!