Real Time Web Analytics How To Expand and Extend To Increase Capacity On A Virtual Hard Disk The Easy and Fast Way–Solve the problem of “Out of Disk Space on Drive C” Forever - ITProGuru Blog by Systems Management Expert Dan Stolts - Site Home - TechNet Blogs

How To Expand and Extend To Increase Capacity On A Virtual Hard Disk The Easy and Fast Way–Solve the problem of “Out of Disk Space on Drive C” Forever

       Build Your Lab! Download Windows Server 2012
       Don’t Have a Lab? Build Your Lab in the Cloud with Windows Azure Virtual Machines
       Want to Get Certified? Join our Windows Server 2012 "Early Experts" Study Group
Share with friends!

How To Expand and Extend To Increase Capacity On A Virtual Hard Disk The Easy and Fast Way–Solve the problem of “Out of Disk Space on Drive C” Forever

  • Comments 8
  • Likes

Before following these instructions… PLEASE backup your machine.  The best way to get a good backup of a machine is to do an export.  So please, export the machine or at the very least test your backup procedures to make sure they are valid.  Also, if you want a way to do this through a GUI then check out the Expand and Extend VHD.vmv video and go to the end.  Very cool shortcut that is much easier than the command prompt but requires Windows 2008 R2

I ran this on a Windows Server 2008 R2 SP1 machine.  These instructions will be identical for Windows 7.  I am not certain of the changes from earlier versions of the OS.  I think these commands are all available in Vista but I am not sure and I do not have a vista machine available for testing.  The commands in this post must be run while the VHD file is closed.  It cannot be attached with disk manager and it cannot be attached to a running VM.  You also have to be in an elevated command prompt.  Start | type cmd | Right-click cmd (top of menu) | Run as Administrator

I have done several posts recently on managing VHD’s.  I wanted to simplify the process of adding additional space to the C: drive (Boot Drive) of a virtual machine.  I have collapsed it down to a few simple steps using diskpart.  Thanks to all that posted comments giving me the suggestion to write this post.  If you have snapshots on the volume or are using differencing disks you will need to check out How To Merge a Chained Differential VHD Disk So It Can Be Extended and Expanded to learn what you need to do before you can expand and extend these disks. 

The commands I ran to expand and extend my disk (all together). Notice your commands will be different as you will have to put in your name and path and look to see what volume # your disk is so you are working with the correct volume.  A couple things of note as I worked through these instructions again and produced a video of it.  The most important of which is that the disk has to be completely closed before you can start the machine up.  

I did a video walkthrough of these instructions.  You can down the video from Expand and Extend VHD.vmv  

diskpart
Select vdisk file="D:\W510\BRS Fargo - {SQL, FEP Server ConfigMgr } .10\BRS-FargoNew.vhd"
list vdisk
expand vdisk maximum=40000
attach vdisk
list disk

-- If disk is not online… Use “Online Disk” to bring it online

list volume
select volume 9
extend
list volume
detach vdisk 
exit

Now let’s look in more detail at what I am doing with each command…

Command Description
diskpartLaunch the DiskPart utility
Select vdisk file="D:\W510\BRS Fargo - {SQL, FEP Server ConfigMgr } .10\BRS-FargoNew.vhd" Select the VHD file.  Notice that if the path or the file name has spaces you have to put “” quotes around it
list vdisk Shows you a list of Vdisks.  The * at the left shows the one that is selected.
expand vdisk maximum=40000 changes the size of the vdisk to this new size defined by the maximum= parameter.  This is the number of bytes that the resulting disk should have in it. 40000 is almost 40gb.
attach vdisk once the disk is expanded you have to mount it to work on the disk.  This actually mounts the disk. If you look in Disk Manager or in windows explorer you would see that after you run this you have a new drive.  It is doing the Attach to the currently selected vdisk which is the one we just expanded
list disk Shows the list of disks.  This is all mounted disks so it includes all vDisks that are mounted.  The disk we want to work with is already selected because we just attached it.  if it were not selected you could select it with Select Disk #.  Notice that we now have 19gb of free space thanks to the expand vdisk command we ran above
Online DiskIf disk is not showing online. you will need to bring it online.
list volumeList volumes (partitions) the ### column is the most important.  It has the number you need to use to select the volume you will work with.  notice that the volume is currently 19gb
select volume 9Select the volume we want to work with.  In my case the volume I want to work with is Volume 9
extendextends the currently selected volume to use all contiguous available space on the same disk
List Volumerunning again to show the new size of 39gb.  When we ran it before, it was only 19gb.
detach vdiskdismounts the Vdisk volume.  Taking the volume offline is required because Hyper-V cannot load a disk that is mounted
exitExit diskpart utility
 
 

And finally, a screenshot of what I typed and the result.

SNAGHTML744201

Other articles that may be of interest:

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi,

    I've used this way too to expand windows 2003 system disks, however, do you have any idea on how we can script it?

    I know diskpart /s script.txt, but there's no way to parse out the volume number..

    Ideas?

    ----

    I would guess that it can be done with powershell but not sure.  I will add it to my list to investigate when I have some time. 

     

  • Hi,

    In you example, you expand on a dynamic VHD hard drive (boot drive).

    Is this work on a fixed VHD drive ?

    Thank for all, very good job !

  • Just a small typo which might cause some confusion:

    "changes the size of the vdisk to this new size defined by the maximum= parameter.  This is the number of *MEGA*bytes that the resulting disk should have in it. 40000 is almost 40gb"

  • Also, I believe that the vdisk must be detached before you expand it, at least that was the case for me.

  • Hi,

    I have Hyper-V running on a Windows 2008 Service Pack 2. The version of Diskpart is 6.0.6002. This version of Diskpart doesn't seem to support vdisk. Any suggestions?

  • Hi Dan, thanks for this gold nugget of a post -really clear and the video is a nice touch.

    I used this guide to expand a fixed size disk vhd which I had prevously converted from vmware player's vmdk. I am using this vhd as a boot disk. The expand command after a couple of minutes of countdown indicated successful completion and I could see in file explorer the increase in size.

    This worked on windows 8 pro and at the point of attaching vdisk it was automatically onlined. Rather than extending the partion at this point I detached the vdisk and exitted from diskpart and rebooted into the vhd. Then opened up disk management and as expected could see the unalloacted space.

    On a different subject any plans do do a blog and video for devs wishing to use hyper-v? I had a play with windows 8 pro with hyper v and set up a couple of machines. Didn't seem to support multi monitors and have never used remote desktop and hadn't the time to fully explore it. From the videos I have seen for hyper-v on Win 8 seems to be excellent for spinning up testing environments and easy deployment but not so much on developing and using visual studio 2012 hosted under hyper-v. Have not seen much about the remote desktop experience etc. My perception so far as a developer is the barriers to entry are much higher than vmware.

  • thx, the procedure with diskpart also works with windows 8.1 and save me a lot of hassle

  • Thnx A lot! I expanded my vhd easily.