We won the WORLD CUP!!!!

Somos campeones del mundo!!

We are the champions!!

IMG_0302 (Medium)

Creating Windows OEM recovery DVDs with Windows AIK (part 2)

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)

SELECT DISK 0                               
CLEAN                                       

EXIT

image

 

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

image

 

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.

  1. 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).
  2. 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.
  3. After the files are copied I copy imagex to e: and start restoring
  4. Then I create the boot for the new Windows
  5. 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)
  6. 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.

Posted in Windows AIK. Tags: . 11 Comments »

Creating Windows OEM recovery DVDs with Windows AIK (part 1)

This post follows the previous post in were I explained how I bought a new ASUS laptop with preinstalled Windows 7 PRO x64 OEM and they didn’t give me the restore DVDs. Instead they had a retarded restoring system that relied on a 20GB partition in the HD that got useless when I changed my Partitions to use the Striped and Mirror features that come with the OS.

In this post I’ll explain how to manually create a set of DVDs from the original ASUS system image files named asus.swm, asus2.swm and asus3.swm. This method can be used for other brands that have the same type of lame restoring system or if you want to split an image bigger than the size of a DVD (usually the split is named install.swm install2.swm install3.swm).

After you finish reading your post you’ll be able to create a set of DVDs/CDs of the size you want and have a bootable DVD/CD that will automate the restoring and prompting to introduce the next disk. I’m going to add as many details and explanations as I can to allow non developers to be able to understand the process and create their set of DVDs. So if you find it too easy, skim through. If you find it still complicated, add a comment and I’ll try to give more samples (you can read the MS documentation as well).

To create the recovery DVDs we are going to need “Windows Automated Installation Kit for Windows 7” (Windows 7 AIK) installed (you can download it and install it for free). This is the set of tools that the laptop manufacturers use create the images that are installed in your system. This post can also be used as a tutorial to understand the process of deployment using Windows 7 AIK (the steps used here are taken out from Microsoft documentation and they are using the tools that MS has made freely available to users to deploy Windows in an alternative way to standard setup). I take no responsibility of any errors in the scripts that I’ll be providing in the next post and I take no responsibility of the information that could be lost by using these steps. Please take your time to read the official Microsoft documentation about the tools and the risks of using them (http://technet.microsoft.com/en-us/library/dd744356%28WS.10%29.aspx) and remember that restoring the image will wipe out all the data in your HD so you need to run a backup of your data before you restore your system. And remember that these instructions should never be used to install Windows in a computer other to the one that you have paid the license for (no license no install). Please read read your Windows license agreement before following the steps to install your Windows image.

Lets get started!

Before we start with the process ne need to have the full image file (install.wim or asus.wim or image.wim) or the image already split in parts (asus.swm, asus2.swm and asus3.swm or install.swm install2.swm install3.swm). If you want to change the size to use double layer DVDs or CDs or a Blu-Ray or any other thing, you can join your image and then split it back in the size that you want. To do that you can use imagex command to:

Split an image file:

  • imagex /split C:\imaging\asus.wim D:\imaging\asus.swm 4000
  • imagex /split C:\imaging\install.wim D:\imaging\install.swm 4000

Join an image file:

  • imagex /ref asus*.swm /check /export asus.swm 1 asus.wim
  • imagex /ref install*.swm /check /export install.swm 1 install.wim

Now that we have our images with the size that we want, we are going to start.

Create a bootable DVD to start the process

To restore the system we need to create a bootable DVD with all the tools required to boot, configuration files to create partitions and scripts to restore the image.

In this process I will assume that we have installed Win AIK in the standard path (c:) and that we want to do the work in the d: drive.

    1. Start Windows AIK command line as an administrator

image

  1. Get the required files for the boot DVD (boot image with standard MS tools)
    • copype.cmd x86 d:\winpe_x86
  2. Mount the image to add custom restore scripts (this is similar to mounting an ISO but here we use a folder for you to modify the files)
    • imagex.exe /mountrw d:\winpe_x86\winpe.wim 1 d:\winpe_x86\mount
    • mount winpe.wim (MS boot image) in the folder that we specify)
  3. In this step we will copy the restore script and the commands to re create the disk partitions (I’ll explain this later in the next post). However, with the DVDs you can already manually restore your system once you boot with the first restoring disk (the process requires to create 2 partitions, 1 for Windows and 1 to copy the *swm files)
        • restore.cmd: script to restore the system automatically
        • clear_partitions.txt: Cleans the Hard drive
        • create_partitions.txt: Creates the partitions before restoring the image

    copy restore.cmd d:\winpe_x86\mount\Windows\System32\
    copy clear_partitions.txt d:\winpe_x86\mount\Windows\System32\
    copy create_partitions.txt d:\winpe_x86\mount\Windows\System32\

  4. Modify startup to call our restore script (This step required opening notepad as administrator. You can launch it from an Administrator command line)
    • notepad.exe d:\winpe_x86\mount\Windows\System32\System32\startnet.cmd
    • startnet.cmd is the script the is executed when booting the DVD. We need to add an extra line at the end of the file to call our restore.cmd script
      image
    • What we have done here is to call our script to start the restoring process. This allows us to create an automated restoring process for simplicity.
  5. Save the changes in the customized image (commit the changes to the mounted boot image)
    imagex.exe /unmount /commit d:\winpe_x86\mount
    imagex.exe /unmount d:\winpe_x86\mount
    imagex.exe /unmount /cleanup

    Note: For some reason, sometimes the first command sometimes doesn’t do all the work and there are files still hanging around. Most likely the command has successfully updated the image but it can’t unmount and release the files. If this happens, you need to close all the Windows Explorer windows and run the second and third commands (some times even several times) until “imagex.exe /unmount /cleanup” tells you that nothing is mounted.
  6. Create the DVD folders (each folder will be one DVD)Create folders:
    d:\ASUS\DVD1\sources (this will be the bootable DVD)
    d:\ASUS\DVD2\sources
    d:\ASUS\DVD3\sourcescopy asus.swm d:\ASUS\DVD1\sources
    copy asus2.swm d:\ASUS\DVD2\sources
    copy asus3.swm d:\ASUS\DVD3\sources
  7. Add extra required tools to DVD1 to make the DVD bootable and copy the program used to restore the system
    xcopy /y /e d:\winpe_x86\ISO\*.* e:\ASUS\DVD1\
    copy “C:\Program Files\Windows AIK\Tools\x86\imagex.exe” d:\ASUS\DVD1\
  8. Copy customized boot to DVD1 (created in step 6)
    • copy d:\winpe_x86\winpe.wim d:\ASUS\DVD1\sources\boot.wim
    • Notice the change of name. The destination name must be boot.wim
  9. Create the disk images (notice that the first one is bootable)
    oscdimg -m -n -b”d:\winpe_x86\etfsboot.com” D:\ASUS\DVD1 D:\ASUS\DVD1.iso
    oscdimg -m -n D:\ASUS\DVD2 D:\ASUS\DVD2.iso
    oscdimg -m -n D:\ASUS\DVD3 D:\ASUS\DVD3.iso
  10. Burn images to DVDs (with Windows 7 right click on the ISO and choose burn)
  11. Congratulations! You have created your set of restoring DVDs.

In the next post I’ll explain how to fully automate the process creating the scripts from the step 4.

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.

Posted in Windows AIK. Tags: . 16 Comments »
Follow

Get every new post delivered to your Inbox.