Preboot Environment
What is a PE?
Windows Preinstallation Environment is a lightweight system, less than 300Mo for the disk image. When we boot a WinPE, we only have a cmd console and we can do all necessary think to install a computer.
How can create a WinPE image
Vanilla version
Get it from CDROM
Explode the windows cdrom/iso (server or desktop), and get some boot files, you can find it in the sources and bootdirectory.
The boot.wim file is the only file we need to boot a valid winpe system, and /boot/boot.sdi and /bootmgr
How to create boot image
We can create a usb boot device, but i want a netboot winpe system. So we need to create a boot disk image loadable by gPXE.
The Steps are:
- format an usb drive
- add the boot.wim file
- create a bootable windows 7 compliant disk
- create a image disk
Get a Usb drive (512Mo not more than 512), or create a partition with a size of 512M, add the boot.wim file in this paritition. add the boot sector, and dump this disk to an image disk.
modus operandi
On Linux:
mkfs.ntfs -f -L WinPE /dev/sdb1
mount /dev/sdb1 /mnt
cp /data/Windows/boot.wim /data/Windows/bootmgr /data/Windows/boot.sdi /mnt
mkdir /mnt/BCD
umount /mnt
On Windows, if we consider b: as the drive of the usb disk:
bcdedit /store b:\boot\BCD /set {bootmgr} timeout 5
bcdedit /store b:\boot\BCD /create {ramdiskoptions}
bcdedit /store b:\boot\BCD /set {ramdiskoptions} ramdisksdidevice boot
bcdedit /store b:\boot\BCD /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
for /f "tokens=3" %a in ('bcdedit /store b:\boot\BCD /create /d "Boot Windows PE" /application OSLOADER') do set GUID=%a
bcdedit /store b:\boot\BCD /set %GUID% device ramdisk=[boot]\boot.wim,{ramdiskoptions}
bcdedit /store b:\boot\BCD /set %GUID% osdevice ramdisk=[boot]\boot.wim,{ramdiskoptions}
bcdedit /store b:\boot\BCD /set %GUID% systemroot \windows
bcdedit /store b:\boot\BCD /set %GUID% detecthal yes
bcdedit /store b:\boot\BCD /set %GUID% winpe yes
bcdedit /store c:\boot\BCD /ems {default} on
bcdedit /store c:\boot\BCD /bootems {bootmgr} on
bcdedit /store b:\boot\BCD /displayorder %GUID% /addlast
Now we have a usb drive for booting WinPE system, we can make a winpe.img now.
On linux again:
dd if=/dev/sdb1 of=/data/Windows/winpe.img bs=1024k
gzip winpe.img
Now we have the winpe image we describe in basis gPXE setup, but gzip the file memdisk can gunzip it on the fly.
Custom version
How to modify
Now, for customing this system, we can modify or change the boot.wim file.
For doing this the steps are:
- mount the winpe.img file
- add/remove/modify the boot.wim file
- unmount and save the winpe.img
Modus operandi
This part can be done on linux, we mount a loop device at osfset 65536.
losetup -o 65536 /dev/loop0 /data/Windows/winpe.img
mount -o loop /dev/loop0 /mnt
cp /data/windows/NewWinPe.wim /mnt/boot/wim
umount /mnt
losetup -d /dev/loop/0
How to modify the boot.wim file
For doing this we must have WAIK2 system. We talk about that later.