243

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.

  • 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 '13 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 '14 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 '18 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 '18 at 9:25

13 Answers 13

313

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.

  • 19
    +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 '11 at 10:05
  • 3
    +1, This is certainly the cleanest way to do it. – Starx May 3 '12 at 15:08
  • 19
    @asd Changing the disk size isn't enough, you also need to resize the partition. – Bruno Nov 7 '12 at 18:44
  • 1
    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/… – Travis van der Font Dec 9 '16 at 14:46
  • 5
    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. – TranslucentCloud Sep 6 '17 at 19:04
23

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

  • 12
    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 '12 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. – Richard Povinelli Apr 15 '12 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 :-) – Richard Povinelli Apr 15 '12 at 12:19
  • 2
    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 '14 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 – Ajith R Nair Aug 17 '16 at 13:52
17

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
    Not required on Linux in VirtualBox. Just had to shut down the guest OS completely first. – Underverse Feb 4 '17 at 9:23
7

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

5

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.
3

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.

  • Worked great. Shouldn't this be the accepted answer, at least for the recent versions of VirtualBox? – AlwaysLearning Apr 29 '18 at 12:38
3

You can also do it using the VirtualBox menu:

Select File -> Virtual Media Manager ...

A window will open: enter image description here

Select your disk, and select Properties. Now just move the slider at the bottom.

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

Open Computer Management (search for it in the start menu), select Storage -> Disk Management in the left menu. Select your partition (probably C:), right click on it and select Extend Volume .... Now just click through the wizard and you're done.

1

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.

1

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.

  • Some people reported this causes the home dir to have bad permissions – Jonathan Sep 1 '16 at 0:02
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/

  • 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. – Tom Brossman Sep 29 '12 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. – Marcin Kaminski Nov 21 '12 at 0:41
1

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
    Did you have to reinstall / reformat / repartition? or did it just boot right back up? – Jonathan Sep 1 '16 at 0:01
0

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.

0

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.

protected by Community Apr 10 '12 at 10:27

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.