1. Launch VirtualBox and highlight the virtual machine that you will be editing in the pane on the left side of the application window.
2. Click the Settings button in the ribbon at the top of the application window.
3. In the dialog box that appears, navigate to Storage on the left, then click on your VDI to view its properties.
4. As you can see from the image above, this VDI is dynamically allocated. This is what we need. Now that we have verified that our VDI is dynamically allocated, we need to back up our VDI in case the resizing fails and destroys our data. In the dialog box that appeared in step 3, navigate to the VDI information section that we opened and right-click on the Location line. This will offer the option to copy the path, which we need to do.
5. With the path to our VDI copied to our clipboard, we can proceed. We need to detach the VDI from the virtual machine now, so click on the minus button beneath the storage device list in the dialog box.
6. The VDI for your virtual machine should disappear from the storage device list as mine has in the image below.
7. Next we need to open a terminal on our Ubuntu 18.04 LTS host machine. With the terminal open, enter the following command,
cp <my-vdi-location> ~
8. The process will take awhile since we are copying a large amount of data. The prompt will return to the terminal when the process has completed. When the prompt returns, we can enlarge our VDI by entering the following command. Make sure to replace <my-vdi-location> by pasting the path to your VDI that you copied in step 4 and replace <new-vdi-size> with the new, desired size, specified in megabytes.
vboxmanage modifyhd <my-vdi-location> --resize <new-vdi-size>
9. When complete, the output of the previous command looks like this:
10. Next, we need to return to the VirtualBox Manager application. With Storage selected in Settings, click on Controller: SATA in the storage device list to highlight it, then click the plus button beneath the storage device list to add your resized VDI. In the dropdown menu, choose Add Hard Disk.
11. A new dialog box will appear. We want to choose an existing disk, so select that option in the dialog box, then select you new, resized VDI.
12. When re-attached, the VDI will show in the storage device list like the image below.
13. We have successfully resized our VDI and reattached it to our virtual machine, but the guest operating system still will not be able to use the newly allocated space. We will need to boot our virtual machine from a live Linux distribution containing GParted so that we can resize the file system. To do this, click on the button with the CD and green plus button next to Controller: SATA. This will allow us to add another optical drive with our live Linux distribution. For this tutorial, I will use Ubuntu 18.04 LTS as the live Linux distribution because it contains GParted preinstalled.
14. After clicking the add disk button, a new dialog appears. Select Choose disk and select your live Linux distribution containing GParted.
15. Highlight the newly added optical disk and select the Live CD/DVD on the right.
16. Next, select System from the pane on the left and ensure that Optical is first in the boot order. The boot order should look similar to this:
17. Finally, click OK to exit the Settings dialog.
18. Now we can boot our virtual machine into our live Linux distribution by highlighting our virtual machine and clicking Start on the ribbon at the top of the application.
19. If you are using Ubuntu 18.04 LTS as your live distribution, select Try Ubuntu when this view loads:
20. After Ubuntu 18.04 LTS live has loaded, open GParted.
21. Notice the new, unallocated space in the grey portion in the image above. We will now configure the virtual machine to use that space in addition to the currently occupied space. Right click on the occupied space in white in GParted at the top of the application. From the dropdown menu that appears choose Resize/Move.
22. A new dialog box appears showing both occupied and unallocated space. Move the slider all the way to the right to use all of the space, then click the Resize/Move button on the bottom of the dialog box.
23. To apply our changes to the filesystem, click the green check mark in the ribbon at the top of the GParted application.
24. Click Apply in the confirmation dialog box that appears.
25. After a moment the operation completes and returns a success message. Close the message, close GParted, and then poweroff the live Linux distribution. We are now finished with resizing.
26. Now we need to open Settings and navigate to Storage again. Highlight your virtual machine and click the Settings button on the top of the VirtualBox Manager application.
27. Navigate to Storage in the left pane of the Settings dialog. Click on the optical device containing the live Linux distribution iso to highlight it, then click the minus button below the storage devices list to remove the optical device.
28. Select Remove from the confirmation dialog box that appears.
29. Click the OK button at the bottom of the Settings dialog to save the changes and close the dialog.
30. Finally, reboot your machine and verify that the new, additional space has been added. As you can see from the image below, after booting my Windows 10 virtual machine and opening the disk management console, I now have all of the additional storage I allocated available to my virtual machine.