How to resize a Virtual Drive

Everything which doesn't fit into the other sections.
Post Reply
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

How to resize a Virtual Drive

Post by Perryg »

Resize a virtual HDD

First, resizing does not work if the guest has snapshots (prior to version 4.3.*) nor will it work on Fixed drives, nor on drives which are already larger than the selected size.

Secondly when doing anything that could prove as destructive as this should you make a mistake, backup the *.vdi file before you start.

Increasing the drive does not increase the primary partition so this is a two step process.

Step 1: Increase the size of the drive.
  • For VirtualBox 6.0.x and later
    Go to Virtual Media Manager:
    • 6.1 & earlier: File menu > Virtual Media Manager
    • 7.0 & later: File menu > Tools > Virtual Media Manager
    Find your VDI, make sure the "Properties" is enabled in the toolbar, select the "Attributes" on the bottom part. There is a slider and a numeric control there, that you can use to adjust the VDI size.

    Be doubly careful before pressing the "Apply" button, because you can only increase the VDI size, you cannot decrease it. But that wouldn't be a real problem because you made a backup of your data before trying this stuff, right?
     
  • For VirtualBox before 6.0.x
    Note: if the path has spaces in it you will need to wrap the path in quotes.
    Use the following command to increase the size of the drive:

    Code: Select all

    VBoxManage modifyhd <absolute path to file> --resize <size in MB>
    Example: I have a 10GB drive that I want to be 20GB the command would be.

    Code: Select all

    VBoxManage modifyhd <absolute path including the name and extension> --resize 20480

Step 2: Extend the primary partition to include the new drive space.
  • Download the GParted Live CD or whatever partition manager program you wish and mount it to the guests virtual CD and boot the guest. You can download the GParted Live CD from HERE. From here you can expand the primary partition to use the new space.
  • Windows Vista and newer Windows guests can use the built in "Disk Management" tool to expand the primary partition.
Note 1: The only step that VirtualBox is concerned with is step 1. After that you need to seek additional information on the partition manager you wish to use from the vendor of the partition manager.

Note 2: You can not shrink a guest drive with VirtualBox due to the inherent danger of losing data or making the guest non-bootable.

Note 3: In 4.3.0 the devs fixed a bug which had previously made it impossible to resize a snapshot. Since then it is possible, but not recommended for non-experts.
Last edited by Perryg on 18. Aug 2015, 16:24, edited 3 times in total.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to resize a Virtual Drive

Post by mpack »

What if I used Fixed Disks, or VMDK?

As the advice above states, resizing of fixed VDIs or VHDs is not directly supported, nor is resizing of formats other than VHD/VDI. Nor is it easy to resize disks which are part of a snapshot chain.

However, all of these problems are easily addressed if you clone the disk to a supported format first, using :-
(fields in brackets are placeholders which should be replaced with actual filenames, the brackets are not literal)

Code: Select all

VBoxManage clonehd <infilename or UUID> <outfilename> --format VDI --variant Standard
You can then resize the resulting dynamic VDI using "VBoxManage modifyhd" as described in the previous message.

If a snapshot chain is involved then <infilename> should be the name of the latest snapshot VDI in the "Snapshots" subfolder. Do not make the rookie mistake of cloning the base VDI. In this case "clonehd" will create a merged clone and it's important that you not incorporate this back into a VM which is still expecting a chain of difference disk images. Either build a new VM around the clone, or delete all the snapshot markers from the original VM, then replace the disk file. If the VM did not use difference images (no immutable drive, linked clone or snapshot) then you can use the Storage settings panel to remove the old disk and replace with the new one.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to resize a Virtual Drive

Post by mpack »

What if my VM uses Snapshots?

If you are intent on keeping the snapshot structure then you are supposed to enlarge all members of the snapshot chain, which is a risky business. Or you can enlarge only the latest snapshot, but that is even more risky (think about future complications when snapshot elements are removed).

The best thing is to delete all the snapshots using the UI, before enlarging the current state. Be sure to make a backup of the VM before starting this.

You can also use the "clone VM, then enlarge" trick from the previous post. In particular see the paragraph on merging a snapshot chain into a single disk using VBoxManage clonehd. This would be an easy way to dispense with snapshots, making it a trivial matter to enlarge the disk.
Post Reply