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
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…
diskpart | Launch 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 Disk | If disk is not showing online. you will need to bring it online. |
list volume | List 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 9 | Select the volume we want to work with. In my case the volume I want to work with is Volume 9 |
extend | extends the currently selected volume to use all contiguous available space on the same disk |
List Volume | running again to show the new size of 39gb. When we ran it before, it was only 19gb. |
detach vdisk | dismounts the Vdisk volume. Taking the volume offline is required because Hyper-V cannot load a disk that is mounted |
exit | Exit diskpart utility |
And finally, a screenshot of what I typed and the result.
Other articles that may be of interest:
Comments
Anonymous
January 01, 2003
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.Anonymous
April 05, 2011
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.
Anonymous
May 01, 2012
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 !Anonymous
June 13, 2012
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 MEGAbytes that the resulting disk should have in it. 40000 is almost 40gb"Anonymous
June 13, 2012
Also, I believe that the vdisk must be detached before you expand it, at least that was the case for me.Anonymous
October 15, 2012
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?Anonymous
April 06, 2014
thx, the procedure with diskpart also works with windows 8.1 and save me a lot of hassleAnonymous
June 10, 2014
Thnx A lot! I expanded my vhd easily.Anonymous
July 16, 2014
Thank you - helped a lot.Anonymous
August 03, 2014
The comment has been removedAnonymous
August 03, 2014
I have win 2008 r2, when Iaunch command "expand vdisk=10000" the system say me: parameter not correct verify event log...
I have tryed on another vhd file and the message is the same
please helpme!Anonymous
August 04, 2014
Hi,
We are having issues with disk creation where we're trying to create a 2GB fixed disk through the Hyper-V Manager and it's taking days. Is there a quick way to create a fixed disk?
Thanks...Anonymous
September 20, 2014
I have finally found the tutorial to extend C drive size without formatting it. Its an easiest and fastest method which I used to increase my partition size within 1 minute athttp://seotrickz.com/use-aomei-partition-assistant-to-extend-c-drives-without-formatting/”>seotrickz.comAnonymous
September 20, 2014
I have finally found the tutorial to extend C drive size without formatting it. Its an easiest and fastest method which I used to increase my partition size within 1 minute athttp://seotrickz.com/use-aomei-partition-assistant-to-extend-c-drives-without-formatting/Anonymous
October 21, 2014
I found this article and tutorial video very useful.Thanks for sharingAnonymous
January 31, 2015
Really dude? The "expand vdisk maximum" is in MEGAbytes, NOT bytes. Now I'm stuck waiting for a VHD to expand to 2TB. I just got totally trolled!! >.< sigh :(
See the documentation...
https://technet.microsoft.com/en-us/library/gg252550.aspx
Thanks anyway. :)Anonymous
February 26, 2015
sdsdsdsAnonymous
February 26, 2015
sdsdsdsAnonymous
February 26, 2015
hi how r u?Anonymous
April 15, 2015
Thanks, it works perfectlyAnonymous
June 01, 2015
I have a W2008R2 vhd that needs more space on C:. It is a dynamic vhd and I have already done the expand the vhd so maximum size is perfect. However my C: drive is still previous size so do I have to expand the partition for C: so it can utilize the expanded vhd size? I can't find how to do this anywhere. So even though my VHD shows maximum size of 120GB, my C: drive is still full at 80GB.Anonymous
September 20, 2015
The comment has been removedAnonymous
December 03, 2015
The comment has been removedAnonymous
January 09, 2016
Thank you for this. Especially the huge SS of the CMD windows with all the ornaments. Very simple, thurro and useful ^^