README.md 6.84 KB
Newer Older
1
# My Retina Windows Templates for Packer
Stefan Scherer's avatar
Stefan Scherer committed
2

3
[![Build status](https://ci.appveyor.com/api/projects/status/76pea1oexae5ca05?svg=true)](https://ci.appveyor.com/project/StefanScherer/packer-windows)
Joe Fitzgerald's avatar
Joe Fitzgerald committed
4

Joe Fitzgerald's avatar
Joe Fitzgerald committed
5 6
### Introduction

Stefan Scherer's avatar
Stefan Scherer committed
7 8 9
This repository contains Windows templates that can be used to create boxes for
Vagrant using Packer ([Website](https://www.packer.io))
([Github](https://github.com/mitchellh/packer)).
Joe Fitzgerald's avatar
Joe Fitzgerald committed
10

Stefan Scherer's avatar
Stefan Scherer committed
11 12 13
This repo is a modified fork of the popular
[joefitzgerald/packer-windows](https://github.com/joefitzgerald/packer-windows)
repo.
14 15 16 17 18

Some of my enhancements are:

* Support of fullscreen Retina display on a MacBook Pro.
* WinRM, no more OpenSSH
Stefan Scherer's avatar
Stefan Scherer committed
19
* PowerShell attached to taskbar in desktop editions
Joe Fitzgerald's avatar
Joe Fitzgerald committed
20

21 22
### Packer Version

23
[Packer](https://github.com/mitchellh/packer/blob/master/CHANGELOG.md) `1.1.3` is recommended.
24

25 26
### Windows Versions

Stefan Scherer's avatar
Stefan Scherer committed
27
The following Windows versions are known to work (built with VMware Fusion Pro
28
10.1.1):
29

Stefan Scherer's avatar
Stefan Scherer committed
30
* Windows 10
31
  * Windows 10 1803 -> Vagrant Cloud box [StefanScherer/windows_10](https://app.vagrantup.com/StefanScherer/boxes/windows_10)
Stefan Scherer's avatar
Stefan Scherer committed
32
  * Windows 10 Insider
33
* Windows Server 2016 Desktop -> Vagrant Cloud box [StefanScherer/windows_2016](https://app.vagrantup.com/StefanScherer/boxes/windows_2016)
34
* Windows Server 2019 Desktop (Insider Preview)
Stefan Scherer's avatar
Stefan Scherer committed
35
* Windows Server Core
36
  * Windows Server 2016 without and with Docker -> Vagrant Cloud box [StefanScherer/windows_2016_docker](https://app.vagrantup.com/StefanScherer/boxes/windows_2016_docker)
Stefan Scherer's avatar
Stefan Scherer committed
37
  * Windows Server 1709 without and with Docker
38 39
  * Windows Server InsiderPreview Semi-Annual without and with Docker
  * Windows Server 2019 Core(Insider Preview)
40

Stefan Scherer's avatar
Stefan Scherer committed
41 42
You may find other packer template files, but older versions of Windows doesn't
work so nice with a Retina display.
43 44 45

### Windows Editions

Stefan Scherer's avatar
Stefan Scherer committed
46 47 48 49
All Windows Server versions are defaulted to the Server Standard edition. You
can modify this by editing the Autounattend.xml file, changing the
`ImageInstall`>`OSImage`>`InstallFrom`>`MetaData`>`Value` element (e.g. to
Windows Server 2012 R2 SERVERDATACENTER).
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
To retrieve the correct ImageName from an ISO file use the following two commands.

```
PS C:\> Mount-DiskImage -ImagePath C:\iso\Windows_InsiderPreview_Server_2_16237.iso
PS C:\> Get-WindowsImage -ImagePath e:\sources\install.wim

ImageIndex       : 1
ImageName        : Windows Server 2016 SERVERSTANDARDACORE
ImageDescription : Windows Server 2016 SERVERSTANDARDACORE
ImageSize        : 7,341,507,794 bytes

ImageIndex       : 2
ImageName        : Windows Server 2016 SERVERDATACENTERACORE
ImageDescription : Windows Server 2016 SERVERDATACENTERACORE
ImageSize        : 7,373,846,520 bytes
```

68 69
### Product Keys

Stefan Scherer's avatar
Stefan Scherer committed
70 71 72 73
The `Autounattend.xml` files are configured to work correctly with trial ISOs
(which will be downloaded and cached for you the first time you perform a
`packer build`). If you would like to use retail or volume license ISOs, you
need to update the `UserData`>`ProductKey` element as follows:
74 75 76 77

* Uncomment the `<Key>...</Key>` element
* Insert your product key into the `Key` element

Stefan Scherer's avatar
Stefan Scherer committed
78 79 80
If you are going to configure your VM as a KMS client, you can use the product
keys at http://technet.microsoft.com/en-us/library/jj612867.aspx. These are the
default values used in the `Key` element.
81

82
### Using existing ISOs
Stefan Scherer's avatar
Stefan Scherer committed
83 84 85 86 87 88

If you have already downloaded the ISOs or would like to override them, set
these additional variables:

* iso_url - path to existing ISO
* iso_checksum - md5sum of existing ISO (if different)
89 90

```
Stefan Scherer's avatar
Stefan Scherer committed
91
packer build -var 'iso_url=./server2016.iso' .\windows_2016.json
92 93
```

94 95
### Windows Updates

Stefan Scherer's avatar
Stefan Scherer committed
96 97 98 99 100 101
The scripts in this repo will install all Windows updates – by default – during
Windows Setup. This is a _very_ time consuming process, depending on the age of
the OS and the quantity of updates released since the last service pack. You
might want to do yourself a favor during development and disable this
functionality, by commenting out the `WITH WINDOWS UPDATES` section and
uncommenting the `WITHOUT WINDOWS UPDATES` section in `Autounattend.xml`:
102

103 104 105
```xml
<!-- WITHOUT WINDOWS UPDATES -->
<SynchronousCommand wcm:action="add">
106 107 108 109
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1 -AutoStart</CommandLine>
    <Description>Install OpenSSH</Description>
    <Order>99</Order>
    <RequiresUserInput>true</RequiresUserInput>
110 111 112 113
</SynchronousCommand>
<!-- END WITHOUT WINDOWS UPDATES -->
<!-- WITH WINDOWS UPDATES -->
<!--
114 115 116 117 118
<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c a:\microsoft-updates.bat</CommandLine>
    <Order>98</Order>
    <Description>Enable Microsoft Updates</Description>
</SynchronousCommand>
119
<SynchronousCommand wcm:action="add">
120 121 122 123
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1</CommandLine>
    <Description>Install OpenSSH</Description>
    <Order>99</Order>
    <RequiresUserInput>true</RequiresUserInput>
124
</SynchronousCommand>
125
<SynchronousCommand wcm:action="add">
126 127 128 129
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\win-updates.ps1</CommandLine>
    <Description>Install Windows Updates</Description>
    <Order>100</Order>
    <RequiresUserInput>true</RequiresUserInput>
130
</SynchronousCommand>
131 132
-->
<!-- END WITH WINDOWS UPDATES -->
133 134 135 136
```

Doing so will give you hours back in your day, which is a good thing.

137
### WinRM
138

139
These boxes use WinRM. There is no OpenSSH installed.
140

141
### Hyper-V Support
Stefan Scherer's avatar
Stefan Scherer committed
142

143
If you are running Windows 10, Windows Server 2016 or later, then you can also use these packerfiles to build
Stefan Scherer's avatar
Stefan Scherer committed
144 145 146
a Hyper-V virtual machine. I have the ISO already downloaded to save time, and
only have Hyper-V installed on my laptop, so I run:

147
```
Stefan Scherer's avatar
Stefan Scherer committed
148
packer build --only hyperv-iso -var 'hyperv_switchname=Ethernet' -var 'iso_url=./server2016.iso' .\windows_2016_docker.json
149 150
```

151
You then can use this box with Vagrant to spin up a Hyper-V VM.
152 153 154 155 156

#### Generation 2 VMs

Some of these images use Hyper-V "Generation 2" VMs to enable the latest features and faster booting. However, an extra manual step is needed to put the needed files into ISOs because Gen2 VMs don't support virtual floppy disks.

157 158 159
* `windows_server_insider.json`
* `windows_server_insider_docker.json`
* `windows_10_insider.json`
160 161 162 163

Before running `packer build`, be sure to run `./make_unattend_iso.ps1` first. Otherwise the build will fail on a missing ISO file

```none
164
hyperv-iso output will be in this color.
165

166 167 168 169
1 error(s) occurred:

* Secondary Dvd image does not exist: CreateFile ./iso/windows_server_insider_unattend.iso: The system cannot find the file specified.
```
170

171 172
### Using .box Files With Vagrant

Stefan Scherer's avatar
Stefan Scherer committed
173
The generated box files include a Vagrantfile template that is suitable for use
174
with Vagrant 1.7.4+, but the latest ersion is always recommended.
Stefan Scherer's avatar
Stefan Scherer committed
175

176
Example Steps for Hyper-V:
Stefan Scherer's avatar
Stefan Scherer committed
177

178
```
Stefan Scherer's avatar
Stefan Scherer committed
179 180
vagrant box add windows_2016_docker windows_2016_docker_hyperv.box
vagrant init windows_2016_docker
181
vagrant up --provider hyperv
182
```
183

Joe Fitzgerald's avatar
Joe Fitzgerald committed
184 185
### Contributing

186
Pull requests welcomed, but normally should go to Joe's repo.