In this post I’m going to continue creating the scripts (and manual steps) to restore the windows image file and show alternatives to the creation of the DVDs. To fully understand the process I recommend reading the part 1 of this series.
By now you should have your set of restoring DVDs and the bootable DVD that includes the tools required to continue the process.
I’m going to start explaining the manual steps to restore the image, so you can understand what’s going on, and then I’ll give you the code for the restore.cmd script that can be used to restore the system automatically.
Important!!
Go and get yourself a coffee while you back-up your data, as the restoring process described here cleans the hard drive.
Create partitions
The first thing the we need to do is to clean the disk and create the partitions. To do that we will use diskpart.
The process involves creating 2 partitions. The first one is for Windows. Here I’ve used a 40GB but you can choose what you want. and the second needs to be al least 15GB to copy all the image parts, as the tool imagex doesn’t prompt for multi-disk image and we need to do this manually. I wouldn’t be too worried by now about the size of the partitions. I my case, once I had the system restored and Windows finished installing, I went to the Windows Disk Management tools and I resized the Windows partition and created some Striped partitions (RAID 0) to improve performance.
In case you need to use Windows HD encryption, you will need to create 3 partitions. 1st for the partition called “system” (this one will be the active one, and it doesn’t need a letter assigned as it’s hidden)
After booting from the boot DVD you will have a command prompt.
Type: diskpart
SELECT DISK 0
CLEAN
CREATE PARTITION PRIMARY SIZE=40000 (create a 40GB partition for Windows)
SELECT PARTITION 1
FORMAT QUICK FS=NTFS LABEL="Windows"
ASSIGN LETTER="C"
ACTIVE
CREATE PARTITION PRIMARY (create a second partition in the disk for the remaining)
SELECT PARTITION 2
FORMAT QUICK FS=NTFS LABEL="EXT"
ASSIGN LETTER="e"
EXIT
Copy image parts to disk
Now that we have the partitions we need to copy the image parts and the tool to restore the image to e:
In case you had the image parts in an external HD or USB Key or the second HD, you don’t need to copy the files locally. Instead you could connect your USB external HD and go to the next step (restore the image) because the system can detect the external HD when you plug it in and read the image directly from there (you only need to type the right source location)
copy d:\imagex.exe e:\
copy d:\sources\asus.swm e:\
(change to DVD 2 )
copy d:\sources\asus2.swm e:\
(change to DVD 3 )
copy d:\sources\asus3.swm e:\
Restore the image
Once we have the files in the HD e:, we need to go to e: (where we have the imagex.exe file) and apply the image to the HD c: with the next command
e:
imagex /ref e:\asus*.swm /apply e:\asus.swm 1 c:
The command:
- /ref e:\asus*.swm => tells the imagex program that the file is in several parts and needs to reference all the files called e:\asus*.swm
- /apply e:\asus.swm 1 c: => tells the imagex program that the file to apply is called e:\asus.swm (to create that file uses the /ref files) and it needs to apply from that file the image number 1 (because the tools support several images in a single file) to the HD called C:
This process can take a while, just wait until it’s finished.
Make the HD bootable
Now that the Windows image has been restored we need to make that image bootable. To do that we need to go the the restored Windows system files and run the bcdboot command.
CD c:\Windows\System32
BCDBOOT C:\Windows
Finished!
At this stage your system has already been restored and you need to reboot. Remove all your DVDs and restart the machine.
You can type wpeutil reboot to do so.
If everything went Ok, your system must be restarting and finishing the installation in the same way it did the first day that you used your computer. So finish the install, fix your partitions and uninstall all the rubbish that thy have installed by default. I also recommend to create a backup of your system once you have it the way you like it, and next time you can restore it to that state directly without having to do all these steps.
The scripts
To finish creating the fully automated restore you can use the following scripts (to continue the process in the part 1).
There are 2 txt files with the commands for diskpart to clean the HD and create partitions. The reason why is that depending on the HD partitions before restoring the system, when the restoring starts, the partitions are mounted in different drive letters. If this happens, the scripts don’t know which drive contains the tools and where to copy the image files. To solve that, what I have implemented is a 2 steps recovery. First, I check if the tools are in the expected location (it happens when the HD is clean). If the script can’t find the tools in the HD d:, then cleans the HD and restarts automatically. Next time the system boots, we know where we are and we can automate the process. There are better ways to do this, but this one works and I didn’t want to spend too long for a process that shouldn’t happen more than once or twice a year.
Diskpart clean HD (clear_partitions.txt)
Diskpart clean HD (create_partitions.txt)
|
SELECT DISK 0 CLEAN
CREATE PARTITION PRIMARY SIZE=40000 SELECT PARTITION 1 FORMAT QUICK FS=NTFS LABEL="Windows" ASSIGN LETTER="C" ACTIVE
CREATE PARTITION PRIMARY SELECT PARTITION 2 FORMAT QUICK FS=NTFS LABEL="EXT" ASSIGN LETTER="e"
EXIT
|
Restore.cmd
In this script I have added a bit of error checking, some CLS (clear screen) and messages to make it look a bit better and easier to use once it’s been deployed.
You can modify the script to adapt it you your convenience in case you have a different number of DVDs or you are creating images for other machines.
- The first section I check if the tools are where I expect. If they aren’t I clean the HD and I restart (I have explained this above).
- In the second section I check if the *.swm files are where I expect. If they aren’t I prompt to change the disk and try again. When you change the disk, some times it takes a couple of seconds for the system to pick it up, so be patient.
- After the files are copied I copy imagex to e: and start restoring
- Then I create the boot for the new Windows
- And I restart. I used the command ping to wait for 5 seconds and let the user see that it’s all good, but you can remove this step (ping -n 6 127.0.0.1 > nul each ping take 1 second)
- If there was any error I jump to the end and I finish the process
|
@echo off CLS @echo. ———————————————– @echo. Initializing Hard Drive @echo. ———————————————– @echo.
IF NOT EXIST d:\create_partitions.txt ( @echo. Cleaning the HD and rebooting afterwards diskpart /s clear_partitions.txt
wpeutil Reboot )
@echo. Initialising the HD diskpart /s d:\create_partitions.txt
if errorlevel 1 goto :errorPartitions
copy d:\imagex.exe e:\
CLS @echo. ———————————————– @echo. Copying the images from DVD @echo. ———————————————– @echo.
:retryFile1 IF NOT EXIST d:\sources\asus.swm ( @echo. @echo. File not found d:\sources\asus.swm @echo. Insert the DVD 1 and wait 5 secs. until DVD is loaded @echo. pause goto :retryFile1 ) @echo. @echo. Copying DVD 1 (d:\sources\asus.swm) copy d:\sources\asus.swm e:\ if errorlevel 1 goto :retryFile1
CLS :retryFile2 @echo. Insert the DVD 2 and wait 5 secs. until DVD is loaded pause IF NOT EXIST d:\sources\asus2.swm ( @echo. @echo. File not found d:\sources\asus2.swm in DVD 2 goto :retryFile2 ) @echo. @echo. Copying DVD 2 (d:\sources\asus2.swm) copy d:\sources\asus2.swm e:\ if errorlevel 1 goto :retryFile2
CLS :retryFile3 @echo. Insert the DVD 3 and wait 5 secs. until DVD is loaded pause IF NOT EXIST d:\sources\asus3.swm ( @echo. @echo. File not found d:\sources\asus3.swm in DVD 3 goto :retryFile3 ) @echo. @echo. Copying DVD 3 (d:\sources\asus3.swm) copy d:\sources\asus3.swm e:\ if errorlevel 1 goto :retryFile3
CLS @echo. ———————————————– @echo. Restoring image to drive C: @echo. ———————————————– @echo.
e: imagex /ref e:\asus*.swm /apply e:\asus.swm 1 c:
if errorlevel 1 goto :errorRestore
CLS @echo. ———————————————– @echo. Setting up boot partition @echo. ———————————————– @echo.
CD c:\Windows\System32 BCDBOOT C:\Windows
if errorlevel 1 goto :errorBoot
CLS @echo. ———————————————– @echo. Process Finished! @echo. The system will reboot in 5 seconds @echo. ———————————————– @echo. ping -n 6 127.0.0.1 > nul
wpeutil reboot
:errorPartitions @echo. There was an error cleaning the hard disk and creating the partitions. goto :end
:errorRestore @echo. There was an error restoring the image. goto :end
:errorBoot @echo. There was an error creating the boot. goto :end
:end
|
Congratulations!
At this stage you are smarter than the guys that developed the restoring system for ASUS because:
- you understand all the recovery process (the tech support has no idea and they will tell you that you can’t be happy and that you need to take the computer for them to restore it and waste your time for few hours)
- you are able to create a more flexible set of recovering disks (ASUS want you to be unhappy trying to restrict you how to use the computer that you have bought)
- You no longer have a 20GB partition in your HD.
If ASUS was smarter, they would give you the original install install disk (I would have paid a bit extra to avoid all the crap that they have put in my computer and that I have uninstalled anyways). They may probably get some extra cash from the companies of the preinstalled rubbishware they put in your machine, but in a long term, they end up paying back all that money because of they need a larger number of people in support to attend complains and answering users and they have to spend extra resources as electricity to keep your computer plugged-in while restoring.
Enjoy your coffee!!
Update: I have added a new post in where I explain how to fully customise the WIM image, update it with service packs and updates and remove bundled crap to create an updated and clean image that can be safely used to bring your computer to a clean state without the pain of running all the Windows updates again. Please check my post.