Is there an easy way to increase virtual hard disk space on VirtualBox?
There is not an easy way to do this.
There is a complicated one, though:
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.
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.
If you are running Windows Server 2012 and VirtualBox version 4 and above, there are only 4 steps:
- run the "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd .vdi --resize
- Boot Up Virtual Box
- In server managaer -->File And Storage Services --> Volumes --> Disks --> Tasks --> Rescan Storage
- 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!!
This worked perfectly (from Windows 7 and using VirtualBox 4.x).
Do the following:
- Open cmd as administrator.
- Go to the folder where the VirtualBox is installed so you can use the
From there, run the following command:
VBoxManage modifyhd <file path and name> --resize <size in MB>
VBoxManage modifyhd C:\V-MACHINES\SERVER2008\WIN-2008.VDI --resize 26000
- You will see a message from 0 to 100% and done.
- 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.
- If necessary restart the VM.
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.
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
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
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.
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.
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.
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.
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 ) :
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.