This How To will walk you through expanding the virtual hard drive size of a guest Windows 10 virtual which is being hosted on an Ubuntu 20.04 machine running Virtualbox 6.1.
There are three sections to this guide.
Section I is work that needs done from a Terminal Window inside your Linux Host System and from inside the Virtualbox 6.1 program.
Section II is work that needs done from inside you virtual Windows 10.
Section III is work done inside your virtual Windows 10 in an Admin Command Prompt but only needs done if you encounter certain problems in Section II.
------------------------------------------------------------------------------------------------------------------
1. Make sure your virtual is shut off.
2. Locate your Windows 10 virtual image file (.vdi). Mine is located in "/Home/username/VirtualBox VMs/Windows 10 Home/Windows 10 Home.vdi"
3. Make a backup copy of the .vdi file and put it in a safe place (this will take a little time since it is probably several gigs in size, mine was 60gb).
4. Open Virtualbox (not your virtual Windows 10, but Virtualbox itself).
5. Once in Virtualbox, Right Click on your Windows 10 virtual and select SETTINGS.
6. In settings, select STORAGE, then Right Click on your .vdi file (mines called "Windows 10 Home.vdi") and then click on the REMOVE ATTACHMENT.
NOTE: Don't worry this does not delete anything it just disconnects it from this virtual. Think of it as taking the hard drive out of your computer, you can put it back in whenever you want, nothing is lost)
8. With the .vdi file detached, close Virtualbox.
9. Open a Terminal Window and navigate to the location where your .vdi file is located (Mine is in /Home/username/VirtualBox VMs/Windows 10 Home/Windows 10 Home.vdi) (from Step 2).
10 Once you are in the same folder as your .vdi file, type the following into your Terminal Window.
vboxmanage modifyhd "NameOfYourVDIfile.vdi" --resize 128000
NOTE: You will need to replace "NameOfYourVDIfile.vdi" with the actual name of your .vdi file. The 128000 at the end is the new size you want your virtual hard drive to become. This number is in megabytes (mb) so in this case 128000 mb equals 128gbs. This number has to be bigger than your original virtual hard drive size (you can't make it smaller this way) and has to be able to fit in your actual physical hard drive's free space (this is your physical computer's physical hard drive).
11. Once you've made the changes needed to the above command, hit ENTER. You will then see something that looks like this:
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
SECTION III
If you encountered a 4th partition named Windows Recovery in Section II and it was between your C: and Unallocated partitions, you can not combine the two (C: and Unallocated) without removing the Windows Recovery Partition. If the option to EXTEND VOLUME is grayed out on your C: partition, removing the Recovery Partition is the only way I know of to proceed. We will need to do this from an Admin DOS Command Prompt from within the virtual Windows 10. Here's how:
1. From within the virtual Windows 10
Right-click the Start Menu and select Command Prompt (Admin).
2. Type diskpart and press Enter.
3. Type list disk and press Enter.
(A list of disks will be displayed.)
4. Type select disk # and press Enter.
(Replace # with the number of the disk containing the recovery partition)
5. Type list partition and press Enter.
(A list of partitions will be displayed.)
6. Type select partition # and press Enter.
(Replace # with the number of the recovery partition)
7. Type delete partition override and press Enter.
After the confirmation message, you can close the DOS Command Prompt and go back to Section II and finish those steps.