DeutschEnglish

Submenu

 - - - By CrazyStat - - -

23. April 2013

Enlarge dynamic and fixed VHD virtual hard drives

Filed under: Windows — Tags: , , , , , , , , — Christopher Kramer @ 23:42

If you use Virtual PC or built-in Windows backup for example, you probably use virtual hard drives stored in vhd-files.

I already blogged once about how you can mount such a vhd file easily in Windows.

But there is one big problem with vhd files: When you create them, you often don’t really know how big the file should be. You can use a dynamic vhd to solve this partly (at the cost of performance), but still you need to give a maximum size.

And then the time will come when you realize your vhd needs to be bigger then you specified it. So here is how you can enlarge vhds – no matter whether they are fix sized or dynamic.

Enlarge vhd file using diskpart

You can enlarge the vhd file in diskpart. Start diskpart, e.g. with [Windows-Key]+[R], type “diskpart” and hit [enter]. UAC will prompt you for permission (say “Yes”). So now select your virtual disk using the following command:

select vdisk file="C:\path\to\vdisk.vhd"

Now enlarge the disk using this command:

expand vdisk maximum=10000

In this example, 10000 means that the new total size of the disk is 10 000 MB (adjust the number to your needs).

So now your virtual hard drive grew larger. But the partition inside still has the old size. So you need to enlarge the partition as well.

Enlarge the partition in the virtual disk using Disk management

The easiest way to do this is to use Windows Disk Management, which is part of Computer Management . The fastest way to get there in Windows 7 is to click the Windows icon and enter “Disk Management” and start the appearing “Windows Disc Management” (Windows UAC will again ask you for permission, say “Yes”). Or, also for other Windows version, [Windows]+[R] and type “diskmgmt.msc” and hit enter.

Open the VHD with “Action” / “Attach VHD”. Choose the file, make sure “readonly” is not checked and click “OK”.

Then you will see the VHD just like your normal drives in the graphical overview. There you will see the partition in blue (or dark green, if it is a logical one) and the empty space in light green. Right-click the partition and choose “Extend Volume”. The tool  will propose to use all the empty space so you can just accept that and that’s it. Finally, right click the VHD drive and select “Detach VHD”. Make sure you don’t select the option to delete the VHD file after detaching!

Enlarge the partition in the virtual disk using diskpart

You can also achieve the same thing in diskpart (i.e. on the console, not using the GUI).

Open diskpart, and mount the VHD using:

select vdisk file="C:\path\to\vdisk.vhd"
attach vdisk

Then do

list volume
select volume=<No of volume>
extend size=100

Instead of <No of volume>, you need to enter the number of the volume (see output of “list volume”).

In this example, the partition gets enlarged by 100 MB. Here you need to specify the relative amount of space that gets added.

Finally, detach the vdisk:

detach vdisk

Problems? Just ask!

I hope this helps somebody. If so, please drop a comment. If you have problems, also just drop a comment.

Recommendation

Try my Open Source PHP visitor analytics script CrazyStat.

14 Comments »

  1. Could not get to work. Realized that where you put 10.000 MB you intended to put 10.000 GB.
    Once I realized that if worked great thanks.

    Comment by Fred — 3. July 2014 @ 18:06

  2. Although the thread is quite “antique” it helped my very much today! Thank you!

    Comment by Fluxx — 5. December 2014 @ 13:03

  3. Great post. Was simple and just what I needed. I am running win7 vhd natively. I couldn’t expand it while I was running it, plus it’s not the safest way to do it so I made a copy of the .vhd file (just right click and select copy). Had to test the copy to make sure it was bootable so I set up the system to dual boot using BCDEdit. After it booted I decided I didn’t feel like rebooting so I just followed the instructions on this page and increased the size of the original partition. While I was doing it I noticed that the copied .vhd was fixed not dynamic like the original was. I had a little trouble after I had expanded the volume and wanted to extend it. Rather than trying to figure out what I did wrong I just used the gui disk manager to extend it. Rebooted and it all was all good.
    Thanks for you post again.
    I found these also helpful:
    For the BCDEdit stuff – https://www.youtube.com/watch?v=_XOwQvPFSwA
    and https://www.youtube.com/watch?v=gEnIO9KRlLo

    Comment by ki — 8. December 2014 @ 09:24

  4. Very useful, very helpful — thank you. Having carried out the first step using “Diskpart” as recommended, I elected to extend the partition using Disk Management within the VM, and this was trouble-free, so you may wish to consider adding this as a third option for the second stage of the procedure.

    Comment by Philip TAYLOR — 10. February 2016 @ 09:34

  5. Old but gold! Used same MO as #4, resizing the partition inside the VM (could surely work with mounting in Disk Manager as well). All other solutions I found required third party tools, or really complicated PowerShell scripts.

    Comment by Dennis Langthjem — 6. April 2016 @ 11:27

  6. This helped me to enlarge my win10.vhd because it was too small. tyvm!!!

    Comment by jvanlangen — 26. April 2016 @ 23:36

  7. Can someone please help me? whenever i try expanding the vdisk maximum an error pops up that the parameter is incorrect

    Comment by Leah — 20. May 2016 @ 08:27

  8. @Leah: What exactly is the command you enter and what exactly is the error returned? Have you checked whether there is enough free space on the drive where the vhd is lying? 😉

    Comment by Christopher Kramer — 20. May 2016 @ 09:10

  9. Thanks for this recipe! It worked perfectly for me on my W10 64 desktop.

    To upgrade my virtual W7 Starter (based on VirtualBox) to Windows 10 Home 32, I first cloned the virtual machine. Then I found out I needed about 5 GB extra. I added 6.000 MB and enlarged the partition with extend size=1000 a few times, until that step was too large. Then I used extend size=500, and halving it until size=1 was too large.
    Now the upgrade started, but I soon got the message the hard disk still had not enough room. So I repeated the procedure by adding another 2.000 MB and enlarging the partition in a number of steps in the same way.

    Comment by krypteller — 22. July 2016 @ 16:19

  10. To krypteller

    Have you used the simple, GUI method of making Windows recognise the extended size of the VHD? In disk management you should see the extended space as “unallocated”. Right click the volume to be extended and select the extend context menu option and follow the wizard. It will extend it and you will see the new extended size straight away. For that part the GUI method is easier!

    Comment by david — 15. September 2016 @ 14:56

  11. Great article! Out of all the results in Google, this was the only one that answered my question. Everything else was either incomplete or answering the wrong question.

    Comment by Dielectric — 29. December 2016 @ 03:08

  12. Thanks so much! It was so hard to find such a simple way of resizing VHDs – which is extremely useful for restoring old hard drives imaged from macrium reflect and converted to VHD for use in virtualbox – I ended up stuck with Windows 95 installations I could not upgrade due to low disk space!

    Comment by Shiva Prakash — 9. January 2017 @ 10:54

  13. Yep, still helping people using Windows 10! Thanks.

    Comment by Geoff — 12. June 2017 @ 06:12

  14. This page gave me useful information unlike many before. Thanks!

    Comment by Dave — 28. June 2017 @ 21:56

RSS feed for comments on this post. TrackBack URL

Leave a comment