Windows PE

From ThinkWiki
Revision as of 01:34, 4 April 2010 by Newhren (Talk | contribs) (add USB-FDD boot option)
Jump to: navigation, search

Some utilities/drivers provided by IBM/Lenovo come only in the form of Windows executables (for example, Intel AMT firmware updates). And for people who don't use Windows OS on their computers it becomes impossible to use/apply them. Luckily, Microsoft provides Automated Installation Kit (aka AIK) for free to everyone with very few resctictions on usage (basically, they only prohibit using it as a substitute of a "real" OS, and allow to use it for any diagnostic and reapair tasks). The latest version is The Windows® Automated Installation Kit (AIK) for Windows® 7. Users of Windows OS can use this AIK to create bootable CD-ROMs and bootable USB-flash drives with Windows PE (or WinPE for short), which is essentially a stripped-down version of Windows. In this article we will explain how to create bootable CD-ROMs and USB-flash drives with WinPE using only FOSS software.

How to build a bootable WinPE *.iso image

  • From the AIK installation file KB3AIK_EN.iso, provided in the form of a UDF disk image, use 7z (from p7zip) to extract the files wAIKX86.msi and WinPE.cab
  • use 7z or cabextract to unpack these files into /tmp/wAIKX86.msi/ and /tmp/WinPE.cab/ respectively
  • create a bootable WinPE *.iso image /tmp/winpe3_x86.iso
cd /tmp
mkdir -p winpe3_x86/boot
mkdir -p winpe3_x86/sources
cp wAIKX86.msi/F_WINPE_X86_etfsboot.com winpe3_x86/etfsboot.com
cp wAIKX86.msi/F1_BOOTMGR winpe3_x86/bootmgr
cp wAIKX86.msi/F_WINPE_X86_bcd winpe3_x86/boot/bcd
cp wAIKX86.msi/F_WINPE_X86_boot.sdi winpe3_x86/boot/boot.sdi
cp WinPE.cab/F1_WINPE.WIM winpe3_x86/sources/boot.wim
genisoimage -sysid "" -A "" -V "Microsoft Windows PE (x86)" -d -N -b etfsboot.com -no-emul-boot \
 -c boot.cat -hide etfsboot.com -hide boot.cat -o winpe3_x86.iso winpe3_x86

the file you will get will be about 120M in size. Then you can burn this *.iso and boot it on any x86-machine which supports booting from CD-ROMs (which is pretty much any PC today)

How to build a bootable WinPE USB-flash image

a more convenient option would be to create a bootable USB-flash drive. Unfortunately, Windows loader does not support booting from USB-FDD, while for some BIOSes this is the only type of bootable USB devices. If this is your case, you will have to create a virtual CDROM with memdisk from syslinux and boot the *.iso image you've created in the previous step. The drawback is that you will have to sacrifice 120Mb or so of RAM for the virtual CDROM, but the advantage is that this USB-image will be bootable on any PC.

Building WinPE USB-HDD image in a virtual machine

Since we already have a bootable WinPE *.iso image, we can use it to build a bootable WinPE USB-HDD image in a virtual machine like qemu.

  • prepare a blank
dd if=/dev/zero of=winpe3_x86.img count=250000
  • boot winpe3_x86.iso (which you've created before) in a virtual machine
qemu -cdrom winpe3_x86.iso -boot d -m 640 -hda winpe3_x86.img
  • now, in the shell provided by WinPE in the virtual machine
diskpart.exe
diskpart> list disk
diskpart> select disk 0
diskpart> clean
diskpart> create partition primary
diskpart> list partition
diskpart> select partition 1
diskpart> format fs=fat32 quick
diskpart> active
diskpart> assign
diskpart> list volume
diskpart> exit
xcopy /s d:\* c:\
wpeutil shutdown
  • when the virtual machine shuts down, you can copy WinPE image on a flash media. It will fit on any media > 125M in size.
dd if=winpe3_x86.img of=/dev/sdb

and use it for test/diagnostic tasks such as firmware upgrades. If you want, you can create an additional partition for you firmware/diagnostic tools, just don't mess with the partition created by Windows -- you may reder it unbootable.

Building WinPE USB-HDD image with syslinux

if for some ethical or religious reasons you do not want to run any Windows code even in a virtual machine -- you can build a bootable WinPE USB-HDD image using syslinux.

  • prepare a blank
dd if=/dev/zero of=winpe3_x86.img count=250000
  • create a bootable partition
parted winpe3_x86.img
(parted) mklabel msdos
(parted) unit s
(parted) print free
(parted) mkpart primary fat32
(parted) set 1 boot on
(parted) print

in my case the output looks like this. Note the numbers corresponding to "Start" and "Size" of your partition, we will use them in the next command

Model:  (file)
Disk /tmp/winpe3_x86.img: 250000s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End      Size     Type     File system  Flags
 1      32s    249999s  249968s  primary               boot, lba
  • format and mount the partition
losetup -o $((32*512)) --sizelimit $((249968*512)) /dev/loop0 winpe3_x86.img
mkfs.vfat -F32 /dev/loop0
mount /dev/loop0 /media/sdb1
  • copy the files
mkdir -p /media/sdb1/boot
mkdir -p /media/sdb1/sources
cp /tmp/wAIKX86.msi/F1_BOOTMGR /media/sdb1/bootmgr
cp /tmp/wAIKX86.msi/F_WINPE_X86_bcd /media/sdb1/boot/bcd
cp /tmp/wAIKX86.msi/F_WINPE_X86_boot.sdi /media/sdb1/boot/boot.sdi
cp /tmp/WinPE.cab/F1_WINPE.WIM /media/sdb1/sources/boot.wim
cp /usr/lib/syslinux/chain.c32 /media/sdb1/chain.c32
  • create the config file /media/sdb1/syslinux.cfg
DEFAULT WinPE
LABEL WinPE
        COM32 /chain.c32
        APPEND boot ntldr=/bootmgr
  • install syslinux
syslinux /dev/loop0
umount -d /media/sdb1
  • now you can copy this WinPE image on a flash media.
dd if=winpe3_x86.img of=/dev/sdb

and use it for test/diagnostic tasks such as firmware upgrades.

Building WinPE USB-FDD image with syslinux

  • prepare a blank
dd if=/dev/zero of=winpe3_x86.img count=250000
  • format and mount the image
losetup /dev/loop0 winpe3_x86.img
mkfs.vfat -F32 /dev/loop0
mount /dev/loop0 /media/sdb
  • copy the files
cp /tmp/winpe3_x86.iso /media/sdb/
cp /usr/lib/syslinux/memdisk /media/sdb/
  • create the config file /media/sdb/syslinux.cfg
DEFAULT WinPE
LABEL WinPE
        KERNEL /memdisk
        INITRD /winpe3_x86.iso
        APPEND iso
  • install syslinux
syslinux /dev/loop0
umount -d /media/sdb
  • now you can copy this WinPE image on a flash media.
dd if=winpe3_x86.img of=/dev/sdb

and use it for test/diagnostic tasks such as firmware upgrades.