What's new

Guide for Creating a Customized Recovery Image on Surface Pro/Surface Pro 2

ixtapalapaquetl

New Member
Guide for Creating a Customized Recovery Image on Surface Pro/Surface Pro 2

I am a power user who lives almost exclusively on the desktop, with only occasional forays into Metro-land. For various reasons I do not trust my data to be stored on the cloud, so I do not make extensive use of SkyDrive. For these reasons, when Windows starts getting mucked up and I want to go for a Reinstall through Recovery, backing up all my data and reinstalling my non-Metro apps is a tedious annoyance. What follows is a method to get around these issues.

This guide will bring about the following changes in the behavior of your SP1/SP2:

• Your User Profile directory (so all of your Documents, Photos, Desktop, etc. folders) will be moved from the Windows partition onto a separate partition. This will be done natively by the operating system, and thus you will not need to resort to the use of junctions or registry hacks.

• Using “Remove Everything and Reinstall” (accessed through Recovery in the Charms menu) will not only reinstall Windows 8.1, but will also automatically reinstall all of your other applications and Windows settings. Once you have fixed your computer's state, you can return to that exact state at any time in the future, regardless of what other changes you make to your computer.

• Since your User Profile directory is no longer on the Windows partition, this data will remain completely untouched by the Reinstall process, thus eliminating the need to back up your data prior to reinstallation.

• This process will not be dependent on any third party software, but rather will use native Windows functionality. Documentation for each phase can be found on Microsoft’s TechNet.


I have successfully tested this guide on both an SP1 and an SP2 (though I have very real concerns that there will not be enough room on a 64GB SP1 – 128GB is OK, but tight). When Windows starts acting up on me, I simply initiate a Reinstall through Recovery, and I am back to my initial environment with all my data untouched – the whole process takes maybe 5 minutes for the reinstallation to complete. Painless, and no additional software or external drives are required.


OVERVIEW:

Phase I will tell Windows to look for your recovery directory in a folder you have easy access to rather than a hidden partition.

Phase II will create an initial recovery image (a file named install.wim), and inject any drivers you choose into this image. During this phase you may inject any drivers you wish. You should certainly include the telemetry driver that is missing from the OEM Reinstall image. Injecting the telemetry drivers into the image resolves a familiar issue in Device Manager, and may resolve a battery drain issue when using a keyboard. But you may also easily include the latest Intel video drivers, Wacom drivers for the pen, and any drivers for any peripherals you might wish to use. Once injected, these drivers will be available within Windows for all subsequent reinstallations.

Phase III will involve deleting the old recovery partition, recapturing the newly created extra space, and creating a new partition for use by the User Profile directory.

Phase IV moves the User Profile directory to the partition that was just created.

Phase V allows for creation of a custom installation image that includes all your applications, settings, and tweaks. This image will then replace the default image, allowing Windows to return you to this state at the press of a button, except for your data which will remain untouched.


CAVEATS:


I highly recommend starting this guide from a clean install (detailed in Phase 0). It is possible to adapt this procedure to work from an existing installation, but doing so introduces many unnecessary bugs into Windows. In particular, moving the User Profile directory after already having installed your software leads to some undesirable system behavior, and thus should be avoided. Starting from Phase 0 and following the remaining phases in order ensures that Windows does not get confused regarding the location of critical folders. This guide balances convenience against reliability – the amount of effort required to get a current installation working without error is much greater than the effort required to just install everything from scratch.

Also, this procedure is rather unforgiving of errors. You won’t brick your SP, but you will likely need to start over from a clean install if any mistakes are made. I strongly suggest that you use the same folder/file names as used in the guide to minimize the chance of error. If you do not have a lot of command line experience, it might be a good idea to create a Recovery USB drive for use in the event that you can’t boot up. This is an unlikely, but possible, outcome that can be avoided completely by carefully adhering to this guide.

Finally, it has been suggested elsewhere that upgrades to Windows 9 might be broken by moving the User Profiles to another drive. I obviously can’t test that hypothesis now, but in the worst case scenario, all that would be required would be reverting to an OEM image, upgrading the operating system, and then starting the guide over. No changes are so permanent that they can’t be simply written over.


INSTRUCTIONS:

PHASE 0: Create a pristine environment

In this phase you will be removing all information from your computer. Thus, you will need to back up any data to you have to an external drive, as well as any third party installation software or passwords. When this phase concludes, your computer will be in the same state as when you first got it. Do not begin this process until everything you want to save has been safely moved to another drive.

1) Initiate an OEM Reinstall: Charms > Change PC Settings > Update And Recovery > Recovery > Remove Everything And Reinstall Windows > click Get Started.

2) When this operation is complete and you are ready to enter Windows for the first time, create a temporary user “temp1” (this user will be deleted later) and log in. For simplicity's sake, I suggest that you create a Local Account rather than a Microsoft Account.

3) Go to Windows Update and fully update the new installation. Continue checking manually for updates until you are told there are no available updates remaining. If you are on a SP1 (or possibly an older SP2), you will need to go to the Windows Store to upgrade to Windows 8.1. When that has completed, check again for further updates using Windows Update. It is important to be fully updated on Windows 8.1 before proceeding to the next phase.



PHASE I: Move the Recovery directory

We begin by directing Windows to use C:\Recovery as the recovery folder rather than the hidden partition it natively uses. The customized image that we will create in Phase V will likely be too large for this undesirable recovery partition, necessitating this move. In order to allow this move to take place, we will need to create a temporary dummy file called install.wim (which will be replaced with an actual image in the subsequent phase). Be sure that Windows is set to show file extensions so that you can properly rename the .txt file.

We will need to use an “elevated command prompt” many times throughout this guide when we make use of the command line. One quick way to do this is Charms > Search > type Powershell. Hold the Powershell icon a moment and choose Run as Administrator from the popdown menu. This must be done for all elevated command line entries in this guide. I will bold these commands as a reminder.

1) Create the folders C:\Recovery, C:\drivers, and C:\mount

2) Use Notepad to create a blank text file and save it in C:\Recovery. Rename this file as install.wim (confirm yes to changing the file extension). You must have Windows set to display File Extensions!

3) Open an elevated command prompt and enter

reagentc /setosimage /path C:\Recovery\install.wim /index 1



PHASE II: Creating an initial image and injecting drivers

Windows uses a file called install.wim when it installs itself onto your hard drive. The big idea behind this guide is to replace that file with one of our own making so that next time it installs, it does it with all the things we want already included. Unfortunately, the OEM install.wim is missing some necessary drivers for the SP, so this needs to be addressed before going any further. And since we already have to inject some drivers into the image, we may as well inject any other drivers you will need as well.

1) Download the Surface Driver packages from Microsoft: SP1 from here and SP2 from here. For SP2, you can also grab the Intel Display Driver.

2) Unzip and place the resulting folders in C:\Drivers. Place any additional drivers you want included in your image into C:\Drivers as well. You may wish to include among these the Wacom drivers (and for SP1, the Intel display drivers).
We will now make a preliminary image and inject the drivers from C:\Drivers into it. Each of these steps will take a little while.

3) Go to Charms > Change PC Settings > Update And Recovery > Recovery > Advanced Startup > click Restart Now.

4) Once restarted, Troubleshoot > Advanced Options > Command Prompt. After rebooting, select the user temp1 and enter your password. The command prompt you see is already elevated, so you will not have to do anything special in 5) and 6) below.

5) Create a new image by typing in the command prompt

dism /capture-image /capturedir:C:\ /imagefile:C:\Recovery\install.wim /name:OEMwithdrivers /compress:max

This will take several minutes.

6) To inject the drivers, type

dism /mount-image /mountdir:C:\mount /imagefile:C:\Recovery\install.wim /index:1

When that completes, type

dism /image:C:\mount /add-driver /driver:C:\Drivers /recurse

Then finally

dism /unmount-image /mountdir:C:\mount /commit

When the last command finishes, close the command prompt, exit Windows, and boot up again. We now have an OEM Windows 8.1 install.wim with your drivers added in. You may now delete C:\mount and C:\drivers, but DO NOT delete C:\Recovery.



PHASE III: Managing the hard drive

We will need to use diskpart to do some hard drive management here, as the now defunct hidden recovery partition is protected and thus can only be removed via diskpart. Afterwards, a new data partition will be created within Windows.

1) Open an elevated command prompt and type diskpart.

2) Type

select disk 0

3) Type

list partition

4)
If you only see one partition labeled Recovery, go to the next step. If you have two partitions labeled Recovery, identify the partition number of the larger recovery partition (sized at several GB – not 300MB). Replace the “n” below with the number assigned to the recovery partition. Obviously you need to be careful to not delete the wrong partition, so make sure you use the right number for n.

select partition n
delete partition override


5) Type exit

6) Open Disk Manager (Charms > Search > disk and click Create and Format Hard Drive Partitions)

7) Right click on the bar representing C: and shrink it down to a smaller size. The smaller this partition is, the larger your data partition will be.

8)
Right click on the space next to C: bar and create a new partition. Then right click the new partition bar and assign the partition the letter D.



PHASE IV: Moving the User Profiles directory

The steps below are a simplified version of a guide User Profiles - Relocate to another Partition or Disk . If you are not using the exact commands/folder structure I use below, I strongly recommend that you familiarize yourself with the guide in the link before proceeding, as this phase is very sensitive. Errors here will definitely warrant starting over from Phase 0.

1) From an elevated command prompt type

C:\Windows\System32\Sysprep\Sysprep.exe /audit /reboot

and allow the computer to reboot.

2) Go to the desktop and click Cancel on the System Preparation Tool that is now open.

The following two steps are critical.


3) Move the file C:\Recovery\install.wim to D:\install.wim and rename it as OEMdrivers.wim. You must have Windows set to display File Extensions!

4) Open Notepad, paste the following text, and save the file as D:\relocate.xml. The formatting is not important (line breaks, tabs, etc.). You must have Windows set to display File Extensions!

THE NAMES AND LOCATIONS IN 3) AND 4) MUST BE EXACTLY AS STATED ABOVE OR YOU MUST ADJUST THE XML FILE BELOW ACCORDINGLY. Failure to do so will mess things up and you’ll have to start from Phase 0!

<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FolderLocations>
<ProfilesDirectory>D:\Users</ProfilesDirectory>
</FolderLocations>
</component>
</settings>
<cpi:eek:fflineImage cpi:source="wim:D:/OEMdrivers.wim#Windows 8.1" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>


5) From an elevated command prompt, type

net stop WMPNetworkSvc

If it says the service isn’t running, wait a few minutes and try again. If it still says it isn’t running,
go on to the next step.

6) Now type

cd c:\Windows\System32\Sysprep

followed by

.\sysprep /audit /reboot /unattend:D:\relocate.xml

7) After the reboot happens, go back to the desktop. Make sure the System Preparation Tool is set to Enter System out of Box Experience (OOBE) and Reboot, then click OK.

8) After the reboot, create a new user profile “temp2” and log in to Windows. Again, for simplicity's sake I suggest using a Local Account.

9) Finally, create what will become your actual final user account through Charms > Change PC Settings > Accounts > Other Accounts (be sure to set your actual user account as an Administrator!). Reboot, log in as this user, navigate once again to Charms > Change PC Settings > Accounts > Other Accounts, and delete the accounts for temp1 and temp2. Then navigate to D:\Users and manually delete the temp1 and temp2 folders if you see them there. You may need to change ownership and permissions of these folders to do so, try rebooting first though.

10) You may now delete D:\relocate.xml to tidy things up. Do not delete OEMdrivers.wim however; instead move that file a secure location. This image will serve as a failsafe if you ever need to go back to a vanilla installation with User Profiles on C: (though it will retain the drivers you have injected).



PHASE V: Preparing your custom image

At this point, all that remains is installing your apps, reimporting your data, and personalizing your Windows settings according to your preferences. Once you have everything set up just right, you are ready to make your final custom recovery image. Whatever state your computer is in before initiating these commands will be the state you return to through Reinstall. You will be able to return your computer to this current state at any time in the future.

1) Charms > Change PC Settings > Update And Recovery > Recovery > Advanced Startup > click Restart Now

2) Once restarted, Troubleshoot > Advanced Options > Command Prompt. After rebooting, select your username and enter your password.

3) Create your custom image by typing from the command prompt

dism /capture-image /capturedir:C:\ /imagefile:C:\Recovery\install.wim /name:customimage

4) That’s it! All done! Reboot and you are good to go.



VERIFICATION/USAGE:

And now for the moment of truth… at any point in time, you can return your computer's state to the custom state you created in Phase V by following the steps below. (If you want to test out your computer’s new functionality, put something on your desktop (anything will do) and uninstall a program (again, it doesn’t matter which one) before so you have changed the environment.)

1) Go to Charms > Change PC Settings > Update And Recovery > Recovery > Remove Everything And Reinstall Windows > click Get Started.

2)
Be sure to choose Only the Drive Where Windows is Installed or your data will be removed too!

Behind the scenes, Windows wipes C: clean except for your image in C:\Recovery. It will then take that image and write it to C: (including boot partitions). Once it is finished, your computer will be exactly as it was the moment before you began step 1) of Phase V with one notable difference – all of your User Folders will be untouched. You can see the program you uninstalled moments ago will be back and ready for use. You will also see that the file you placed on your desktop a moment ago is still there despite this Reinstall. This is because your desktop is now located on D:, and is thus untouched by the Reinstall process!


FINAL NOTES:

As time goes on, there may be further critical software/firmware updates etc. that you want incorporated into your custom image. My suggestion would be to do a Reinstall as detailed in the paragraph above, install whatever new software/updates you want, then repeat the steps in Phase V. This will overwrite the old install.wim image with your updated image, and you are then good to go.

If for any reason you want to go back to a vanilla Windows installation with the User Profiles on C:, simply copy the OEMdrivers.wim file you saved earlier to C:\Recovery, rename it install.wim, and go through the reinstall process. This will take you back to a point before you moved the User Profile and you can proceed from there (obviously your programs will not be installed). This may become important when it comes time to upgrade to Windows 9.

The big take away here is whatever image is in C:\Recovery is what you will get when you reinstall. This is so powerful. And no other software to worry about! I hope you find this guide to be useful. I will be checking in from time to time to answer questions that come up. Good luck and enjoy.
 
Last edited:

Kerplunk

New Member
Registered to say thanks. Would this method allow for a copying of the install.wim in C:\Recovery to another surface pro 2 tablet? in the event of hardware RMAs and such.?
 
OP
I

ixtapalapaquetl

New Member
Registered to say thanks. Would this method allow for a copying of the install.wim in C:\Recovery to another surface pro 2 tablet? in the event of hardware RMAs and such.?
Absolutely. I once dropped a SP2 install.wim on a SP1 (after injecting the SP1 drivers) with no trouble at all.

If you already have a custom install.wim, you would go through everything but Phase V on the RMA machine. Then instead of Phase V, you would just drop your image in C:\Recovery, initiate Reinstall, and reboot to your custom state. Once you get a good image you can really start playing around.
 

Kerplunk

New Member
I am having an issue on Phase 4 Step 9.

I seem to be stuck "hanging" after I create a new account and log in for the first time. It took 30 minutes before I saw the start screen and when I went to Change PC Settings it blacked out. I restarted and went back into the account and again said it was installing apps and settings. Is there a work around for this ?

Edited: It turns out all of my accounts had issues such as not being able to access C: or launch programs. I went ahead and copied the OEMdrivers.wim back into C:\Recovery renamed it install.wim and did a recovery. Everything went back to the way it was so success!

My question is what is the purpose of Phase 4 and Phase 5 if Phase 3 took care of the actual back up ?

Thanks again for this great method.
 
Last edited:
OP
I

ixtapalapaquetl

New Member
I am having an issue on Phase 4 Step 9.

I seem to be stuck "hanging" after I create a new account and log in for the first time. It took 30 minutes before I saw the start screen and when I went to Change PC Settings it blacked out. I restarted and went back into the account and again said it was installing apps and settings. Is there a work around for this ?

Edited: It turns out all of my accounts had issues such as not being able to access C: or launch programs. I went ahead and copied the OEMdrivers.wim back into C:\Recovery renamed it install.wim and did a recovery. Everything went back to the way it was so success!

My question is what is the purpose of Phase 4 and Phase 5 if Phase 3 took care of the actual back up ?

Thanks again for this great method.
Sorry for your troubles. I have had this happen before too when I was ironing out the process. Here is what I think the issue was: Phase IV requires access to an image while it is moving the User Profile directory. If it can't find that image, bad things happen while it tries. The original guide I used had me put that image on a USB drive. Once I attempted the move and forgot to plug in the USB drive and got behavior similar to what you describe. That's why I modded the process to make it more idiot proof - it doesn't matter where the image is, so I made it local. The .xml I posted tells Windows to look for the image it needs at D:\OEMdrivers.wim - my best guess at an explanation for what happened to you was that it didn't find it there. This is by far the most sensitive phase of the guide, sorry you had trouble!

That said, good on you for figuring out how to get yourself out of trouble! This is exactly why I designed the guide to have TWO images created. The first image OEMdrivers.wim is a failsafe. Without it, things can get pretty ugly when problems arise. With it, you just drop it into C:\Recovery, rename it, Reinstall, and you are up and running again. I figured there would be some inexperienced folk trying this out, and wanted to make sure they had an easy fix.

My guess is that while you still have a new partition D:, your actual Users Profile is on C: right now since OEMdrivers.wim was created before we told Windows to move it. To test this, place a file on your desktop. Then see if that file is on C:\Users\<username>\desktop or D:\Users\<username>\desktop. My guess is it is on C:. If that's the case, I'd do a quick format of D: (after backing up anything you need there like relocate.xml and OEMdrivers.wim), then I'd do a fresh Reinstall with the renamed OEMdrivers.wim as C:\Recovery\install.wim to make sure you're starting from a clean environment, and then finally start phase IV again making sure that you have a file D:\OEMdrivers.wim before proceeding.

The reason for the second image is that this is the image with all the apps installed on it - since you used OEMdrivers.wim, you should not have any apps installed. The real power of the guide is getting your good stuff on the install.wim image, which doesn't happen till phase V. After that, you can Reinstall with all your apps already in place, all your personalization done, all your tweaks set. It's awesome!

Let me know how it goes.
 

Kerplunk

New Member
It works!

Thanks for this method.

I just have a few questions about other implementations of this. What would it happen if install.wim was not in C:\Recovery? Would windows default back to the recovery partition ? (assuming I put it back in after getting rid of it) If not, how would I be able to access the recovery partition and restore from that?

Is there a way to install the install.wim in the event that I am no longer able to gain access to windows? Maybe something like a boot from USB or something?
 
Last edited:
OP
I

ixtapalapaquetl

New Member
It works!

Thanks for this method.

I just have a few questions about other implementations of this. What would it happen if install.wim was not in C:\Recovery? Would windows default back to the recovery partition ? (assuming I put it back in after getting rid of it) If not, how would I be able to access the recovery partition and restore from that?

Fantastic! Glad you got it sorted out.

I'm not 100% certain what would happen if install.wim was not in C:\Recovery, but I strongly suspect Windows would throw an error at you when you initiate the Reinstall and you would not be able to proceed. I'm not sure I understand what you are asking in the rest of your question - why would install.wim not be there? What I can tell you is that there is nothing special about C:\Recovery\install.wim other than that's where you told Windows the recovery directory would be. Now that you have a custom image and have moved your User Profile, it is easy to change the recovery directory. Just place install.wim wherever you want, then run Phase I step 3) again. You can even place it on a USB drive - but I really like having the image self contained on my computer so I can Reinstall if I'm out and about. Note that if you do move from C:\Recovery, you need to make a fresh image as your current image will put recovery back to C:\Recovery after Reinstall (I think).

Is there a way to install the install.wim in the event that I am no longer able to gain access to windows? Maybe something like a boot from USB or something?

Yeah, if you have a bootable Windows Recovery USB drive, you could boot to it and then choose Reinstall from there - it will ask Windows where the recovery directory is, and Windows will direct it to C:\Recovery.

This next trick is pretty sick (but not as clean as this guide). If you have a full Windows installation thumb drive (say E:), in the folder E:\sources there is a file called install.wim. Guess what happens when you replace it with your custom image? :) There are some cleanup files that are missing so you will have some extra junk folders on C: and a few bugs here and there, but it's still pretty sweet. That's what I used to do a long time ago when I was just learning about this stuff. But it's not nearly as clean as following this guide.
 

Kerplunk

New Member
I'm not sure I understand what you are asking in the rest of your question - why would install.wim not be there?

I previously had my recovery partition backed up to an external because I thought I needed space. In that case, would it be possible to restore my backed up recovery partition and tell Windows to look into the recovery partition instead of the C:\Recovery? The purpose of this is in the event I wanted to sell or get rid of the Pro2 I think I would prefer to have it be in a "from the microsoft store state".

My question regarding the USB drive is because I also backed up my install.wim to a flash drive since it is 50+gigs. In the event of a complete "oh no' situation I could pop the flash drive in and be up and running.
 
Last edited:
OP
I

ixtapalapaquetl

New Member
I previously had my recovery partition backed up to an external because I thought I needed space. In that case, would it be possible to restore my backed up recovery partition and tell Windows to look into the recovery partition instead of the C:\Recovery? The purpose of this is in the event I wanted to sell or get rid of the Pro2 I think I would prefer to have it be in a "from the microsoft store state".

My question regarding the USB drive is because I also backed up my install.wim to a flash drive since it is 50+gigs. In the event of a complete "oh no' situation I could pop the flash drive in and be up and running.

Now I get it. Yeah, no prob. As I stated last time, the reagentc command in Phase I, step 3) puts the recovery directory wherever you want it (I suspect that's what you did initially when you moved it off the hidden partition?). As long as you have an install.wim, you can use reagentc to point at your "from the microsoft store state", Reinstall and you'll be good to go (after deleting D: and recapturing the space with C:). Again, Windows will look wherever you want with reagentc.

So I think the procedure would go something like this:

1) Shrink D: so you have enough room for the hidden Recovery partition
2) Use the guide you originally used to get the Recovery partition back on (there are some things you will need to do in Diskpart to make it "microsoft state" - guid attributes or some such) including the original install.wim. You will need to assign a letter to this partition, say R.
3) Use reagentc to point at R:\install.wim
4) Reinstall
5) Delete D:, expand C: to recapture the new space
6) Unassign R:
7) Profit
 

Kerplunk

New Member
Now I get it. Yeah, no prob. As I stated last time, the reagentc command in Phase I, step 3) puts the recovery directory wherever you want it (I suspect that's what you did initially when you moved it off the hidden partition?). As long as you have an install.wim, you can use reagentc to point at your "from the microsoft store state", Reinstall and you'll be good to go (after deleting D: and recapturing the space with C:). Again, Windows will look wherever you want with reagentc.

So I think the procedure would go something like this:

1) Shrink D: so you have enough room for the hidden Recovery partition
2) Use the guide you originally used to get the Recovery partition back on (there are some things you will need to do in Diskpart to make it "microsoft state" - guid attributes or some such) including the original install.wim. You will need to assign a letter to this partition, say R.
3) Use reagentc to point at R:\install.wim
4) Reinstall
5) Delete D:, expand C: to recapture the new space
6) Unassign R:
7) Profit

awesome, thanks!
 
Top