45

Is there an easy way to increase virtual hard disk space on VirtualBox?

0

9 Answers 9

56

There is not an easy way to do this.

There is a complicated one, though:

http://www.my-guides.net/en/content/view/122/26/

Has a good screenshot-by-screenshot guide. Essentially you're copying your install onto a new virtual-disk file.

Update: As of VirtualBox 4 they added support for expansion.

VBoxManage modifyhd filename.vdi --resize 46080

That will resize a virtual disk image to 45GB.

6
  • 10
    Regarding the VirtualBox 4 version: after resizing the disk, you have to resize the partition as well which cannot be done when booted from so one has to boot into some sort of gparted livecd as well.
    – fikovnik
    Mar 14, 2011 at 2:14
  • 1
    @fikovnik- Yes, the partition needs to be resized too. However, on Windows it can be done on the booted disk itself using the diskpart utility tool via the command-line or via the Disk Management GUI without booting from a separate disk.
    – Ray
    Jun 8, 2011 at 19:35
  • I don't have a vdi file what is it? I have .vmdk files
    – chobo2
    Aug 2, 2012 at 21:45
  • I provide a link to help with re-partition the ubuntu hard disk, after using VBoxManage connection.rnascimento.com/2011/01/25/…. After re-partition the hard disk, u need to resize the file system using resize2fs command.
    – Thang Pham
    Sep 4, 2013 at 5:07
  • @fikovnik I managed to modifyhd to a larger number and I can clearly see it in the virtualbox manager the disk size has increased, however, i cannot see the extra space disk after i booted into gparted, weird.
    – B.Mr.W.
    Oct 19, 2015 at 4:56
5

The Trivial Proof blog has a nice tutorial of the process for VirtualBox versions before and after 4.0. It includes the steps for adjusting the partition on the expanded disk.

3
  • That blog site no longer exists. Aug 15, 2011 at 17:52
  • The link was just broken, @Barry. Fixed now.
    – Don Kirkby
    Aug 17, 2011 at 3:31
  • As of 2015, this answer is superior to the one that was accepted by the original questioner. Sep 6, 2015 at 4:04
2

If you are running Windows Server 2012 and VirtualBox version 4 and above, there are only 4 steps:

  1. run the "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd .vdi --resize
  2. Boot Up Virtual Box
  3. In server managaer -->File And Storage Services --> Volumes --> Disks --> Tasks --> Rescan Storage
  4. Go to server manager -->File And Storage Services --> Volumes --> Right click on volume --> choose expand volume.

Go to file explorer and right click on the drive. You will seethat the volume has increased in size!!

2

This worked perfectly (from Windows 7 and using VirtualBox 4.x).

Do the following:

  1. Open cmd as administrator.
  2. Go to the folder where the VirtualBox is installed so you can use the VBoxManage program.
  3. From there, run the following command:

    VBoxManage modifyhd <file path and name> --resize <size in MB>
    

    e.g.: VBoxManage modifyhd C:\V-MACHINES\SERVER2008\WIN-2008.VDI --resize 26000

  4. You will see a message from 0 to 100% and done.
  5. Start your machine and go to "Computer" (or "My Computer", if applicable), right click and select "Manage", go to "Storage" → "Disk Management", right click on the disk you want to expand, click on "Extend Volume" and resize the disk as you wish.
  6. If necessary restart the VM.
1
  • Yes, and, make sure you do that for snapshotted .vdi's. But note - once I've done all the above steps, my Win7 guest is very unstable. sfc /scannow hangs, even chkdsk hangs.
    – Greg Bell
    Jul 12, 2016 at 23:13
1

Had to search a bit on how to run this command.

Navigate to folder having your-filename.vdi e.g:(cd /Users/binoy/VirtualBox\ VMs/)

Then run the command to increase the space to 25 gb.

VBoxManage modifyhd filename.vdi --resize 25000

You would now have to attach the additional space using resize2fs or Gparted.

0

There's also now a simple GUI too called Clone VDI for Windows users that @Eric Kigathi mentioned here: https://stackoverflow.com/a/5987875/1024735

0

Lets see the currently existing virtual hard drives of your virtual box(es) using the vboxmanage command

$ vboxmanage list hdds

In my case it lists only this one

UUID:           db753df8-de41-425b-b452-fab84f1f8b71
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /home/anonyn/WIN81_64BITS.vdi
Storage format: VDI
Capacity:       39891 MBytes
Encryption:     disabled

Keep the location of the VDI file you want to resize /home/anonyn/WIN81_64BITS.vdi

Lets determine how much physical space is left on your real machine (Linux)

$ df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            3,9G     0  3,9G   0% /dev
tmpfs           791M  1,4M  790M   1% /run
/dev/sda2       110G   29G   76G  28% /
tmpfs           3,9G   62M  3,8G   2% /dev/shm
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
tmpfs           3,9G     0  3,9G   0% /sys/fs/cgroup
/dev/sda1        38M   512   38M   1% /boot/efi
tmpfs           791M   28K  791M   1% /run/user/1000

Since in my case I have 76GB free on /dev/sda2 I can increase that WIN81_64BITS.vdi it by 36GB without any issues

Some simple math will allow you to get the desired new size

[CurrentSizeFrom first command] + [SizeToIncrease in MBytes too]
39891 MBytes + 36*1024 MBytes
39891 MB + 36864 MB = 76755 MB [NewSizeInMB]

Now you are ready to build the command that will help you solve the problem

VBoxManage modifyhd [path/To/File.vdi] --resize [NewSizeInMB]

$ VBoxManage modifyhd /home/anonyn/WIN81_64BITS.vdi --resize 76755

$ VBoxManage modifyhd /home/anonyn/WIN81_64BITS.vdi --resize 76755 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Now boot that virtual machine and extend the desired partition following this steps

enter image description here enter image description here enter image description here enter image description here

0

Before any modifications are done, you should be aware of the limitations:

  • Only increasing is supported, no shrinking!
  • If the VM has any shapshots, you can increase the virtual disk, but not the partition inside of the VM (no free space visible). So you need to delete the snapshots first (recommended) or increase it for all snapshots (considered risky)
  • Creating a backup is highly recommended

Step 1: Increasing the VHD

Since a while (V4), you can do this using both the GUI and the CLI. It's not required to do both, just decide which way you're more comfortable with, they'll generate the same result.

Using the GUI

Start the VirtualBox Manager and on File > Tools > Virtual Media Manager.

enter image description here

On the right side, you'll see a list of the virtual hard disks of all VMs. Click on the desired disk and select it's new size on the bottom, then click Apply.

enter image description here

Using the CLI

You can increase the VHD using the command line, where --resize requires the new size in MB, not the quota you'd like to add! Let's say you have a 20 GB VHD and want to add 20 GB, so the new size is 40 GB, then you'll using the following command:

vboxmanage modifyhd <absolute path including the name and extension> --resize 40960

On GNU/Linux, the vboxmanage is in the global $PATH. When the host is running on Windows, you may need to change the directory using the cd command to the VirtualBox program files folder first, where those cli tools are located.

Step 2: Increase the partition inside your VM

The disk doesn't know about the partitions and especially which of them you want to increase, since there could be multiple ones on the same (virtual) disk. So this step needs to be done manually. You can increase a partition by using generic free tools like GParted, which have to be booted as live CD before the guest OS.

Or you can use the tools of the guest OS: Ubuntu for example, has several tools, it can be done using either GUI or CLI. Windows has the Disk management (diskmgmt.msc). On both systems, you now should see the extended space as free, so it's possible to extend the partition before or create a new one.

Further information

Can be found in the official post for this topic. I tried this using VirtualBox 7.0.4-1 on Manjaro (host) with a Windows 10 guest, however it should work in the same way with other OS combinations.

0

As others mentioned, first increase the vdi file size, to the desired level, using the vboxmanage command and then:

Just use the Live CD from this Open Source Project, on Hosts / Guests ( this Live CD has the gparted program built in, in its Applications Menu, along with many other goodies like File Manager, Disk Mounter, Installer, Internet Browser etc.; also read the instructions on the site ) :

https://sourceforge.net/projects/live-cd-with-zerofree-utility/

P.S. A 32-Bit Version ( i686 architecture ) of this Live CD is available at: https://sourceforge.net/projects/live-cd-with-zerofree-32-bit/

For very OLD Architectures, Please try this Live CD : https://sourceforge.net/projects/live-cd-with-zerofree-x86/

Hope this helps all.

An additional point to note: gparted from a live cd works much better than the gparted from within the same operating system, as it does not face any issues like Locking Problems, Unmounting Problems etc.

You must log in to answer this question.

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