Wednesday, February 02, 2011

Create a bootable USB key with Windows using Barte PE / PE Builder

How to boot ISO image from USB device NTFS formatted.

# The situation:
- You have an USB drive (HDD or Stick) containing only one NTFS partition.
- You already have data on this USB drive and you don't want to format it or repartition it.
- You have a computer or several computers that can boot on USB devices
- You want to dump the partitions of these computers into files on the USB device and use that USB device as a recovery medium in case of computer crash or hard drive failure.

# What you need:
- computer with a BIOS allowing to boot on USB devices
- a USB device
- a windows XP SP2 installation CD or DVD
this is the system we want to boot
- when XP SP2 installation CD comes from DELL we need subinacl tool from Microsoft (download here: http://www.microsoft.com/downloads/details.aspx?FamilyID=E8BA3E56-D8FE-4A91-93CF-ED6985E3927B&displaylang=en)
- the windows XP server 2003 SP1 (here to download from microsoft: http://download.microsoft.com/download/1/2/7/127c5938-d36a-4405-9df1-f00d57495652/WindowsServer2003-KB889101-SP1-x86-ENU.exe)
Some of the files from this release are needed to update the XP SP2 boot files.
- BartPE (here to download: http://www.nu2.nu/pebuilder/)
BartPE is the free software that you will be using to create the bootable "live" Windows rescue disk
- Sherpya's XPE (here to download: http://sourceforge.net/project/showfiles.php?group_id=126922&package_id=140740)
XPE is an addition to BartPE (that is, a "BartPE plugin") that allows you to have a Windows-like desktop, Windows Explorer and other Windows tools (like the disk defragmenter) when you boot to the rescue environment


# Important notices
In the following, we assume that USB_DRIVE: is the drive letter of you USB device
Do not use any space in directory and file names as it may not always be supported by the tools we are using here.

# Make the USB drive bootable
1 -> Install windows XP on the USB drive from the installation CP
The easiest way to do so, is to install XP on the USB drive from the installation CD. For this purpose you may use any XP installation CD.
To do so, I changed the boot devices in order to boot from CD.
When you are asked about disk preparation, you may choose to install directly on the drive without formatting it.
This will modify the MBR of the disk so that it can boot windows XP.
When the files are copied you will be asked to reboot the PC.
You must do it, but don't try to reboot on the USB hard drive, windows XP would not boot and would show a blue screen!
This is because windows XP resets the USB ports and looses the USB device during boot...
You must then boot the PC on the internal hard drive of your PC.

2 -> Remove installed files form the USB drive.
Since we just wanted windows to make it bootable and need to used the server 2003 files, we must remove the XP SP2 installed files from the USB drive.
Remove the windows directory, as well as the NTDETECT.COM, ntldr, and any other file that was created by the windows installation. (you must check that you removed all hiden files like AUTOEXEC.BAT, boot.ini, CONFIG.SYS, IO.SYS, MSDOS.SYS, ...)

3 -> Copy USB boot files from XP server 2003 SP1
To solve this boot problem from XP, we use WP server 2003 SP1.
Extract the downloaded WindowsServer2003-KB889101-SP1-x86-ENU.exe file into a temporary directory.

> WindowsServer2003-KB889101-SP1-x86-ENU.exe -x

You will get a I386 folder.
From this folder:
copy setupldr.bin to USB_DRIVE:\ntldr
copy ramdisk.sy_ to USB_DRIVE:\ramdisk.sy_
copy NTDETECT.COM to USB_DRIVE:\
USB_DRIVE:
cd \
expand -r ramdisk.sy_

create a text file named winnt.sif with the following lines:
[SetupData]
BootDevice = "ramdisk(0)"
BootPath = "\I386\SYSTEM32\"
OsLoadOptions = "/noguiboot /fastdetect /minint /rdexportascd /rdpath=boot.iso"

This file will tell windows to copy the boot.iso image into a ramdisk and boot from it.
The RAMDISK is limited to 512MB, the ISO image has to fit this maximum size.

note: be careful, these files must not be compressed on the NTFS of your USB drive.

# create a ISO bootable windows XP Preinstalled Environment (PE) with BartPE

0 - Install Tools
a) install bartPE
let say you have installed it in c:\pebuilder3110a
b) install Macrium Reflect
let say you have installed it in c:\reflect


1 - Prepare the I386 folder
In order to create such an environment, BartPE requires you to have a windows installation CD.

a) copy the I386 folder from the CD to the harddrive
Some of the files must be modified with the server 2003 files, so the I386 folder must be copied onto an harddrive and updated.
Let say we copy the I386 folder into c:\pebuilder3110a\i386

b) update the I386 folder
create a srsp1 folder in c:\pebuilder3110a
From the previously extracted I386 XP server 2003 folder
copy setupldr.bin to c:\pebuilder3110a\i386\ntldr
copy ramdisk.sy_ to c:\pebuilder3110a\i386\ramdisk.sy_
copy NTDETECT.COM to c:\pebuilder3110a\i386\NTDETECT.COM

c) When the XP SP2 CD comes from DELL, the following steps must be done:
Dell delivery CD bring some issues to BartPE with file permission.
Using the DELL installation CD will lead BartPE to be unable to delete some file during the environment creation, so that it will not create the ISO file.
I found the solution on 911cd's forum (here: http://www.911cd.net/forums//index.php?showtopic=15138&st=0) and copy it here for convenience.

c.1) In c:\pebuilder3110a\i386, create a text file named fixdell.cmd with the following lines:
REM Version 1.4
reg query HKU | find /i "pebuilder" > fixdell.txt
for /f %%a in (fixdell.txt) do reg unload %%a
reg load HKLM\DELL setupreg.hiv
subinacl /subkeyreg hkey_local_machine\dell\controlset001\services\*\ /objectcopysecurity=hkey_local_machine\dell\controlset001\services
reg unload HKLM\DELL
del fixdell.txt
del /ah setupreg.hiv.log
echo Check output to see if there is any error.
pause

c.2) copy the previously downloaded subinacl.exe into c:\pebuilder3110a\i386.

c.3) run the fixdell.cmd script.

c.4) Create a folder fixdell in c:\pebuilder3110a\plugin
In c:\pebuilder3110a\plugin\fixdell create a text file named fixdell.inf with the following lines:
; Original file from Bart
; Updated 2009-12-01

[Version]
Signature= "$Windows NT$"

[PEBuilder]
Name="Fix Dell Windows XP OEM boot problems"
Enable=1

[SourceDisksFiles]
a320raid.sys=4,,4
aac.sys=4,,4
aarich.sys=4,,4
afamgt.sys=4,,4
ahcix86.sys=4,,4;required at least by Latitude D620 and D630
cercsr6.sys=4,,4
iastor.sys=4,,4
megasas.sys=4,,4
NvAtaBus.sys=4,,4
nvgts.sys=4,,4;required at least by Latitude D620 and D630
nvraid.sys=4,,4
nvrd32.sys=4,,4;required at least by Latitude D620 and D630
sisraid4.sys=4,,4;required at least by Latitude D620 and D630
symmpi.sys=4,,4

d) copy Macrim plugin
copy the Macrium folder from c:\reflect\PEBuilder to c:\pebuilder3110a\plugin

e) launch BartPE
Click on Plugin and use the button Activer to activate and unactivate a given plugin.
As it will reduce the ISO we will only activate the following:
[Sherpya] Windows XPE
[Sherpya] Windows XPE: Crypto
[Sherpya] Windows XPE: Defaults
[Sherpya] Windows XPE: DirectX
[Sherpya] Windows XPE: Help System
[Sherpya] Windows XPE: MMC
[Sherpya] Windows XPE: PnP & Multimedia
[Sherpya] Windows XPE: WMI
Check Disk (chkdsk.exe)
Customize
Fix Dell Windows XP OEM boot problems
Keyboard Layout (read PluginHelp)
Macrium Reflext
Nu2Menu
RAMDisk [Nu2 Productions]
Serial Mouse

Unactivate the other ones.

Then configure :
- the Source directory to point to your c:\pebuilder3110a folder
- the output directory where the environment will be generated (this is a temporary directory)
- select "create an ISO image" (or créer une Image ISO)