Difference between revisions of "Windows PE"

From ThinkWiki
Jump to: navigation, search
(remove USB-HDD)
(don't need to have access to root account)
Line 41: Line 41:
 
  xcopy /s d:\* c:\
 
  xcopy /s d:\* c:\
 
  wpeutil shutdown
 
  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.
+
* when the virtual machine shuts down, the bootable WinPE image is ready. If you have write permissions for some flash media device (e.g. <tt>/dev/sdb</tt>), you can copy it with
  dd if=winpe3_x86.img of=/dev/sdb
+
  # 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.
 
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===
 
===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'''.
+
if for some ethical or religious reasons you do not want to run any Windows code even in a virtual machine, or you don't have a virtual machine at all -- you can build a bootable WinPE USB-HDD image using '''syslinux''' and '''mtools'''.
 
* prepare a blank
 
* prepare a blank
 
  dd if=/dev/zero of=winpe3_x86.img count=250000
 
  dd if=/dev/zero of=winpe3_x86.img count=250000
* create a bootable partition
+
* create a bootable partition entry
  parted winpe3_x86.img
+
  /sbin/parted winpe3_x86.img
 
  (parted) mklabel msdos
 
  (parted) mklabel msdos
 
  (parted) unit s
 
  (parted) unit s
Line 64: Line 64:
 
   
 
   
 
  Number  Start  End      Size    Type    File system  Flags
 
  Number  Start  End      Size    Type    File system  Flags
   1      32s   249999s  249968s primary              boot, lba
+
   1      '''32'''s   249999s  '''249968'''s primary              boot, lba
* format and mount the partition
+
* create and format the partition image
  losetup -o $((32*512)) --sizelimit $((249968*512)) /dev/loop0 winpe3_x86.img
+
  dd if=/dev/zero of=winpe3_x86p1.img count='''249968'''
  mkfs.vfat -F32 /dev/loop0
+
  /sbin/mkfs.vfat -F32 winpe3_x86p1.img
mount /dev/loop0 /media/sdb1
+
* copy the files (you may have to put "mtools_skip_check=1" into <tt>~/.mtoolsrc</tt> if your partition is not aligned like mine)
* copy the files
+
  mmd -i winpe3_x86p1.img boot
  mkdir -p /media/sdb1/boot
+
  mmd -i winpe3_x86p1.img sources
  mkdir -p /media/sdb1/sources
+
  mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F1_BOOTMGR ::/bootmgr
  cp /tmp/wAIKX86.msi/F1_BOOTMGR /media/sdb1/bootmgr
+
  mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F_WINPE_X86_bcd ::/boot/bcd
  cp /tmp/wAIKX86.msi/F_WINPE_X86_bcd /media/sdb1/boot/bcd
+
  mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F_WINPE_X86_boot.sdi ::/boot/boot.sdi
  cp /tmp/wAIKX86.msi/F_WINPE_X86_boot.sdi /media/sdb1/boot/boot.sdi
+
  mcopy -i winpe3_x86p1.img /tmp/WinPE.cab/F1_WINPE.WIM ::/sources/boot.wim
  cp /tmp/WinPE.cab/F1_WINPE.WIM /media/sdb1/sources/boot.wim
+
  mcopy -i winpe3_x86p1.img /usr/lib/syslinux/chain.c32 ::/chain.c32
  cp /usr/lib/syslinux/chain.c32 /media/sdb1/chain.c32
+
* create the config file <tt>/tmp/syslinux.cfg</tt> and copy it
* create the config file /media/sdb1/syslinux.cfg
 
 
  DEFAULT WinPE
 
  DEFAULT WinPE
 
  LABEL WinPE
 
  LABEL WinPE
 
         COM32 /chain.c32
 
         COM32 /chain.c32
 
         APPEND boot ntldr=/bootmgr
 
         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
 
  
 +
mcopy -i winpe3_x86p1.img /tmp/syslinux.cfg ::/syslinux.cfg
 +
* install syslinux and copy the partition image into the disk image
 +
syslinux winpe3_x86p1.img
 +
dd if=winpe3_x86p1.img of=winpe3_x86.img seek='''32'''
 +
* now the image is ready. If you have write permissions for some flash media device (e.g. <tt>/dev/sdb</tt>), you can copy it with
 +
# dd if=winpe3_x86.img of=/dev/sdb
 
and use it for test/diagnostic tasks such as firmware upgrades.
 
and use it for test/diagnostic tasks such as firmware upgrades.

Revision as of 21:22, 6 April 2010

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 install this AIK and 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 free 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-HDD image

a more convenient option would be to create a bootable USB-flash drive. Unfortunately, Windows loader does not seem to support booting from USB-FDDs, while for some BIOSes this is the only type of bootable USB-flash devices.

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, the bootable WinPE image is ready. If you have write permissions for some flash media device (e.g. /dev/sdb), you can copy it with
# 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, or you don't have a virtual machine at all -- you can build a bootable WinPE USB-HDD image using syslinux and mtools.

  • prepare a blank
dd if=/dev/zero of=winpe3_x86.img count=250000
  • create a bootable partition entry
/sbin/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
  • create and format the partition image
dd if=/dev/zero of=winpe3_x86p1.img count=249968
/sbin/mkfs.vfat -F32 winpe3_x86p1.img
  • copy the files (you may have to put "mtools_skip_check=1" into ~/.mtoolsrc if your partition is not aligned like mine)
mmd -i winpe3_x86p1.img boot
mmd -i winpe3_x86p1.img sources
mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F1_BOOTMGR ::/bootmgr
mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F_WINPE_X86_bcd ::/boot/bcd
mcopy -i winpe3_x86p1.img /tmp/wAIKX86.msi/F_WINPE_X86_boot.sdi ::/boot/boot.sdi
mcopy -i winpe3_x86p1.img /tmp/WinPE.cab/F1_WINPE.WIM ::/sources/boot.wim
mcopy -i winpe3_x86p1.img /usr/lib/syslinux/chain.c32 ::/chain.c32
  • create the config file /tmp/syslinux.cfg and copy it
DEFAULT WinPE
LABEL WinPE
        COM32 /chain.c32
        APPEND boot ntldr=/bootmgr
mcopy -i winpe3_x86p1.img /tmp/syslinux.cfg ::/syslinux.cfg
  • install syslinux and copy the partition image into the disk image
syslinux winpe3_x86p1.img
dd if=winpe3_x86p1.img of=winpe3_x86.img seek=32
  • now the image is ready. If you have write permissions for some flash media device (e.g. /dev/sdb), you can copy it with
# dd if=winpe3_x86.img of=/dev/sdb

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