There are occasions that we want to expand existing disk space like in situation where we cloned a disk from a smaller hard drive to a bigger one or removing drive D as data drive so that we don’t run out of disk space on C that crashes our system.
There is also, expanding of VM image’s allocated space. (Although removal of recovery drive don’t impact the operation of VM, keeping the recovery partition may be useful for moving virtual to physical for troubleshooting issues in recovery console).
Usually such situation, involves backing up existing data, removing secondary partition and extending the primary partition to utilize the freed up space from the removed partition. But with recovery partition at the end of the original disk, the extension of space would require deleting the recovery partition, extending the disk and leaving no option to go into recovery mode for troubleshooting.
The following steps are for expanding a virtual machine disk size but is also applicable for physical machine using the same commands to achieve expanding a partition and keeping recovery partition without using third party software.
Running diskpart on virtual shows 19GB space on main windows partition on 3 with 530MB recovery on partition 4.
Disk was expanded via Hyper-V Manager by editing the vm disk and expanding it.
We accessed the Windows 10 vm via RDP or console and deleted the recovery partition 4 using diskpart.
- Run CMD as administrator
- Type diskpart
- Within diskpart > prompt, type select disk 0
- list partition (show all partition in disk 0)
- Type select partition 4 (select for removal)
- Type delete partition 4 override (force deletion)
- Type exit twice from diskpart and cmd prompt box.
Once done. Start Windows Disk Manager (diskmgr.exe) and expand the disk with space available.
Download and insert Windows 10 iso and locate the wim file for your Windows version by listing sources\install.esd file with DISM.
Create a temp folder and a mount folder in C drive.
1. Go to CMD, type md c:\temp && md c:\WinMount
Delete temp folder and Cleanup mounted path by closing file explorer and running
DISM /Unmount-Image /MountDir:C:\WimMount /Discard
Delete also the WimMount folder to clean up.