System Imaging Guide with ImageX and Windows PE
What is Windows PE?
Windows Preinstallation Environment (Windows PE) is a minimal Win32/64 operating system with limited services, built on the Windows 7 kernel. It is used to prepare a computer for Windows installation, to copy disk images from a network file server, and to initiate Windows Setup.
Windows PE is not designed to be the primary operating system on a computer, but is instead used as a standalone preinstallation environment and as an integral component of other setup and recovery technologies, such as Setup for Windows 7, Windows Deployment Services (Windows DS), the Systems Management Server (SMS) Operating System (OS) Deployment Feature Pack, and the Windows Recovery Environment (Windows RE).
------------------------------------------------------------------------------------------------------------------------------------------
We will be using Windows PE as a bootable system that will be completely independent of the HDD. That way we can take the image off of that system for later deployment.
You will need to install Windows AIK on the PC where you want to build Windows PE. The download can be found here:
http://www.microsoft.com/en-us/download/details.aspx?id=5753
Burn the image contents to a DVD or mount with an iso mounter then install it on your workstation PC. Install for just the account you are working from. Not everyone.
1. Open the Deployment Tools Command Prompt with admin privileges
Start > All Programs > Microsoft Windows AIK, right-click Deployment Tools Command
Right click -> open as administrator
2. Use the command copype.exe <arch> <destination> to copy the Windows PE files to a new directory
<arch> is the architecture (x86, x64) *note x64 might be labeled amd64*
<destination> is the location where the files will be copied to.
The complete command I used was
Copype.cmd amd64 c:\winpe_x64
That will create the folder winpe_64 with the necessary files to boot a 64 bit Windows PE
3. Use this command to copy and rename the winpe.wim file
Copy c:\winpe_x64\winpe.wim c:\winpe_x64\iso\sources\boot.wim
4. Copy imagex to the Windows PE boot cd
Copy c:\<path to Windows AIK>\tools\amd64\imagex.exe c:\winpe_x64\iso\
This will add imagex.exe to the iso folder.
** At this point you can either use a CD\DVD or a USB drive. I’ll go through the steps for both**
5.1 USB - Get a flash drive that is completely empty. We are going to format it so all of the data on it will be lost
Open an administrator command prompt and run Diskpart
Next, run list disk
My USB drive was labeled as Disk 1. Your drive might be labeled differently.
Run these commands:
select disk 1
clean
create partition primary
select partition 1
active
format quick fs=fat32
assign
exit
5.2 Copy the contents of the iso folder to the USB or build an ISO to be burned to a CD/DVD later with the following command
*note this command is for a CD\DVD only*
Oscdimg -n -bC:\winpe_x64\Etfsboot.com C:\winpe_x64\ISO C:\winpe_x64\winpex64.iso
You should now have a fully bootable Windows PE device.
Generalize the install
Setup a pc with all of the necessary software that you want included in your image. Make sure that you have all of the configurations in place. Any configurations that you make after the image is taken will need to be done separately after every install of the image. Be sure to update Windows and clean up any left over documents that you do not want in the image.
*Sysprep is here for reference. Do not use for cloning drives!*
Sysprep Overview
The System Preparation (Sysprep) tool is used to change Windows® images from a generalized state to a specialized state, and then back to a generalized state. A generalized image can be deployed on any computer. A specialized image is targeted to a specific computer. You must reseal, or generalize, a Windows image before you capture and deploy the image. For example, when you use the Sysprep tool to generalize an image, Sysprep removes all system-specific information and resets the computer. The next time that the computer restarts, your customers can add user-specific information through the Out-Of-Box Experience (OOBE) and accept the Microsoft® Software License Terms. You can run Sysprep as either a command-line tool or a graphical user interface (GUI) tool.
We use sysprep to generalize the system and prepare it so we can grab an image that has no drivers that are tied to it. You can either call sysprep from CMD or from the GUI.
CMD -> run as administrator. You will get a prompt that looks like this
C:\Windows\System32>
Run the following commands to call sysprep from CMD
cd sysprep
sysprep /generalize
To use the GUI, navigate to C:\Windows\System32\sysprep\ Run sysprep.exe as administrator
When the system preparation tool opens make sure that the settings match to the picture below.
Hit OK to run sysprep with those options. It will generalize the install and shutdown the PC. Now you are ready to install the bootable Windows PE medium and grab the system image.
Grabbing the Image
Boot your Windows PE USB\CD\DVD. If you boot the HDD instead of Windows PE, you need to do another generalize and reboot. When it is fully loaded you will see a command prompt with the following
X:\windows\system32>
The first thing that you want to do is figure out what volumes you have on the system and what labels they have.
diskpart
list disk
The output will show you what disks (not partitions) are available on the system. Once you find what disks are available you can quit diskpart
exit
The output should be similar to this
Microsoft DiskPart version 6.1.7600
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: MININT-6ILNCG9
DISKPART>list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 465 GB 0 B
Disk 1 Online 465 GB 1024 KB
Disk 2 Online 3864 MB 0 B
DISKPART>exit
Leaving DiskPart...
Here we can see that my 500gb internal drive, 500gb external drive, and my Windows PE flash drive have been initialized by the system.
Next, you want to find what the labels of the partitions are. To do this you can use the command
dir <partition label>
So dir will show you the label of the volume, as well as the contents of that volume. Here is a sample output.
X:\windows\system32>dir c:\
Volume in drive C is System Reserved
Volume Serial Number is 5A2F-D07C
Directory of C:\
X:\windows\system32>dir d:\
Volume in drive D has no label.
Volume Serial Number is E031-299C
Directory of D:\
03/28/2013 02:22 PM <DIR> Intel
07/13/2009 07:20 PM <DIR> PerfLogs
04/02/2013 11:18 AM <DIR> Program Files
04/02/2013 08:19 AM <DIR> Program Files (x86)
03/28/2013 02:27 PM <DIR> swsetup
03/28/2013 02:21 PM <DIR> Users
04/02/2013 12:19 PM <DIR> Windows
0 File(s) 0 bytes
7 Dir(s) 461,311,115,264 bytes free
X:\windows\system32>dir e:\
The device is not ready
X:\windows\system32>dir f:\
Volume in drive F is New Volume
Volume Serial Number is FCE8-B463
Directory of F:\
03/19/2013 07:23 AM <DIR> Affective
02/28/2013 12:05 PM 2,612,672 anyconnect-win-3.0.10057-web-deploy-k9.exe
03/07/2013 12:44 PM 523,666,432 archive.pst
03/21/2013 10:48 AM <DIR> Blancco Test Files
11/19/2012 07:55 AM <DIR> Dell Latitude 6520 win7 64bit sp1
04/02/2013 03:53 PM 2,930 dir.txt
04/03/2013 06:55 AM 642 dirlist.txt
04/01/2013 01:31 PM <DIR> Firefox
03/31/2009 07:20 PM 217,769 grldr
04/02/2013 02:43 PM <DIR> HPImage
03/25/2013 01:42 PM <DIR> install stuff
12/21/2012 08:03 AM <DIR> MapPoint 2013
07/18/2012 10:18 AM 240 menu.lst
12/01/2006 08:37 PM 904,704 msdia80.dll
12/31/2012 09:19 AM <DIR> New folder
04/02/2013 06:12 PM <DIR> WorldShip 2013
9 File(s) 5,238,076,749 bytes
21 Dir(s) 409,609,949,184 bytes free
Volume in drive G has no label.
Volume Serial Number is 6266-088C
X:\windows\system32>dir g:\
Directory of G:\
03/28/2013 02:43 PM <DIR> boot
03/28/2013 02:43 PM <DIR> EFI
03/28/2013 02:46 PM <DIR> sources
07/13/2009 06:39 PM 383,562 bootmgr
07/13/2009 06:45 PM 667,712 bootmgr.efi
07/14/2009 07:10 AM 581,008 imagex.exe
3 File(s) 1,632,282 bytes
3 Dir(s) 3,875,164,160 bytes free
From the output I can see what partition labels I need to finish my commands.
C:\ - System Reserved
D:\ - Windows, Users, Applications... (what I want to build the image from)
E:\ - “the device is not ready” Most likely this is the CD\DVD drive. The device is on, but there is no media in the device. You may also see this if you have a card reader installed.
F:\ - External drive
G:\ - Windows PE bootable USB
Now that we know where everything is we can issue the command for capturing the image.
G:\imagex /capture D:\ F:\HPImage\HP_Image.wim “HP_Image”
To break that down here are the individual labels
G:\imagex – path to imagex on Windows PE device
/capture – argument for imagex giving the command to capture an image
D:\ - location of the generalized Windows install
F:\HPImage\HP_Image.wim “HP_Image” – location of where I want to save my image, what I want to name the image, and the “image label”
The command should run for about a half hour.
Once the command finishes you should now have an image saved to the external drive.
Deploying the Image
To deploy the image, we will need to boot the system with the new hard drive installed as well as our external drive and Windows PE device.
Boot to Windows PE and run diskpart
list disk
select disk <disk where you want to install>
the internal drive most likely listed as disk 0
select disk 0
clean
create partition primary [size=<n>]
you can either leave the size option out to have the partition use the entire volume or specify a size in mb.
create partition primary entire volume
create partition primary [size=92160] create a primary partition with a size of 92160mb/90gb
Mechanical drives can partition the entire drive. To maximize SSD Life make the primary partition 70%-80% of the full drive capacity.
select partition 1
active
format quick fs=ntfs label=OS
the label is not necessary but the functionality is there if you want to label it.
assign letter=C
*If you get an error saying that the label C is not available then one of the other devices may have grabbed the C as it’s label in windows PE. If that is the case go into disk part and reassign the media to another drive letter.
**these commands only necessary if you have a device labeled C:\ that is not the drive you want to image**
diskpart
…This is the output from my workstation desktop as an example…
Microsoft DiskPart version 6.0.6001
Copyright (C) 1999-2007 Microsoft Corporation.
On computer: KYLE-AFWS
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D RAW DVD-ROM 2048 B Healthy
Volume 1 E DVD-ROM 0 B No Media
Volume 2 C NTFS Partition 149 GB Healthy System
Volume 3 G Removable 0 B No Media
Volume 4 H Removable 0 B No Media
Volume 5 I Removable 0 B No Media
Volume 6 J Removable 0 B No Media
Volume 7 K Seagate Exp NTFS Partition 932 GB Healthy
Volume 8 L OS NTFS Partition 90 GB Healthy
I can see that I have a volume already labeled as C, so I need to move it from C to an unused letter. From the output above I would issue the following commands.
select volume 2
assign letter=M
That command will free up C as a label allowing you to assign the drive to be imaged as the new C:\ drive
select volume 8
select partition 1
assign letter=C
At this point we are now ready to pull the image down to the drive that we just set up. Referencing the output of the dir commands under the section “Grabbing the Image” the command for installing the image to your new drive would be
g:\imagex /apply f:\HPImage\HP_Image.wim 1 c:\
Breaking the commands down…
g:\imagex – is calling imagex from your Windows PE device
/apply – is an argument for imagex telling it to apply an image
f:\HPImage\HP_Image.wim 1 – location of the image file that you want to be applied. It is important that you use the exact file name as what is saved on the external device. The 1 is a version number. There is a possibility to have different versions of an image so mark the image to be applied as 1 unless there is another version that you want to use.
C:\ - where you want the image to be applied.
Imagex will now take the image and apply it to the C:\ drive. Once the imaging process is complete navigate to the C drive and install the boot configuration
C:
cd Windows\system32
bcdboot c:\windows /s c:
restart the PC without all of the external devices, install any missing drivers and setup the PC for the end user.