Windows, yes Windows.

Standard

Rain, apathy and boredom. That is how the last few weeks have been. To make things worse, I was pushed into this new project forcing me to dabble with Windows 8.1 and its deployment process.

So apparently, you may think “Deploy Windows 8.1? You had to write a blog for that?!”. Well let me tell you, you fuck stick, there is a difference between installation and deployment. You do an installation when you set up everything from a brand new Windows CD. Deployment is a process where you directly apply a pre configured Windows image to the system. Got it? Good.

So before starting… or just lets start, yeah. You have to download some stuff before you start. To be more elaborate, what you are downloading is Windows Assessment and Deployment Kit (ADK). It is a suite of tools required to configure and deploy Windows 8 on a machine. Please follow instruction on how to obtain and how to install Windows ADK on your machine. I assume that you have done so.

We will start with Windows Pre Installation Environment or WinPE. It is a scaled down version of the failed Windows Vista and provides a minimal command line interface to run deployment and other scripts. After you install Windows ADK, you’ll have WinPE with other tools… we make a copy of it.

If you installed the ADK, you’ll have a command line environment called Deployment and Image Servicing Tools (DISM), you must run this as an admin:

pic1

Once it starts up, assuming that your PC is 32 bit (mine is), fire off the command:

copype x86 C:\winpe_x86

replace “x86” with “amd64” if you are on a 64 bit machine. This will copy the required files into a folder named “winpe_x86” (create the folder beforehand).

We have to mount the image. Once upon a time that would have excited me because I was working on Linux. Now its just… boring. Fire off: (you’ll have to make a mount folder in the previously created folder)

dism /mount-image /imagefile:c:\winpe_x86\media\sources\boot.wim /index:1 /mountdir:c:\winpe_x86\mount

You can customize it. As an example, here is how to add packages for PowerShell and language packs and other dependencies for PowerShell. You can get commands to add packages all over the net.

dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFx.cab"
dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFx_en-us.cab"
dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
dism /image:C:\winpe_amd64\mount /Add-Package /PackagePath:"C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Powershell_en-us.cab"

Plug in a flash drive and install WinPe on it. Fire off: (after plugging in the flash drive of course, I’ll assume the drive letter is F:).

dism /unmount-image /mountdir:c:\winpe_x86 /commit
makewinpemedia /UFD C:\winpe_x86 F:

Now, starts the fun part. We will capture an image of the running system. To do so, you have to “Sysprep” the machine into Audit mode. Go to run and type “sysprep”. A window will open and you have to execute “sysprep” executable file.

pic2

from the first drop down menu, select Audit mode and make sure you have checked Generalize. Let shutdown options remain same. When the system shuts down, connect the flash drive created above and restart the system. It will boot into WinPE:

pic3

I have fired the “DISKPART” command which lists the current partitions on the hard drive. To capture an image then, you must do: basically, you are capturing the current state of the windows partition on your systems (C drive in most cases) to your pen drive (“install.wim”)

dism /capture-image /capturedir:c:\ /imagefile:F:\install.wim /name:"DeploymentTestImage"

Now that you have captured an image, lets customize it. Type exit to exit from WinPE and reboot the system. When the system reboots, you have to mount the captured image to customize it. Mount the captured image by typing the following in DISM command prompt (above): make a “mount” folder under C: before continuing

dism /mount-image /imagefile:f:\install.wim /index:1 /mountdir:c:\mount

When you navigate to “mount” folder, you can see that it looks like the C drive of your current system. Common folders like “PerfLogs”, “Windows\System32” etc are present. I’ll change the wallpaper as a basic customization as I’m not a Windows whiz kid. Navigate to Windows\System32\Web\Wallpaper. You’ll see the default wallpaper that you get when you do your first install (img0.jpg). Replace it with your own wallpaper. Note that you might have to take admin privileges to do that.

Dismount the image and commit changes:

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

Now again reboot the system whilst the flash drive is plugged in. Now,

If you are on a BIOS machine, this is the layout. We have to make partitions before deployment. We use “DISKPART” to make these partitions.

// Create Partitions BIOS
// These commands are used with DiskPart to
// set up the drive and create three partitions
select disk 0
clean
// System partition
create partition primary size=350
format quick fs=ntfs label="System"
assign letter="S"
active

// Windows partition
create partition primary size=15000
// Format Windows partition
format quick fs=ntfs label="Windows"
assign letter="W"
create partition primary size=10000
format quick fs=ntfs label="User"
assign letter="D" // the "D:\" Drive

// Recovery image partition
create partition primary
format quick fs=ntfs label="Recovery image"
assign letter="R" 
set id=27
list volume
exit

You can alternatively run create a text file (partitions.txt) with the above commands and run diskpart as:

diskpart /s partitions.txt

To deploy the final captured image, I made this batch file to automate the process (actually borrowed it):

rem    Usage:   ApplyImage WimFileName 
rem    Example: ApplyImage F:\install.wim ==

rem == Copy the image to the recovery partition ==
md R:\RecoveryImage
copy %1 R:\RecoveryImage\Install.wim

rem == Apply the image to the Windows partition ==
dism /Apply-Image /ImageFile:"R:\RecoveryImage\Install.wim" /Index:1 /ApplyDir:W:\

rem == Copy boot files to the System partition ==
W:\Windows\System32\bcdboot W:\Windows

:rem == Copy the Windows RE image to the System partition ==
md S:\Recovery\WindowsRE
xcopy /h W:\Windows\System32\Recovery\Winre.wim S:\Recovery\WindowsRE\

:rem == Register the location of the recovery tools ==
W:\Windows\System32\Reagentc /Setreimage /Path S:\Recovery\WindowsRE /Target W:\Windows

:rem == Register the location of the push-button reset recovery image. ===
W:\Windows\System32\Reagentc /Setosimage /Path R:\RecoveryImage /Target W:\Windows /Index 1

You can read about the command line options and documentation for the commands used any where on the web (if you google correctly).

Thats it. There, you have a pen drive having a custom Windows 8.1 image that you can deploy on any system. It will take half as much time as a full installation and automatically create partitions etc. I have started to like Windows 8.1… will see what else can I do.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s