Use diskpart to solve problems where the recovery partition is too distracting to extend the disk size
- Windows 10 20H2 64bit
* It works with other versions, but it is unconfirmed.
- The operation of this Tips may cause data corruption if the procedure is incorrect. If you are worried, please respond by "taking a backup in advance", "using a dedicated tool", "asking a specialist", etc.
- The symptoms in these Tips may not occur depending on your PC environment and version of Windows.
- For Windows Pro editions or higher, you must have administrator rights on your local PC.
- Please note that we are not responsible for any failure in these operations.
- In some environments, the correct procedure may not work.
These tips are a Hyper-V virtual machine with Windows 10 20H2 installed.
The disk size is 127GB as shown in the figure.
The disk configuration is created as follows when Windows is installed: By the way, this is a new state immediately after assigning, other than that, it has not been changed in particular.
After Windows installation, open Disk Management and you will find the recovery partition on the right side of drive C.
Now expand the virtual machine's disk.
An unallocated disk was added and I tried to extend drive C, but there is a recovery partition in between and it cannot be extended.
How to check if the current recovery partition is working properly
If you haven't explicitly deleted the recovery partition, it usually works and you don't need to check it, but if you want to do so, you can check it by following the steps below.
There is also a way to check with a command, but the GUI is safer, so we will check it with the GUI here. Since it is a prerequisite to restart Windows, please close all applications.
Open "Settings" from the start menu.
Select Update & Security.
Click the Restart Now button under Customize PC startup. Please note that there will be no confirmation message.
By the way, if you do not have this button, start PowerShell with an administrator command, run the following command, and then restart Windows. (Depending on the environmental condition, this button may or may not have this button.)
You should see the following screen after restarting Windows. Select "Troubleshoot" here.
If you see the "Reset this PC" menu, the recovery environment is enabled.
If the recovery environment is not enabled, "Advanced Options" is displayed as it is. By the way, these menus may change depending on your version of Windows and the PC you're using. If there is such a menu related to recovery, consider that recovery is enabled.
If you want to go back to normal Windows startup, press the ← button in the upper left corner to return to the first screen and select the Continue menu.
When performing these operations, please confirm the input carefully. Also, be aware that you go back and forth between the "two PowerShell windows". Shell commands preceded by [DISKPART] are operations in a window that uses DISKPART .
Since the operation of this item is almost a confirmation process, it will not break the system if there is no typographical error.
Right-click the Start menu and select Windows PowerShell (Admin).
You can enter the following command to view the status of the recovery environment:
This "DiskPart" will perform the main operation of the disk this time. Enter the following command to start DiskPart: DiskPart itself is a command-line tool.
Enter the following command to display a list of disks. This list is the same as the one displayed in the Disk Management window. Note that it is different from the type of drive. In this Tips, only one disk is attached to the virtual machine, so only one is displayed.
Select the disk you want to work with. The "disk 0" part of the disk list is the number. The number of disks varies depending on the PC you are using, so choose a disk with a recovery partition.
select disk [ディスク番号]
select disk 0
Enter the following command to display a list of partitions on the selected disk. You can see that here is the recovery partition.
In the above figure, the number is "4", so select the recovery partition with the following command.
select partition [回復パーティション番号]
select partition 4
Enter the following command to display information about the selected partition.
Preparing to move
Since the operation of this item is related to backup, it will not destroy the system if there is no typographical error, but it will operate the system disk.
By the way, if you only want to delete the recovery environment, you do not need to work on this item.
This operation assumes that you have already selected a recovery partition on the PowerShell DISKPART screen.
First, attach a drive letter to the recovery partition so that it can be accessed as a file. In the example, it is assigned as "Z drive", but if it is not free, specify another drive. Future operations will also use that drive letter.
assign letter [空いているドライブレター]
assign letter z
It will also be visible in File Explorer. However, the files inside are hidden and cannot be seen.
Leave PowerShell running DiskPart as it is, but start PowerShell with administrator privileges.
Navigate to the Z drive.
It is a hidden folder and cannot be seen in File Explorer, but since there is a folder, move it to the following location.
Enter the following command to display the files inside. The following commands are for PowerShell only, so if you are using a command prompt, display them with a different command.
Create a backup folder to copy the files on the recovery partition to drive C.
Copy the file to the backup folder because it has the file in the following location.
xcopy /h Z:\Recovery\WindowsRE C:\Backup\WindowsRE
Since the original file is hidden, even if you copy it, it will not be visible from the explorer.
If you enter the following command, you can confirm that the file exists.
Get-ChildItem C:\Backup\WindowsRE -force
Now that you've copied the file, go back to PowerShell on the DiskPart and delete the drive letter.
remove letter [先ほど設定したドライブレター]
remove letter z
You can confirm that the drive is gone.
Disk move operations
From here, you will actually operate the disk, so please enter it without making a mistake.
From the non-diskpart PowerShell, run the following command to stop the recovery environment:
Run the following command with Recovery Partition selected from PowerShell on diskpart. This operation will delete the partition instantly, so if you perform it with the C drive selected by mistake, etc., the data will be blown away.
delete partition override
When you open the Disk Management screen, you can see that the recovery partition is gone. This allows drive C to expand.
Then extend drive C as much as you want. If you don't need a recovery environment, you can have all remaining disks filled. Expand the disk and finish.
If you are re-creating the recovery environment, leave about 1GB behind.
This is the state after extending with about 1GB left.
Restart Windows at this point (or you may not need to). This is because the drive letter used earlier cannot be used unless it is restarted. (You can substitute it with another drive letter instead.)
After rebooting, open Disk Management again.
Then create a volume for the recovery partition. You can create it with a command, but since it is troublesome to calculate the size of the disk manually, you can create it with the GUI and do what you can not do with the GUI with the command.
Allocate the remaining size.
Since there is work to be done to get the files back, specify the Z drive.
If you want to get the look back, remove the "volume label".
The state after creation. At this point it is a normal file volume.
You can also see it in File Explorer.
Return the files from the recovery environment that you backed up here. Start PowerShell with administrator privileges.
Create a folder on the Z drive. It is visible in File Explorer, but there is no problem.
Return the file.
xcopy /h C:\Backup\WindowsRE Z:\Recovery\WindowsRE
Verify that the file is returned with the following command:
Get-ChildItem Z:\Recovery\WindowsRE -force
Open another PowerShell again with administrator privileges and start DiskPart.
Select the partition by looking at the number you want to change back to the recovery partition.
list disk select disk 0 list partition select partition 4
Set the attribute to indicate that it is a recovery partition with the following two commands.
Return to the non-DiskPart PowerShell and enter the following command to extract the files required for the recovery environment: (There
/target C:\Windows is no problem even if there is none.) )
reagentc /setreimage /path Z:\Recovery\WindowsRE /target C:\Windows
Enable the recovery environment.
Verify that the recovery environment is enabled. If the status is Enabled, it is OK for the time being.
Delete the drive letter on the DiskPart side.
remove letter z
By the way, if the drive seems to be restored after restarting Windows, delete it by entering the following command in DiskPart. If the drive is in a state of reinstatement after a reboot, the recovery environment may become disabled after the drive is removed again. Whenever possible, try not to revive the drive after you restart Windows.
list volume select volume z remove letter=z
If the drive is restored by all means, delete the registry with reference to the following site.
I'll finish by checking a few last things. If DiskPart is still in use, check the list of partitions.
Check Disk Management.
Also check with the command. OK if the status is Enabled.
If it's not a hassle, check the startup options.
Delete the copied backup recovery file.
Remove-Item C:\Backup -Recurse -Force