Difference between revisions of "Windows PE"

From ArchWiki
Jump to navigation Jump to search
(update links to Syslinux wiki)
 
(29 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:System administration]]
 
[[Category:System administration]]
 +
[[ja:Windows PE]]
 
[http://technet.microsoft.com/en-us/library/cc766093(v=ws.10).aspx Windows PE] is a lightweight version of Windows intended to be used for installation of Windows Vista and later versions of Windows, as well as for system maintenance.  It runs entirely from memory and can be booted from the network.  This page describes how customized Windows PE images can be created, and optionally published on the network, using only free software packages on an Arch Linux machine along with Microsoft's Windows Automated Installation Kit (WAIK).  The WAIK can be downloaded at no cost and is only needed to extract the {{ic|boot.wim}} file that contains the initial copy of Windows PE, along with a couple boot files.
 
[http://technet.microsoft.com/en-us/library/cc766093(v=ws.10).aspx Windows PE] is a lightweight version of Windows intended to be used for installation of Windows Vista and later versions of Windows, as well as for system maintenance.  It runs entirely from memory and can be booted from the network.  This page describes how customized Windows PE images can be created, and optionally published on the network, using only free software packages on an Arch Linux machine along with Microsoft's Windows Automated Installation Kit (WAIK).  The WAIK can be downloaded at no cost and is only needed to extract the {{ic|boot.wim}} file that contains the initial copy of Windows PE, along with a couple boot files.
 +
 +
{{Warning|By downloading the Windows Automated Installation Kit, you may be bound by its license, which prevents you from, among other things, using Windows PE as a general-purpose operating system.
 +
}}
  
 
== Use cases ==
 
== Use cases ==
Line 9: Line 13:
 
* you need to run a Windows environment to run Win32 programs, you do not have a Windows machine available, and you do not want to use [[Wine]] or the programs will not run correctly with [[Wine]].
 
* you need to run a Windows environment to run Win32 programs, you do not have a Windows machine available, and you do not want to use [[Wine]] or the programs will not run correctly with [[Wine]].
  
== Warnings ==
+
== Creating a bootable Windows PE image ==
 +
 
 +
Install {{Pkg|wimlib}}.
 +
 
 +
=== Configure the Windows PE image ===
 +
 
 +
To boot into a command prompt, create a startup script, which will be included into the bootable image in the next step:
 +
 
 +
{{hc|start.cmd|<nowiki>
 +
cmd.exe
 +
pause</nowiki>
 +
}}
 +
 
 +
The {{ic|mkwinpeimg}} script supports making further modifications to Windows PE using {{ic|--overlay}} option.  See the manual page for {{ic|mkwinpeimg}} for more information. You may want to do this to add additional Windows applications that you want to run in Windows PE, or to add any additional drivers that Windows PE needs (drivers can be loaded using the {{ic|drvload}} command within Windows PE).
 +
 
 +
=== Make the bootable Windows PE ISO ===
 +
 
 +
{{ic|mkwinpeimg}} can create a bootable Windows PE ISO from either Windows installation image / disk for Windows 7 or later or from Windows Automated Installation Kit (WAIK) image. In order to get Windows PE 4.0 and later versions, you have to use installation media of Windows 8 and later versions. Earlier versions of Windows PE can be obtained from [http://www.microsoft.com/en-us/download/details.aspx?id=5753 standalone WAIK distribution from Microsoft].
 +
Since Windows 8, WAIK has been renamed to WADK and is distributed via {{ic|adksetup.exe}}.
 +
 
 +
The installation media iso files are avaiable for MSDN subscribers, but you can download otherwhere and compare the hash value with the those published on MSDN. Different versions of Windows installation media contains different versions of Windows PE. For the relationship between Windows versions and Windows PE versions, refer to [[wikipedia:Windows_Preinstallation_Environment#Versions|Wikipedia]].
 +
 
 +
{{Tip|It may be possible to use [http://httpfs.sourceforge.net/ httpfs] to avoid downloading the entire image file. Windows PE occupies only around 118MB of the image.
 +
}}
 +
 
 +
Mount the source ISO, either Windows installation image or WAIK/WADK, named winimg.iso:
 +
 
 +
# mkdir /media/winimg
 +
# mount winimg.iso /media/winimg
 +
 
 +
Use the {{ic|mkwinpeimg}} script provided with {{Pkg|wimlib}} to create a bootable Windows PE ISO {{ic|winpe.iso}}, with the startup script created in the previous section:
  
'''If you boot Windows PE on a physical computer, you are placing Microsoft's closed-source code in control of that computer.  You do so at your own risk.'''
+
'''Option A''': source image is Windows installation media
  
'''In addition, by downloading the Windows Automated Installation Kit, you may be bound by its license, which prevents you from, among other things, using Windows PE as a general-purpose operating system.'''
+
$ mkwinpeimg --iso --windows-dir=/media/winimg --start-script=start.cmd winpe.iso
  
== Creating a bootable Windows PE ISO ==
+
'''Option B''': source image is WAIK/WADK:
  
<ol>
+
$ mkwinpeimg --iso --waik-dir=/media/winimg --start-script=start.cmd winpe.iso
<li>
 
Download the Windows Automated Installation Kit (WAIK) from [http://www.microsoft.com/en-us/download/details.aspx?id=5753 Microsoft's website].
 
{{Warning|The entire download, {{ic|KB3AIK_EN.iso}}, is 1.7GB.}}
 
{{Tip|It may be possible to use [http://httpfs.sourceforge.net/ httpfs] to avoid downloading the entire file.  Only around 118MB of it is actually needed.}}
 
{{Tip|If you have an installation media of Windows 7 or later versions, you can use that iso file / optical disc instead of WAIK. {{ic|mkwinpeimg}} accepts both WAIK image and Windows installation media. Note that different versions of Windows installation media contains different versions of Windows PE.}}
 
{{Tip|WAIK has been renamed to WADK since Windows 8 and is now distributed via {{ic|adksetup.exe}}. In order to get Windows PE 4.0 and later versions, you have to use installation media of Windows 8 and later versions. The installation media iso files are avaiable for MSDN subscribers, but you can download otherwhere and compare the hash value with the those published on MSDN.}}
 
</li>
 
  
<li>
+
See the {{man|1|mkwinpeimg}} for more information.
Make sure you have the {{Pkg|fuse}}, {{Pkg|cdrkit}}, and {{Pkg|cabextract}} packages installed.
 
</li>
 
  
<li>
+
Unmount the source ISO:
Install {{AUR|wimlib}} from the [[Arch User Repository]].
 
</li>
 
  
<li>
+
  # umount /media/winimg
Mount the WAIK ISO.
 
{{bc|
 
  # mkdir /media/waik
 
# mount KB3AIK_EN.iso /media/waik}}
 
</li>
 
<li>Use the {{ic|mkwinpeimg}} script provided with {{AUR|wimlib}} to create a bootable Windows PE ISO {{ic|winpe.iso}}.  See the man page for {{ic|mkwinpeimg}} for more information.
 
{{bc|<nowiki>$ mkwinpeimg --iso --waik-dir=/media/waik winpe.iso</nowiki>}}
 
</li>
 
<li>Unmount the WAIK ISO.</li>
 
{{bc|# umount /media/waik}}
 
</ol>
 
  
 
== Booting Windows PE ==
 
== Booting Windows PE ==
Line 53: Line 65:
 
=== In virtual machine ===
 
=== In virtual machine ===
  
Run a virtual machine with {{ic|winpe.iso}} attached as a CD-ROM.  Be sure to give it adequate memory, definitely more than the size of the ISO, since Windows PE runs from memory.  For example:
+
Run a virtual machine with {{ic|winpe.iso}} attached as a CD-ROM.  Be sure to give it adequate memory, definitely more than the size of the ISO, since Windows PE runs from memory.  See [[:Category:Hypervisors]] for a list of available virtualization software.
$ qemu-system-i386 -cdrom winpe.iso -m 512
 
  
 
=== From CD ===
 
=== From CD ===
  
Simply burn {{ic|winpe.iso}} onto a CD, and you can boot from it. '''Again: beware that if you do this on your Arch Linux machine, you are placing Microsoft's closed source operating system in control of your computer.'''
+
Simply [[Optical disc drive#Burning|burn]] {{ic|winpe.iso}} onto a CD, and you can boot from it.
  
 
=== From Network ===
 
=== From Network ===
  
Windows PE can be booted from the network using [http://www.syslinux.org/wiki/index.php/PXELINUX PXELINUX] and its [http://www.syslinux.org/wiki/index.php/MEMDISK MEMDISK] module.
+
{{Merge|PXE|The PXE article already describes most of this stuff, no need for duplication.  Also rc.d?  Just make sure that configuration file is not lost if it's necessary for windows.  Besides that everything is dupe.}}
 +
 
 +
Windows PE can be booted from the network using [https://wiki.syslinux.org/wiki/index.php/PXELINUX PXELINUX] and its [https://wiki.syslinux.org/wiki/index.php/MEMDISK MEMDISK] module on BIOS systems. For UEFI systems, [http://ipxe.org/wimboot wimboot] and [http://ipxe.org iPXE] can be used.
 +
 
 +
Install {{pkg|syslinux}} and {{pkg|tftp-hpa}}.
 +
 
 +
Copy needed PXELINUX files to the [[Tftpd server|TFTP server]] root directory.
 +
 
 +
# rsync -aq /usr/lib/syslinux/bios/ /var/tftpboot/
 +
 
 +
Put {{ic|winpe.iso}} in the [[Tftpd server|TFTP server]] root directory.
 +
 
 +
# mv winpe.iso /var/tftpboot
 +
 
 +
Create a [[Syslinux#Configuration|configuration file]] for PXELINUX similar to the following:
  
<ol>
 
<li>Install {{pkg|syslinux}} and {{pkg|tftp-hpa}}.</li>
 
<li>Copy needed PXELINUX files to the [[Tftpd server|TFTP server]] root directory.
 
{{bc|# cp /usr/lib/syslinux/{pxelinux.0,menu.c32,memdisk} /var/tftpboot}} </li>
 
<li>Put {{ic|winpe.iso}} in the [[Tftpd server|TFTP server]] root directory.
 
{{bc|# mv winpe.iso /var/tftpboot}}</li>
 
<li>Create a [[Syslinux#Configuring_syslinux|configuration file]] for PXELINUX similar to the following:</li>
 
 
{{hc|/var/tftpboot/pxelinux.cfg/default|<nowiki>
 
{{hc|/var/tftpboot/pxelinux.cfg/default|<nowiki>
 
UI        menu.c32
 
UI        menu.c32
Line 84: Line 102:
 
LABEL      localboot
 
LABEL      localboot
 
MENU LABEL Boot from local disk
 
MENU LABEL Boot from local disk
LOCALBOOT  0
+
LOCALBOOT  0</nowiki>
</nowiki>
+
}}
 +
 
 +
Start the [[Tftpd server|TFTP server]].
 +
 
 +
Configure your DHCP server (such as [[Dhcpd]] or [[Dnsmasq]]) to point to {{ic|pxelinux.0}} as the boot file, with the Linux server's IP address.  Beware: if your DHCP server is on a router, it may not be possible to do this without installing custom firmware.
 +
 
 +
After completing the above steps, you should be able to boot Windows PE from the network.
 +
 
 +
{{Note|With the given PXELINUX configuration file, Windows PE will start by default after 5 seconds.}}
 +
 
 +
{{Tip|TFTP is not designed to be used to transfer large files, such as {{ic|winpe.iso}}, which may be 118MB or more and take about 30 seconds to load.  Performance may be improved by using the {{ic|gpxelinux.0}} bootloader instead of {{ic|pxelinux.0}} and loading {{ic|winpe.iso}} using HTTP rather than TFTP.}}
 +
 
 +
== Installing Windows from Windows PE ==
 +
 
 +
Once booted into Windows PE, you can install Windows from an installation media.
 +
 
 +
The installation media can be a network share (Samba). See [[Samba]] for seting up a Samba server on another machine on the LAN. To share the installation image mounted at {{ic|/media/winimg}}, add the following share definition to {{ic|/etc/samba/smb.conf}}:
 +
 
 +
{{hc|/etc/samba/smb.conf|<nowiki>
 +
[REMINST]
 +
browsable = true
 +
read only = no
 +
guest ok = yes
 +
path = /media/winimg</nowiki>
 
}}
 
}}
<li>Start the [[Tftpd server|TFTP server]].
 
{{bc|# rc.d start tftpd}}</li>
 
<li>Configure your DHCP server (such as [[Dhcpd]] or [[Dnsmasq]]) to point to {{ic|pxelinux.0}} as the boot file, with the Linux server's IP address.  Beware: if your DHCP server is on a router, it may not be possible to do this without installing custom firmware.</li>
 
</ol>
 
  
After completing the above steps, you should be able to boot Windows PE from the network. '''Warning: With the given PXELINUX configuration file, Windows PE will start by default after 5 seconds.'''
+
Once booted into Windows PE command prompt, run the following command to initialize the network interface, obtain the IP of the Samba server (assuming Windows PE was booted over PXE from a machine that runs the DHCP, TFTP, and Samba server, the server IP will usually be the Gateway IP), mount the share, and launch the GUI setup:
 +
 
 +
  > wpeinit
 +
  > ipconfig
 +
  > net use I: \\IP.ADDRESS.OF.SAMBA.SERVER\REMINST
 +
  > I:\setup.exe
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== System error 58 has occurred. The specified server cannot perform the requested operation ===
  
=== Network boot performance ===
+
If you are getting the following error when using the {{ic|net use}} command:
  
TFTP is not designed to be used to transfer large files, such as {{ic|winpe.iso}}, which may be 118MB or more.  Performance may be improved by using the {{ic|gpxelinux.0}} bootloader instead of {{ic|pxelinux.0}} and loading {{ic|winpe.iso}} using HTTP rather than TFTP.
+
System error 58 has occurred.
 +
 +
The specified server cannot perform the requested operation.
 +
 
 +
1. Make sure you haven't accidentally unmounted the {{ic|/media/winimg}} directory.
 +
 
 +
2. Add a {{ic|map to guest}} to {{ic|/etc/samba/smb.conf}}. Add the following at the top of the file:
 +
 
 +
{{hc|/etc/samba/smb.conf|<nowiki>
 +
[global]
 +
map to guest = Bad User
 +
...</nowiki>
 +
}}
 +
3. Restart the {{ic|smbd.service}}.
  
== Customizing Windows PE ==
+
4. Specify any username/password in the net use command:
  
The {{ic|mkwinpeimg}} script provided with {{AUR|wimlib}} supports making modifications to Windows PE using the {{ic|--start-script}} or {{ic|--overlay}} options. See the manual page for {{ic|mkwinpeimg}} for more information.
+
net use I: \\IP.ADDRESS.OF.SAMBA.SERVER\REMINST /user:user pass
  
You may want to do this to add additional Windows applications that you want to run in Windows PE, or to add any additional drivers that Windows PE needs (drivers can be loaded using the {{ic|drvload}} command within Windows PE).
+
This is happening because Windows 10 connects to anonymous shares by checking some username and password to see if it is able to log in, and if so it allows an anonymous connection.
 +
Apparently whatever part hides this from the user didn't make it into the PE build.
  
 
==See also==
 
==See also==
Line 108: Line 168:
 
* [http://technet.microsoft.com/en-us/library/cc766093(v=ws.10).aspx Microsoft's documentation for Windows PE]
 
* [http://technet.microsoft.com/en-us/library/cc766093(v=ws.10).aspx Microsoft's documentation for Windows PE]
 
* [http://www.thinkwiki.org/wiki/Windows_PE Another article about making Windows PE images on Linux]
 
* [http://www.thinkwiki.org/wiki/Windows_PE Another article about making Windows PE images on Linux]
 +
* [http://www.ultimatedeployment.org/win7pxelinux1.html A guide with scripts for unattended installation of Windows 7 from Linux using Windows PE]
 +
* [https://serverfault.com/a/858269/206710 Windows 10 PE Unable to map network drive anonymously]

Latest revision as of 08:42, 17 March 2019

Windows PE is a lightweight version of Windows intended to be used for installation of Windows Vista and later versions of Windows, as well as for system maintenance. It runs entirely from memory and can be booted from the network. This page describes how customized Windows PE images can be created, and optionally published on the network, using only free software packages on an Arch Linux machine along with Microsoft's Windows Automated Installation Kit (WAIK). The WAIK can be downloaded at no cost and is only needed to extract the boot.wim file that contains the initial copy of Windows PE, along with a couple boot files.

Warning: By downloading the Windows Automated Installation Kit, you may be bound by its license, which prevents you from, among other things, using Windows PE as a general-purpose operating system.

Use cases

Normally, an image of Windows PE can only be created using the Windows Automated Installation Kit (WAIK) on a Windows machine. However, it is also possible to create and modify images of Windows PE using an (Arch) Linux machine, and optionally publish them on the network for PXE booting. No Windows machine is necessary. You may want to do this if:

  • you need to install Windows from the network, or boot Windows PE from the network for system administration, using an Arch Linux-based server. This may be because you do not have a Windows-based server, or you prefer using a Linux server because of its improved security and configurability, or you are already using a Linux server for other purposes.
  • you need to run a Windows environment to run Win32 programs, you do not have a Windows machine available, and you do not want to use Wine or the programs will not run correctly with Wine.

Creating a bootable Windows PE image

Install wimlib.

Configure the Windows PE image

To boot into a command prompt, create a startup script, which will be included into the bootable image in the next step:

start.cmd
cmd.exe
pause

The mkwinpeimg script supports making further modifications to Windows PE using --overlay option. See the manual page for mkwinpeimg for more information. You may want to do this to add additional Windows applications that you want to run in Windows PE, or to add any additional drivers that Windows PE needs (drivers can be loaded using the drvload command within Windows PE).

Make the bootable Windows PE ISO

mkwinpeimg can create a bootable Windows PE ISO from either Windows installation image / disk for Windows 7 or later or from Windows Automated Installation Kit (WAIK) image. In order to get Windows PE 4.0 and later versions, you have to use installation media of Windows 8 and later versions. Earlier versions of Windows PE can be obtained from standalone WAIK distribution from Microsoft. Since Windows 8, WAIK has been renamed to WADK and is distributed via adksetup.exe.

The installation media iso files are avaiable for MSDN subscribers, but you can download otherwhere and compare the hash value with the those published on MSDN. Different versions of Windows installation media contains different versions of Windows PE. For the relationship between Windows versions and Windows PE versions, refer to Wikipedia.

Tip: It may be possible to use httpfs to avoid downloading the entire image file. Windows PE occupies only around 118MB of the image.

Mount the source ISO, either Windows installation image or WAIK/WADK, named winimg.iso:

# mkdir /media/winimg
# mount winimg.iso /media/winimg

Use the mkwinpeimg script provided with wimlib to create a bootable Windows PE ISO winpe.iso, with the startup script created in the previous section:

Option A: source image is Windows installation media

$ mkwinpeimg --iso --windows-dir=/media/winimg --start-script=start.cmd winpe.iso

Option B: source image is WAIK/WADK:

$ mkwinpeimg --iso --waik-dir=/media/winimg --start-script=start.cmd winpe.iso

See the mkwinpeimg(1) for more information.

Unmount the source ISO:

# umount /media/winimg

Booting Windows PE

After creating a bootable ISO of Windows PE (winpe.iso) as described in the previous section, you may want to boot Windows PE in the following ways:

In virtual machine

Run a virtual machine with winpe.iso attached as a CD-ROM. Be sure to give it adequate memory, definitely more than the size of the ISO, since Windows PE runs from memory. See Category:Hypervisors for a list of available virtualization software.

From CD

Simply burn winpe.iso onto a CD, and you can boot from it.

From Network

Merge-arrows-2.pngThis article or section is a candidate for merging with PXE.Merge-arrows-2.png

Notes: The PXE article already describes most of this stuff, no need for duplication. Also rc.d? Just make sure that configuration file is not lost if it's necessary for windows. Besides that everything is dupe. (Discuss in Talk:Windows PE#)

Windows PE can be booted from the network using PXELINUX and its MEMDISK module on BIOS systems. For UEFI systems, wimboot and iPXE can be used.

Install syslinux and tftp-hpa.

Copy needed PXELINUX files to the TFTP server root directory.

# rsync -aq /usr/lib/syslinux/bios/ /var/tftpboot/

Put winpe.iso in the TFTP server root directory.

# mv winpe.iso /var/tftpboot

Create a configuration file for PXELINUX similar to the following:

/var/tftpboot/pxelinux.cfg/default
UI         menu.c32
MENU TITLE Network Boot
TIMEOUT    50

LABEL      winpe
MENU LABEL Boot Windows PE from network
KERNEL     /memdisk
INITRD     winpe.iso
APPEND     iso raw

LABEL      localboot
MENU LABEL Boot from local disk
LOCALBOOT  0

Start the TFTP server.

Configure your DHCP server (such as Dhcpd or Dnsmasq) to point to pxelinux.0 as the boot file, with the Linux server's IP address. Beware: if your DHCP server is on a router, it may not be possible to do this without installing custom firmware.

After completing the above steps, you should be able to boot Windows PE from the network.

Note: With the given PXELINUX configuration file, Windows PE will start by default after 5 seconds.
Tip: TFTP is not designed to be used to transfer large files, such as winpe.iso, which may be 118MB or more and take about 30 seconds to load. Performance may be improved by using the gpxelinux.0 bootloader instead of pxelinux.0 and loading winpe.iso using HTTP rather than TFTP.

Installing Windows from Windows PE

Once booted into Windows PE, you can install Windows from an installation media.

The installation media can be a network share (Samba). See Samba for seting up a Samba server on another machine on the LAN. To share the installation image mounted at /media/winimg, add the following share definition to /etc/samba/smb.conf:

/etc/samba/smb.conf
[REMINST]
browsable = true
read only = no
guest ok = yes
path = /media/winimg

Once booted into Windows PE command prompt, run the following command to initialize the network interface, obtain the IP of the Samba server (assuming Windows PE was booted over PXE from a machine that runs the DHCP, TFTP, and Samba server, the server IP will usually be the Gateway IP), mount the share, and launch the GUI setup:

 > wpeinit
 > ipconfig
 > net use I: \\IP.ADDRESS.OF.SAMBA.SERVER\REMINST
 > I:\setup.exe

Troubleshooting

System error 58 has occurred. The specified server cannot perform the requested operation

If you are getting the following error when using the net use command:

System error 58 has occurred.

The specified server cannot perform the requested operation.

1. Make sure you haven't accidentally unmounted the /media/winimg directory.

2. Add a map to guest to /etc/samba/smb.conf. Add the following at the top of the file:

/etc/samba/smb.conf
[global]
map to guest = Bad User
...

3. Restart the smbd.service.

4. Specify any username/password in the net use command:

net use I: \\IP.ADDRESS.OF.SAMBA.SERVER\REMINST /user:user pass

This is happening because Windows 10 connects to anonymous shares by checking some username and password to see if it is able to log in, and if so it allows an anonymous connection. Apparently whatever part hides this from the user didn't make it into the PE build.

See also