How do I increase the hard disk size of the virtual machine?

723,592

Solution 1

Since VirtualBox 6, you can use the GUI, as per lenooh's answer.

Otherwise, open a terminal and navigate to the folder with the VirtualBox disk image, then use the following command:

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

replacing YOUR_HARD_DISK and SIZE_IN_MB with your image name and desired size. sudo might be necessary in some machines or you might encounter an error. This answer and a fuller explanation are here, on webupd8. Credit to Andrew there for posting this answer.

After resizing, the extra virtual hard drive space needs to be partitioned and formatted for the guest to use it. This can be done with gparted by booting the guest from a live ISO. We can also resize the existing partition using gparted. For this we may need to disable /swap and create a new swap partition.

In case if VBoxManage is not found in your system, just set the path to:

set PATH=%PATH%;"C:\Program Files\Oracle\VirtualBox" 

and it should resolve path issue. Do make sure VBoxManage is present at this path before setting it.

Solution 2

Since VirtualBox 6 we can use a GUI for resizing VMs' virtual disks.

To access it, click File -> Virtual Media Manager ...

The following window will open VirtualBox Virtual Media Manager

Select your disk, and click Properties. Now just move the slider at the bottom or write the value you want for the size and click "Apply" when you’re done.

After you start the virtual machine, Windows will not recognize the new space.

In Windows, open Computer Management (search for it in the start menu), select Storage -> Disk Management in the left menu (In Windows 10 you can find it as create and format hard disk partitions directly from the start menu). Select your partition (probably C:), right-click on it, and select Extend Volume .... Now just click through the wizard and you're done.

Note that on your VM Windows might not detect the extra space if you have snapshots in your VM. To fix this, it is recommended that you delete the snapshots or (the easiest way) just clone it and perform the resize in the new one.

Solution 3

The following worked for me:

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

However, I understand how mileage can vary :-) As far as resizing the partition, in Windows 7, I was able to resize at the screen you showed by right clicking on the C: drive in the bottom panel and selecting extend volume.

Computer management screen

Solution 4

Wim, I think you'll need to unregister it from Vbox first. File, Media Manager, Click on you hdd, and unregister it. Then try it again.

Solution 5

If you are on Windows host and trying to increase the size of Ubuntu's VDI size then the following information can help you:

Get your full path of vdi, for me, it was "D:\VirtualBoxImages\Ubuntu\Ubuntu.vdi".

enter image description here

Run the command mentioned in the "Marked as answered" post:

"C:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd D:\VirtualBoxImages\Ubuntu\Ubuntu.vdi --resize 40000" 

enter image description here

Above, "C:\Program Files\Oracle\VirtualBox" is the location of the folder where my Windows Virtual Box is installed, 40000 is 40 GB in the above command.

After doing the above-mentioned step, restart the Ubuntu VM.

Go to "Disks"

enter image description here

Resize the existing partition to make it 40 GB:

enter image description here

You can then confirm from the "Storage" that the above operation worked:

enter image description here

Share:
723,592
wim
Author by

wim

Hi from Chicago! Python dev with interest in mathematics, music, robotics and computer vision. I hope my Q&A have been helpful for you. If one of my answers has saved your butt today and you would like a way to say thank you, then feel free to buy me a coffee! :-D [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*

Updated on September 18, 2022

Comments

  • wim
    wim over 1 year

    enter image description here

    I have run out of space on my WinXP virtual machine, which I only gave 10 GB space for when I created it. Is there an easy way to increase it to, say, 20 GB? I can't see any obvious option in VirtualBox settings.


    The suggestion below gives this error

    wim@wim-ubuntu:/media/data/winxp_vm$ VBoxManage modifyhd wim.vdi --resize 20000
    VBoxManage: error: Cannot register the hard disk '/media/data/winxp_vm/wim.vdi' {46284957-2c09-4e70-8a49-bfbe0f7f681d} because a hard disk '/home/wim/VirtualBox VMs/winxp_vm/wim.vdi' with UUID {46284957-2c09-4e70-8a49-bfbe0f7f681d} already exists
    VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
    Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 210 of file VBoxManageDisk.cpp
    

    Removing the .vdi from VirtualBox before calling VBoxManage command, then adding it back in, was successful. But now I can't boot the virtual machine, I get this worrying screen:

    enter image description here

    By the way, it says FATAL: Could not read from the boot medium! System halted.


    The vdi must be reattached to the VM after VBoxManage command. Further, the partition will need to be resized from WITHIN windows, because you will have this empty space:

    enter image description here

    I was able to resize the partition easily using a bit of freeware called EASEUS Partition Master 9.1.0 Home Edition.

    • stolsvik
      stolsvik about 11 years
      Your problem is that you've symlinked the disk to a '/media/data' location and that it doesn't reside on the original '/home/wim/VirtualBox VMs' location. I've answered with how I fixed this.
    • kmonsoor
      kmonsoor over 9 years
      i have detailed my experience here: kmonsoor.wordpress.com/2012/05/26/virtualbox-increase-disk-s‌​ize the "accepted" answer below is way far from being even right.
    • parasrish
      parasrish about 6 years
      There is another possibility of "copying the existing vdi" to a "new empty vdi, whose size is bigger than existing" (refer- justintung.com/2011/01/06/… )
    • parasrish
      parasrish about 6 years
      also, note that, just resizing might not help, as the "vdi" size would have increased, but based on the "vm-os-installation", your primary partition stays the same, and the newly allocated space is typically shown "unallocated". You need to hence do the "partition re-allocation" (Refer the link above).
    • Eric
      Eric about 3 years
  • wim
    wim over 12 years
    unfortunately it does not work.. see my edit
  • Sanam Patel
    Sanam Patel over 12 years
    Sorry that didn't work. Judging from the comments over there it looks like it only works some of the time. Hopefully someone more experienced can reply here or over on webupd8. Don't bother trying to clone the .vdi either, you can't specify a larger partition. I just tried and all you can do is an exact clone. Just a thought, did you do a fixed 10GB initially, or dynamically expanding storage? That might be a clue.
  • wim
    wim over 12 years
    iirc it was dynamic
  • Jonik
    Jonik over 12 years
    +1. Just used this to increase the size of my Windows 7 disk from 20 to 30 GB, and it worked very smoothly (no unregistering etc needed). $ VBoxManage modifyhd Windows7.vdi --resize 30720 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...1‌​00% At first Windows didn't detect the increased space, but after a poweroff it did, and then I was able to use the built-in Disk Management tool to increase the size of my C: partition.
  • Lekensteyn
    Lekensteyn about 12 years
    sudo is not necessary. It may corrupt permissions in your home directory, requiring you to use sudo for virtualbox which is a bad idea.
  • Richard Povinelli
    Richard Povinelli about 12 years
    @Lekensteyn: Good to know that it is not necessary. I used it because others had said it didn't work without being root. As far as permission corruptions go, chmod works well to fix such mistakes.
  • Richard Povinelli
    Richard Povinelli about 12 years
    @Lekensteyn: chown will fix ownership mistakes. I mention chmod and chown, because I have had to fix the problem you are referencing many times :-)
  • Starx
    Starx about 12 years
    +1, This is certainly the cleanest way to do it.
  • Sanam Patel
    Sanam Patel over 11 years
    Can you please explain the steps here? Answers with little more than a link to another site are generally frowned up here, and may be deleted.
  • szx
    szx over 11 years
    My Windows 7 VM can't see any changes in disk size even after second reboot (yes, in Computer Management) but Settings/Storage shows the new value. Any ideas why?
  • Bruno
    Bruno over 11 years
    @asd Changing the disk size isn't enough, you also need to resize the partition.
  • Jon
    Jon about 10 years
    This is great for Windows, but if you have a Linux guest OS this link can help with re-sizing the partitions: forums.virtualbox.org/viewtopic.php?f=35&t=50661
  • Bob
    Bob over 9 years
    What about if the path to the HARD_DISK.vdi contains blank spaces ? I get errors. Is there a way to type correctly the path ?
  • Sanam Patel
    Sanam Patel over 9 years
    @begueradj Sure, put a \ (backslash) character before any spaces in the path, like this: /PATH/HARD\ DISK.vdi.
  • Ajith R Nair
    Ajith R Nair over 7 years
    If you are running windows inside linux you need to follow this options , and extend the disk, otherwise windows wont add the additional space we added
  • Jonathan
    Jonathan over 7 years
    Did you have to reinstall / reformat / repartition? or did it just boot right back up?
  • Jonathan
    Jonathan over 7 years
    Some people reported this causes the home dir to have bad permissions
  • Travis van der Font
    Travis van der Font over 7 years
    THIS WILL WORK! However, you need to increase the partition after so windows can register the new space. Best and quickest / easiest method: howtogeek.com/howto/windows-vista/…
  • Underverse
    Underverse over 7 years
    Not required on Linux in VirtualBox. Just had to shut down the guest OS completely first.
  • Dewsworld
    Dewsworld almost 7 years
    I used sudo before VBoxManage and it worked
  • marijnz0r
    marijnz0r almost 7 years
    This worked for me, followed the guide here: yinfor.com/2015/05/…
  • Neurotransmitter
    Neurotransmitter over 6 years
    I think in recent versions of VirtualBox it is .\VBoxManage.exe modifymedium disk 4d30d154-f8c2-4a3b-bd8b-ddcfbfe64aaf --resize 30720 now. modifyhd is also works though — there is a backward compatibility with older commands.
  • ollydbg23
    ollydbg23 over 6 years
    I just resize the vdi file size from 25G to 120G, but Windows7 system's disk-manager still can't see the unallocated space. Is is caused by a snapshot file(I have a snapshot before), but when I try to delete the snapshot, virtualbox report crashes, so I can't delete the snapshot. Any ideas? My guest win7 still see 25G. thanks.
  • ollydbg23
    ollydbg23 over 6 years
    OK, I finally delete the snapshot, and now start win7, I see it has some 97G extra unallocated spaces, thanks.
  • CGFoX
    CGFoX over 6 years
    VBoxManage is in your installation folder of VirtualBox
  • parasrish
    parasrish about 6 years
    you can validate the increased size by the command : VBoxManage.exe showhdinfo <image_with_path.vdi> There you see the before and after size in the "Capacity:" section.
  • AlwaysLearning
    AlwaysLearning about 6 years
    Worked great. Shouldn't this be the accepted answer, at least for the recent versions of VirtualBox?
  • Royi
    Royi about 5 years
    Do you need to do Release before that? As currently the slider is grayed. Or did you chose dynamic partition?
  • Royi
    Royi about 5 years
    You should add this will work only on Dynamic Size Partitions. See askubuntu.com/questions/539924.
  • lenooh
    lenooh about 5 years
    Royi: when you make the virtual disk, make sure it has a dynamic size.
  • nick-s
    nick-s almost 5 years
    On Mac, VBoxManage is in cd /Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM‌​.app/Contents/MacOS/
  • Manuel Jordan
    Manuel Jordan over 4 years
    @TomBrossman consider to indicate that modifyhd is old and is replaced by modifymedium. The former is still valid for compatibility purposes virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi
  • Manuel Jordan
    Manuel Jordan over 4 years
    Good to know the GUI approach. Of course the command way works too.
  • Lasith Niroshan
    Lasith Niroshan over 4 years
    Also, this solution worked for macOS. thanks for sharing...
  • Jamie Hutber
    Jamie Hutber over 4 years
    This should be the accepted answer. All the others you lose your install and have to format the drive!!!
  • R2-D2
    R2-D2 almost 4 years
    I was using this sucessfully before, but this time it bricked my Ubuntu 20 VM.
  • Robin
    Robin over 3 years
    Seems to be a more complicated story for ubuntu though. I am trying export OCI and then create a new VM to try to get round the deletion of partitions etc.
  • Tim
    Tim over 3 years
    How do you update size when the VM is ubuntu?
  • lenooh
    lenooh over 3 years
    Tim: use the same procedure for Virtualbox, and then in Ubuntu use gparted for example.
  • Pikamander2
    Pikamander2 about 3 years
    @Tim - See Raghav's answer below.
  • run_the_race
    run_the_race almost 3 years
    Very helpful, Ubuntu did not detect the increase in file size.
  • robert
    robert almost 3 years
    I had to use gparted-live iso and do the resize from there as I got an error from Ubuntu 21.04
  • Sagar M
    Sagar M over 2 years
    Read this link itsfoss.com/increase-disk-size-virtualbox this worked for me
  • Chris G
    Chris G over 2 years
    Thanks, this is the only correct answer!
  • baptx
    baptx over 2 years
    The "Extend Volume" option was greyed out so I could not select it. I read it can be because there is another partition between (recovery partition in my case) and to extend the volume, the unallocated space should be next to the volume we want to extend: diskpart.com/windows-10/… I used a GParted live CD to move the partition and then I was able to extend the volume in Windows.
  • lenooh
    lenooh over 2 years
    baptx: recovery partition in a Virtual Box virtual disk? Are you sure you were resizing a virtual disk? 😃
  • parliament
    parliament about 2 years
    Don't use this answer it bricked my VM and had to start over. Use the 2nd answer by lenooh
  • Admin
    Admin about 2 years
    Indeed, very helpful, I was missing that step in which I am supposed to increase the disk space on the Ubuntu virtual machine.