359

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.

5
  • 3
    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.
    – stolsvik
    Apr 9, 2013 at 15:35
  • 1
    i have detailed my experience here: kmonsoor.wordpress.com/2012/05/26/virtualbox-increase-disk-size the "accepted" answer below is way far from being even right.
    – kmonsoor
    Oct 8, 2014 at 16:25
  • 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
    Apr 11, 2018 at 5:22
  • 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).
    – parasrish
    Apr 11, 2018 at 9:25
  • howtogeek.com/124622/…
    – Eric
    Mar 23, 2021 at 10:59

15 Answers 15

398

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.

23
  • 24
    +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%...100% 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.
    – Jonik
    Dec 22, 2011 at 10:05
  • 3
    +1, This is certainly the cleanest way to do it.
    – Starx
    May 3, 2012 at 15:08
  • 24
    @asd Changing the disk size isn't enough, you also need to resize the partition.
    – Bruno
    Nov 7, 2012 at 18:44
  • 9
    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. Sep 6, 2017 at 19:04
  • 3
    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
    Sep 7, 2017 at 3:25
160

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

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

Version 7: in File -> Tools ->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.

11
  • 1
    Do you need to do Release before that? As currently the slider is grayed. Or did you chose dynamic partition?
    – Royi
    Apr 17, 2019 at 10:38
  • 7
    This should be the accepted answer. All the others you lose your install and have to format the drive!!! Nov 15, 2019 at 1:16
  • 3
    How do you update size when the VM is ubuntu?
    – Tim
    Dec 8, 2020 at 19:43
  • 1
    Thanks, this is the only correct answer!
    – ChrisG
    Sep 8, 2021 at 18:19
  • 1
    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.
    – baptx
    Nov 16, 2021 at 17:30
32

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

5
  • 13
    sudo is not necessary. It may corrupt permissions in your home directory, requiring you to use sudo for virtualbox which is a bad idea.
    – Lekensteyn
    Apr 15, 2012 at 12:01
  • 1
    @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. Apr 15, 2012 at 12:05
  • @Lekensteyn: chown will fix ownership mistakes. I mention chmod and chown, because I have had to fix the problem you are referencing many times :-) Apr 15, 2012 at 12:19
  • 3
    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
    – Jon
    Mar 29, 2014 at 21:35
  • 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 Aug 17, 2016 at 13:52
25

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

4
  • 2
    Very helpful, Ubuntu did not detect the increase in file size. Jul 25, 2021 at 18:28
  • 1
    I had to use gparted-live iso and do the resize from there as I got an error from Ubuntu 21.04
    – robert
    Aug 3, 2021 at 14:52
  • Indeed, very helpful, I was missing that step in which I am supposed to increase the disk space on the Ubuntu virtual machine.
    – HanniBaL90
    Apr 28, 2022 at 7:52
  • 6
    just doesn't seem to work in ubuntu 21.04 - asks for authentication after clicking resize then nothing happens
    – niico
    Sep 17, 2022 at 13:33
19

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.

1
  • 4
    Not required on Linux in VirtualBox. Just had to shut down the guest OS completely first.
    – Underverse
    Feb 4, 2017 at 9:23
12

After resizing and not being able to view the resizing on my windows XP guest machine, I had to

  1. clone it
  2. resize it with "VBoxManage modifyhd winxppro\ Clone.vdi --resize 30720" and everything worked

I saw in other forums that snapshots can interfere for resizing and not being able to remove all snapshots for different errors I got, the only found solution for me was to clone it to remove the snapshots and then resize it, and everything worked. For resizing outside windows, a gparted boot cd that can be found here can help

11

I had the same problem where I had moved a disk, and replaced the original with a symlink. This works OK afterwards, but you run into problems with the 'modifyhd' command, as that apparently canonicalizes the path to the vdi-file when working with it. This makes it looks like you're trying to add a new disk with the same UUID but on a different path - or something like that.

There was two problems:

  1. The disk had to be removed from the VM that used it, but then also "from the VirtualBox list of hdds". This was fixed with 'closemedium' command, which removes it from that list.

  2. The disk to be resized was a "fixed disk" instead of "dynamic", and only dynamic disks can be resized. That was fixed with a 'clone' command (the clone is dynamic), and then resize the resulting disk.

This is my log for how it was done. Do notice that I am not at any point running as root, except when I afterwards do the resize of the partition and filesystem.

REMOVE THE ASSOCIATION TO THE DISK FROM VM.

PROBLEM STILL PERSISTS:

virt_box@TestBox:~/VirtualBox VMs/TestInception 64 bit$ VBoxManage modifyhd TestInception\ 64\ bit.vdi --resize 8192
VBoxManage: error: Cannot register the hard disk '/datadisk/VirtualBox VMs/TestInception 64 bit/TestInception 64 bit.vdi' {6cd99209-e4db-4178-a6c2-53f9581b1fad} because a hard disk '/home/virt_box/VirtualBox VMs/TestInception 64 bit/TestInception 64 bit.vdi' with UUID {6cd99209-e4db-4178-a6c2-53f9581b1fad} already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp

Ah, the disk is still "in the system":

virt_box@TestBox:~/VirtualBox VMs/TestInception 64 bit$ VBoxManage list hdds
UUID:        ba58276a-bbe1-4354-8ae5-246bdac390c8
Parent UUID: base
Format:      VDI
Location:    /home/virt_box/VirtualBox VMs/TestInception 32 bit/TestInception.vdi
State:       locked write
Type:        normal
Usage:       TestInception 32 bit (UUID: a693ac62-7caa-4f11-9d00-51d3a149f5f7)

UUID:        6cd99209-e4db-4178-a6c2-53f9581b1fad
Parent UUID: base
Format:      VDI
Location:    /home/virt_box/VirtualBox VMs/TestInception 64 bit/TestInception 64 bit.vdi
State:       created
Type:        normal

Remove/delete the disk from the VirtualBox disk list ("closemedium"):

virt_box@TestBox:~/VirtualBox VMs/TestInception 64 bit$ VBoxManage closemedium disk 6cd99209-e4db-4178-a6c2-53f9581b1fad
virt_box@TestBox:~/VirtualBox VMs/TestInception 64 bit$ VBoxManage list hdds
UUID:        ba58276a-bbe1-4354-8ae5-246bdac390c8
Parent UUID: base
Format:      VDI
Location:    /home/virt_box/VirtualBox VMs/TestInception 32 bit/TestInception.vdi
State:       locked write
Type:        normal
Usage:       TestInception 32 bit (UUID: a693ac62-7caa-4f11-9d00-51d3a149f5f7)

Try the resize again:

virt_box@TestBox:~/VirtualBox VMs/TestInception 64 bit$ VBoxManage modifyhd TestInception\ 64\ bit.vdi --resize 8192
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

DAMN, "fixed-size" DOESN'T WORK! 'clonehd' to the rescue, as that leaves a 'dynamically allocated' cloned disk:

virt_box@TestBox:/datadisk/VirtualBox VMs/TestInception 64 bit$ VBoxManage clonehd TestInception\ 64\ bit.vdi TestInception\ 64\ bit-cloned.vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: 8e237500-173b-401a-9e63-9e64da110da9

NOW DO THE RESIZE (instantanious):

virt_box@TestBox:/datadisk/VirtualBox VMs/TestInception 64 bit$ VBoxManage modifyhd --resize 8192 TestInception\ 64\ bit-cloned.vdi 
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

THEN ATTACH TO SOME VM, FOR RESIZING. This is done as root. Assumes that you only have one partition and possibly swap.

# fdisk /dev/sdb  # <- The extra disk, just attached to be resized
// The procedure looks like this:
// m - print help
// p - print table
// d ... - delete partition (delete both if you have root and swap)
// n - new partition (create root/first partition starting on exact same sector as before, typically 2048, but ends on last, or last minus swap)
//  ... n.. (.. then add the swap partition. Calculate how many sectors using original table)
// t - change type of partition (swap partition, if any, to 82 - not 83 which is "normal Linux").
// w - write partition table (write out, with the resized partition)

# e2fsck -f /dev/sdb1

e2fsck 1.42.5 (29-Jul-2012)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 99918/122160 files (0.3% non-contiguous), 471032/487936 blocks

# resize2fs /dev/sdb1

resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sdb1 to 1965824 (4k) blocks.
The filesystem on /dev/sdb1 is now 1965824 blocks long.
1
5

This worked for me with Virtualbox 5.2.6 installed on Ubuntu 16.04 Host Machine and Windows 10 Guest: open Virtualbox Manager, click on Global Tools (upper right corner) and choose Virtual Media Manager. Click on the Hard Disk Tab and select your Guest OS. At the bottom of the box click on the Attributes Tab. At the bottom you can see the size of the Virtual Disk, and with the slider you can increase the size to your liking. (You can only increase, not decrease the size with this method). Click on Apply. Start your Windows Guest OS, open Computer Management, right click on the C: Drive, and select Extend Volume to extend the file system with the unallocated part.

That’s all I had to do, works perfectly for me.

2
  • Worked great. Shouldn't this be the accepted answer, at least for the recent versions of VirtualBox? Apr 29, 2018 at 12:38
  • 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.
    – Robin
    Oct 16, 2020 at 8:24
4

Here's a way to resize your VirtualBox disk, regardless of whether it is a fixed format or dynamic format disk. Specifically, it prevents this error:

Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

⚠️ Backup the virtual disk. You never know what might go wrong.

On your host:

  1. Open a terminal window.

    On Windows: Open the command prompt cmd.

  2. Go to the directory with the virtual disk you want to resize. For example:

    cd "My VMs"
    
  3. Create a new VirtualBox disk with your desired filename, size (in megabytes) and format (either Standard (dynamic) or Fixed). For example, to create a 50 GB fixed-format disk called MyNewDisk.vdi:

    VBoxManage createmedium --filename "MyNewDisk.vdi" --size 50000 --variant Fixed
    

    If VBoxManage is not recognized as a command, specify the full path to it. It can be found in the VirtualBox installation directory. On Windows the above command would become:

    "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" createmedium
        --filename "MyNewDisk.vdi" --size 50000 --variant Fixed
    
  4. Copy the original disk to the new disk.

    VBoxManage clonemedium "MyOriginalDisk.vdi" "MyNewDisk.vdi" --existing
    
  5. The resize is done! You can check the properties of the new disk if you want:

    VBoxManage showmediuminfo "MyNewDisk.vdi"
    
  6. Change the virtual machine to use the new disk instead.

Next, on your guest OS you need to resize the partitions to use the newly available space.

1
  • what if you get an error on step 4 saying that the uuid already exists?
    – X3R0
    Mar 15, 2023 at 15:51
2

A sure-proof way is to do it the same as moving to a larger hard drive that's not running in a VM. First use ccleaner or similiar program in XP to clean up all junk files that it can. Then create a secondary virtual HDD of the size you want. Boot with the clonezilla ISO in your virtual ODD drive and clone over along with the 'resize to new partition size' option selected. Then set the new Virtual HDD as primary, and don't delete the old one until you know it worked.

0
2

I received the same error until I used sudo to run the command, then worked perfect, still need to have partition grown from within the guest to use additional space.

1
  • Some people reported this causes the home dir to have bad permissions
    – Jonathan
    Sep 1, 2016 at 0:02
2

Make sure you are logged in as user with write permissions to the disk image file. Then run

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB  

Worked for me at first time of asking

1
  • 1
    Did you have to reinstall / reformat / repartition? or did it just boot right back up?
    – Jonathan
    Sep 1, 2016 at 0:01
2

If your host machine is windows, then you can run the following command to increase or decrease the vdi disk size in virtual box:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "C:\Users\your_user_name\VirtualBox VMs\Ubuntu18LTS\Ubuntu18LTS.vdi" --resize 20000

In the above command replace your_user_name with the real windows user and 20000 is MB size of disk.

1

As a matter of fact, it seems that modifyhd alone doesn't do you any good in some cases. I actually expanded my WinXP vdi by cloning the image after expansion.

Here's the complete step-by-step guide that worked for me a couple of weeks ago: http://libtronics.com/2011/07/resize-virtualbox-disk-for-winxp-guest/

2
  • 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. Sep 29, 2012 at 17:10
  • 1
    Well, you need to understand what modifyhd does, which isn't much more than expanding the underlying virtual disk, that's all. You still need to expand the filesystem that's on it. Nov 21, 2012 at 0:41
1

For those who have Windows on a VHD, like I did, first convert to VDI by cloning with the following Linux command. (Note, Windows VM powered off.)

VBoxManage clonehd Windows10.vhd Windows10.vdi --format vdi

This will duplicate the vhd.

Then the VDI can be resized with the following. Note the VDI won't actually grow until it is used.

VBoxManage modifyhd Windows10.vdi --resize 80000

After fixing up the storage mounting in the VM host software, and powering on the VM, Windows boots, but the partition will still be the same size. Google for a Windows tool that can resize the C drive partition. I used EaseUs Partition Master to grow the C drive partition to my new size.

Finally, the VHD can be deleted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .