Go to ...

RSS Feed

Create a custom Windows 10 “factory recovery” partition


These days, most new computers with a pre-installed operating systems ship with a so called factory recovery option. This allows users to completely reset the computer by restoring an image stored on a specific factory recovery partition. The problem with factory recovery is that it restores everything the way the original equipment manufacturer (OEM) wants them. This might include a bunch of “bloatware”, useless software like “30-day trial of XYZ” or “Tweak your PC with this fabulous tweaker” and so forth. One of the first things any user wants to do when setting up a pre-installed Windows on a new computer is to get rid of all this bloatware.

In this post I will show you how to either replace the factory recovery partition with your own custom version, or to create one in case your computer does not have a factory recovery option and partition available to start with.

To begin, open This PC in File Explorer, right click the Windows partition C: and select Rename. Give the partition a distinctive name like “Windows 10“. It will help you later to identify the system partition. If you have no shared network folders on another PC available or alternatively no other partitions than Windows partition on this PC you are using to capture custom Windows image, create a new partition on any internal or external disk or share a folder on another PC on your network to store captured custom Windows image.

Customize your Windows exactly as you want it. When Windows 10 is working as you’d prefer, all required software installed, bloatware and unnecessary apps uninstalled, settings changed and user profiles created, boot computer from either a WinPE media or Windows 10 install media. When Windows Setup starts showing region and language selection, press SHIFT + F10 to open Command Prompt:

Click to open enlarged in a new tab.

Type DISKPART (#1 in next screenshot) and hit Enter to start the disk partitioning utility. When booting from PE or install media, drive letters might be different from what they are when booting normally. Enter the command list vol (#2) to check partition letters. We need to capture the Windows partition and save that captured install.wim file on another partition (internal or external drive) or on a shared network folder. Check what temporary drive letter your Windows system partition has, in my case now it is D: drive (#3). In case you are saving the captured image to another partition on the same PC, check its drive letter, too. In this example case I could have chosen drive E: (#4) as the location to save the captured Windows image.

Enter the command EXIT to quit DISKPART (#5).

In this example now, I want to store the captured image to a shared network folder named Storage on a another computer AGM-W10PRO03. To do that, I need first to initialize networking services with the command wpeinit (#6),  then map the shared folder on that PC to a drive letter on the local computer. For this example, I’ll map the shared network folder as drive Z: using the following command (#7):

net use Z: \\agm-w10pro03\storage

When prompted, I will enter the network credentials (Windows username & password) for that computer.

Path to a network share is told as \\server\share where server is the name of the computer where shared drive or folder is located, and share is the name that drive or folder is shared with. In my case I have shared a folder on drive I: on computer AGM-W10PRO03 as Storage, so the path is \\AGM-W10PRO03\Storage. Change yours accordingly.

OK, everything is ready to capture the Windows install image. In this example, I am capturing the Windows system from drive D: on the local computer to the install.wim file, saving it on a shared network folder on another computer mapped as drive Z: (#8):

dism /capture-image /imagefile:Z:\install.wim /capturedir:D:\ /name:"Recovery" /compress:maximum

Capturing custom Windows image. Click to open enlarged in a new tab.

The switch named /imagefile: followed by a path and filename tells the DISM command where to save the captured Windows image. Switch /capturedir: followed by the drive letter, colon and backslash tells DISM which drive contains the Windows installation I want to capture.

When it’s done, close the Command Prompt and restart the computer booting back to Windows normally.

Check the size of your captured custom install.wim file. In my case it was just under 7 GB:

Create a new partition on any internal disk. Make that partition one GB bigger than your install.wim and name it Recovery. Notice that if you create this partition on the same disk where Windows is installed, and that disk gets corrupted, you will also lose the Recovery partition. Therefore I recommend that you create the custom recovery partition on another disk. However, assuming your system disk will not die, you can also create the Recovery partition on it and use it anytime you need to restore a “factory recovery” image of your own making.

Download the latest Windows 10 ISO image, any edition. Mount it as a virtual DVD (double click, or right click and select Mount), copy its contents to your new Recovery partition. Browse to the Sources folder on your new Recovery drive, and delete the install.esd or install.wim file (only one of these will be present). Copy the captured custom install.wim file to this folder to replace the ESD or WIM file you just deleted (Recovery drive, Sources folder).

Open Notepad or any other text editor and paste the following code to a new text file. For my example, the Recovery drive has drive letter F: (highlighted blue in below code sample), change all three instances of drive letter F: to whatever drive letter your new Recovery drive uses:
bcdedit /create {ramdiskoptions} /d "Ramdisk"
bcdedit /set {ramdiskoptions} ramdisksdidevice partition=F:
bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
for /f "tokens=2 delims={}" %%i in ('bcdedit.exe /create /d "Recovery" /application OSLOADER') do (set guid={%%i})
bcdedit /set %guid% device ramdisk=[F:]\sources\boot.wim,{ramdiskoptions}
bcdedit /set %guid% path \windows\system32\winload.efi
bcdedit /set %guid% osdevice ramdisk=[F:]\sources\boot.wim,{ramdiskoptions}
bcdedit /set %guid% systemroot \windows
bcdedit /set %guid% winpe yes
bcdedit /set %guid% detecthal yes
bcdedit /displayorder %guid% /addlast

Please notice: lines 4 & 5 in the preceding code sample belong together but are shown as two text lines here because of word wrap. Line do (set ID={%%i}) is not its own command line, it belongs to and must be at the end of  the line preceding it. Here’s a screenshot:

Batch file in Windows Notepad. Click to open enlarged in a new tab.

Save the file as a Windows batch file with the extension .bat, and name the file as you wish. I named it  recovery.bat, saving it onto the desktop (folder C:\Users\Kari\Desktop).

Open an elevated Command Prompt, Enter the following command, replacing the path and filename with your actual values:

C:\Users\Kari\Desktop\Desktop\recovery.bat

The batch file now creates a custom recovery environment and adds it to the Windows boot menu:

Running recovery.bat. Click to open enlarged in a new tab.

That’s it! Your Recovery partition is created and added to Windows boot menu:

When the Recovery boot option is selected, normal Windows Setup will be run and you can clean install your custom Windows from the newly created Recovery partition, with all settings, themes, installed software and applications, drivers and user profiles exactly as they were at the moment when you captured the custom image.

Notice that if the disk where Windows is installed gets corrupted, or if you replace the disk with the new one, the boot menu is not shown. In that case simply boot the PC from WinPE or install media, open Command Prompt and check drive letters with DISKPART as told above, then run Windows Setup from Recovery drive. For instance, if DISKPART shows your recovery partition as drive R: you can start restoring simply using this command: R:\Setup.exe.

In case you want to prepare for a total hard disk failure which forces you to replace all disks, or if you just want to be prepared for every scenario, you can also create a bootable USB flash drive from the contents of the new Recovery drive. This will give you a “recovery-on-stick” tool allowing a fast recovery using your custom recovery media simply by booting computer from USB flash drive and running Windows setup from it.

Enjoy!

Kari

Author: Kari Finn

A Windows Insider MVP, Kari started in computing in the mid 80’s writing code for VAX / VMS systems. Since then, he’s worked in a variety of IT positions. He specializes in Windows image capture, customization, repair and deployment as well as Hyper-V virtualization. Kari is a proud Team Member at number #1 Windows site TenForums.com.

Leave a Reply

This website stores some user agent data. These data are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to opt-out of any future tracking, a cookie will be set up in your browser to remember this choice for one year. I Agree, Deny
614