Thursday, December 12, 2024

build a Windows 7 PE boot CD for VMWare Workstation with Defrag toolset

Sometimes you might need a Windows 7 boot CD which can be used with VMWare Workstation e.g. in order to fully defragment the HD. This article will quickly explain what is needed.

1.) download “The Windows Automated Installation Kit (AIK) for Windows 7” from here.

2.) Extract the ISO with winrar to C:\temp\aik (or somewhere else)

3.) In the extracted folder (C:\temp\aik) run the startcd.exe and choose Windows AIK Setup from the menu.

4.) run the “Deployment Tools Command Prompt” from the “Microsoft Windows AIK” menu on your computer as “run as administrator”

5.) In the command prompt from above, type the following below, using C:\PEBuild or another folder name (if another name is used the following steps needs to be changed to the new name!).

copype.cmd x86 C:\PEBuild\image

If you do now have a C:\PEBuild folder, please create one!

The command expects to create the build folder (our image folder), and will fail if the folder already exists!

6.) Create the folder “mounted” in “C:\PEBuild”

7.) Now we’ll use the ImageX tool to mount the default Windows PE image that ships with AIK in read/write mode on the local filesystem.

imagex /mountrw C:\PEBuild\image\winpe.wim 1 C:\PEBuild\mounted

8.) In order to run a automated defrag we need to copy over now some files. From the 32-bit Windows 7 workstation, copy:

C:\Windows\System32\Defrag.exe

C:\Windows\System32\shutdown.exe
to
C:\PEBuild\mounted\Windows\System32

and

C:\Windows\System32\en-US\Defrag.exe.mui
C:\Windows\System32\en-US\shutdown.exe.mui
to
C:\PEBuild\mounted\Windows\System32\en-US

9.) Build a defragnow.cmd with the following content (and save it in C:\PEBuild\mounted\Windows\System32):

@echo off
cls

IF EXIST C:\NUL (
Echo -----------------------------------------------
Echo Deleting C:\pagefile.sys now
REM dir pagefile.sys /ah
attrib -S -H c:\pagefile.sys
del c:\pagefile.sys /F /Q
defrag C: /U /V /W /X
Echo -----------------------------------------------
)

IF EXIST D:\NUL (
Echo -----------------------------------------------
Echo Deleting d:\pagefile.sys now
REM dir pagefile.sys /ah
attrib -S -H d:\pagefile.sys
del d:\pagefile.sys /F /Q
defrag D: /U /V /W /X
Echo -----------------------------------------------
)

echo finished!
REM instead of pause and exit a shutdown via shutdown -s -t 1 is needed. This is the default better way.
Pause
REM Exit
Echo The system will reboot now. This might take some seconds!
shutdown -s -t 1

 10.) Edit the file C:\PEBuild\mounted\Windows\System32\startnet.cmd and replace the content in it with:

wpeinit
@cls
defragnow.cmd

11.) Download the latest VMWare Tools (Windows x86, ISO) from here and store it in C:\PEBuild\downloads

12.) Extract the VMWare Tools ISO file via WinRAR to: C:\PEBuild\VMWareDriver

13.) Add the VMWare Driver now via:

Dism /Image:C:\PEBuild\mounted /Add-Driver /Driver:C:\PEBuild\VMWareDriver\pvscsi\pvscsi.inf
Dism /Image:C:\PEBuild\mounted /Add-Driver /Driver:C:\PEBuild\VMWareDriver\scsi\vmscsi.inf

14.) Now unmount the image via and commit the changes:

imagex.exe /unmount C:\peBuild\mounted /commit

 Please make sure you do not have a Explorer open or any other file in C:/PEBuild or the commit will fail!

15.) Now we need to copy the winpe.wim file we changed to the ISO folder in order to create a bootable ISO file.

copy /y C:\peBuild\image\winpe.wim C:\peBuild\image\ISO\sources\boot.wim

16.) Create a ISO file now

oscdimg.exe -n -b"C:\Program Files\Windows AIK\Tools\PETools\x86\boot\etfsboot.com" C:\PEBuild\image\ISO C:\PEBuild\pe-defrag.iso

17.) Boot from the iso file now. It should start automatically a defrag from your VMWare template/image.

 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

35FollowersFollow
- Advertisement -

Latest Articles