Commit ba1067d4 authored by Bob Tanner's avatar Bob Tanner

Merge branch 'my' into 'master'

Merge upstream my branch into gitlab master branch

See merge request real-time.com/packer-windows!1
parents c95fc93b e691e099
......@@ -11,6 +11,7 @@
/packer_cache/
*.log
*~
*.swp
/output/
*.webm
tmp
......
......@@ -47,6 +47,23 @@ 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).
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
```
### Product Keys
The `Autounattend.xml` files are configured to work correctly with trial ISOs
......@@ -122,7 +139,7 @@ These boxes use WinRM. There is no OpenSSH installed.
### Hyper-V Support
If you are running Windows 10, then you can also use these packerfiles to build
If you are running Windows 10, Windows Server 2016 or later, then you can also use these packerfiles to build
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:
......@@ -130,23 +147,29 @@ only have Hyper-V installed on my laptop, so I run:
packer build --only hyperv-iso -var 'hyperv_switchname=Ethernet' -var 'iso_url=./server2016.iso' .\windows_2016_docker.json
```
You then can use this box with Vagrant to spin up a Hyper-V VM. Vagrant
currently needs some patches as well, see the script
[install-vagrant.ps1](hyperv/scripts/install-vagrant.ps1) how to patch Vagrant
1.8.4 to fix these issues.
You then can use this box with Vagrant to spin up a Hyper-V VM.
#### 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.
- `windows_server_insider.json`
- `windows_server_insider_docker.json`
- `windows_10_insider.json`
Before running `packer build`, be sure to run `./make_unattend_iso.ps1` first. Otherwise the build will fail on a missing ISO file
```none
TODO: error example here
```
### Using .box Files With Vagrant
The generated box files include a Vagrantfile template that is suitable for use
with Vagrant 1.7.4+, which includes native support for Windows and uses WinRM to
communicate with the box.
Vagrant 1.8.4 does need some workarounds though:
with Vagrant 1.7.4+, but the latest ersion is always recommended.
* There is a bug in get_vm_status.ps1
* winrm-fs needs an update as well See:
https://github.com/PatrickLang/packer-windows/issues/1#issuecomment-230151622
These are fixed in 1.8.5, so upgrading is easiest.
Example Steps for Hyper-V:
......
......@@ -42,8 +42,8 @@
<InstallToAvailablePartition>false</InstallToAvailablePartition>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME</Key>
<Value>Windows 10 Enterprise</Value>
<Key>/IMAGE/EditionID</Key>
<Value>EnterpriseEval</Value>
</MetaData>
</InstallFrom>
</OSImage>
......@@ -60,7 +60,7 @@
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<InputLocale>0409:00010409</InputLocale>
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UILanguageFallback>en-US</UILanguageFallback>
......
This diff is collapsed.
This diff is collapsed.
......@@ -6,7 +6,8 @@ install:
- choco install -y packer
- ps: Install-WindowsFeature Hyper-V-PowerShell
build: off
build_script:
- ps: .\make_unattend_iso.ps1
test_script:
- ps: .\test.ps1
#!/bin/bash
# Microsoft Connect ISO
# packer build --only=vmware-iso --var iso_url=~/packer_cache/connect/17035.1000.171103-1616.rs_prerelease_SERVER_ACORE_VOL_x64FRE_en-us.iso --var iso_checksum=dd412bd5c7d29fa5166a10f4cb36dacf7fcb605a5b8e8a6e8fa87e13aed6851d --var iso_checksum_type=sha256 --var autounattend=./tmp/2016_connect/Autounattend.xml windows_server_insider_docker.json
# Windows Insider ISO
PACKER_LOG=debug packer build \
--only=vmware-iso \
--var vhv_enable=true \
--var iso_url=~/packer_cache/insider/Windows_InsiderPreview_Server_17074.iso \
--var iso_url=~/packer_cache/insider/Windows_InsiderPreview_Server_17079.iso \
windows_server_insider_docker.json
# This builds the unattend ISOs needed for Generation 2 VMs with Hyper-V
$isoList = @(
@{
FileName="./iso/windows_server_insider_unattend.iso";
Files=@(
"./answer_files/server_insider_uefi/autounattend.xml",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1"
)
},
@{
FileName="./iso/windows_10_insider_unattend.iso";
Files=@(
"./answer_files/10_insider_uefi/Autounattend.xml"
"./floppy/WindowsPowershell.lnk",
"./floppy/PinTo10.exe",
"./scripts/fixnetwork.ps1",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1"
)
}
)
# FROM https://gallery.technet.microsoft.com/scriptcenter/New-ISOFile-function-a8deeffd
# This probably won't work on Windows Server Core, so may need a different solution later
function New-IsoFile
{
<#
.Synopsis
Creates a new .iso file
.Description
The New-IsoFile cmdlet creates a new .iso file containing content from chosen folders
.Example
New-IsoFile "c:\tools","c:Downloads\utils"
This command creates a .iso file in $env:temp folder (default location) that contains c:\tools and c:\downloads\utils folders. The folders themselves are included at the root of the .iso image.
.Example
New-IsoFile -FromClipboard -Verbose
Before running this command, select and copy (Ctrl-C) files/folders in Explorer first.
.Example
dir c:\WinPE | New-IsoFile -Path c:\temp\WinPE.iso -BootFile "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys.bin" -Media DVDPLUSR -Title "WinPE"
This command creates a bootable .iso file containing the content from c:\WinPE folder, but the folder itself isn't included. Boot file etfsboot.com can be found in Windows ADK. Refer to IMAPI_MEDIA_PHYSICAL_TYPE enumeration for possible media types: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366217(v=vs.85).aspx
.Notes
NAME: New-IsoFile
AUTHOR: Chris Wu
LASTEDIT: 03/23/2016 14:46:50
#>
[CmdletBinding(DefaultParameterSetName='Source')]Param(
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$true, ParameterSetName='Source')]$Source,
[parameter(Position=2)][string]$Path = "$env:temp\$((Get-Date).ToString('yyyyMMdd-HHmmss.ffff')).iso",
[ValidateScript({Test-Path -LiteralPath $_ -PathType Leaf})][string]$BootFile = $null,
[ValidateSet('CDR','CDRW','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','BDR','BDRE')][string] $Media = 'DVDPLUSRW_DUALLAYER',
[string]$Title = (Get-Date).ToString("yyyyMMdd-HHmmss.ffff"),
[switch]$Force,
[parameter(ParameterSetName='Clipboard')][switch]$FromClipboard
)
Begin {
($cp = new-object System.CodeDom.Compiler.CompilerParameters).CompilerOptions = '/unsafe'
if (!('ISOFile' -as [type])) {
Add-Type -CompilerParameters $cp -TypeDefinition @'
public class ISOFile
{
public unsafe static void Create(string Path, object Stream, int BlockSize, int TotalBlocks)
{
int bytes = 0;
byte[] buf = new byte[BlockSize];
var ptr = (System.IntPtr)(&bytes);
var o = System.IO.File.OpenWrite(Path);
var i = Stream as System.Runtime.InteropServices.ComTypes.IStream;
if (o != null) {
while (TotalBlocks-- > 0) {
i.Read(buf, BlockSize, ptr); o.Write(buf, 0, bytes);
}
o.Flush(); o.Close();
}
}
}
'@
}
if ($BootFile) {
if('BDR','BDRE' -contains $Media) { Write-Warning "Bootable image doesn't seem to work with media type $Media" }
($Stream = New-Object -ComObject ADODB.Stream -Property @{Type=1}).Open() # adFileTypeBinary
$Stream.LoadFromFile((Get-Item -LiteralPath $BootFile).Fullname)
($Boot = New-Object -ComObject IMAPI2FS.BootOptions).AssignBootImage($Stream)
}
$MediaType = @('UNKNOWN','CDROM','CDR','CDRW','DVDROM','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','HDDVDROM','HDDVDR','HDDVDRAM','BDROM','BDR','BDRE')
Write-Verbose -Message "Selected media type is $Media with value $($MediaType.IndexOf($Media))"
($Image = New-Object -com IMAPI2FS.MsftFileSystemImage -Property @{VolumeName=$Title}).ChooseImageDefaultsForMediaType($MediaType.IndexOf($Media))
if (!($Target = New-Item -Path $Path -ItemType File -Force:$Force -ErrorAction SilentlyContinue)) { Write-Error -Message "Cannot create file $Path. Use -Force parameter to overwrite if the target file already exists."; break }
}
Process {
if($FromClipboard) {
if($PSVersionTable.PSVersion.Major -lt 5) { Write-Error -Message 'The -FromClipboard parameter is only supported on PowerShell v5 or higher'; break }
$Source = Get-Clipboard -Format FileDropList
}
foreach($item in $Source) {
if($item -isnot [System.IO.FileInfo] -and $item -isnot [System.IO.DirectoryInfo]) {
$item = Get-Item -LiteralPath $item
}
if($item) {
Write-Verbose -Message "Adding item to the target image: $($item.FullName)"
try { $Image.Root.AddTree($item.FullName, $true) } catch { Write-Error -Message ($_.Exception.Message.Trim() + ' Try a different media type.') }
}
}
}
End {
if ($Boot) { $Image.BootImageOptions=$Boot }
$Result = $Image.CreateResultImage()
[ISOFile]::Create($Target.FullName,$Result.ImageStream,$Result.BlockSize,$Result.TotalBlocks)
Write-Verbose -Message "Target image ($($Target.FullName)) has been created"
$Target
}
}
$isoList | foreach-object {
New-IsoFile -Path $_.FileName -Source $_.Files -Force -Media "CDR"
}
\ No newline at end of file
......@@ -34,6 +34,9 @@ Function SetupPhase1 {
Function SetupPhase2 {
Write-Host "Installing Vagrant plugins"
vagrant plugin install vagrant-reload
Write-Host "Adding NAT"
New-VMSwitch -SwitchName "packer-hyperv-iso" -SwitchType Internal
New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter -name "vEthernet (packer-hyperv-iso)").ifIndex
......
......@@ -45,6 +45,7 @@ Vagrant.configure("2") do |config|
v.vmx["sound.autodetect"] = "TRUE"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -57,6 +58,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider "hyperv" do |v|
......
......@@ -36,6 +36,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -48,5 +49,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -36,6 +36,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -48,5 +49,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -36,6 +36,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -48,5 +49,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -46,6 +46,7 @@ Vagrant.configure("2") do |config|
v.vms["virtualhw.version"] = "11"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -58,5 +59,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -37,6 +37,7 @@ Vagrant.configure("2") do |config|
v.vms["virtualhw.version"] = "11"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -49,6 +50,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.enable_vmrun_ip_lookup = false
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider "hyperv" do |v|
......
......@@ -36,6 +36,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -48,5 +49,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -36,6 +36,7 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
config.vm.provider :vmware_workstation do |v, override|
......@@ -48,5 +49,6 @@ Vagrant.configure("2") do |config|
v.vmx["scsi0.virtualDev"] = "lsisas1068"
v.vmx["gui.fitguestusingnativedisplayresolution"] = "FALSE"
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end
end
......@@ -81,22 +81,18 @@
"winrm_username": "vagrant"
},
{
"boot_wait": "0s",
"boot_command": [
"<enter>"
],
"boot_wait": "1s",
"communicator": "winrm",
"cpu": 2,
"disk_size": "{{user `disk_size`}}",
"enable_secure_boot": true,
"enable_virtualization_extensions": true,
"floppy_files": [
"{{user `autounattend`}}",
"./floppy/WindowsPowershell.lnk",
"./floppy/PinTo10.exe",
"./scripts/fixnetwork.ps1",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1"
"generation": 2,
"secondary_iso_images": [
"./iso/windows_10_insider_unattend.iso"
],
"guest_additions_mode": "disable",
"iso_checksum": "{{user `iso_checksum`}}",
......@@ -106,6 +102,7 @@
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"switch_name": "{{user `hyperv_switchname`}}",
"type": "hyperv-iso",
"vm_name": "Windows10Insider",
"winrm_password": "vagrant",
"winrm_timeout": "2h",
"winrm_username": "vagrant"
......
{
"builders": [
{
"boot_wait": "60s",
"boot_command": [
"<enter>"
],
"boot_wait": "1s",
"communicator": "winrm",
"cpu": 2,
"disk_size": "{{user `disk_size`}}",
"enable_secure_boot": true,
"enable_virtualization_extensions": true,
"floppy_files": [
"{{user `autounattend`}}",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1"
"generation": 2,
"secondary_iso_images": [
"./iso/windows_server_insider_unattend.iso"
],
"guest_additions_mode": "disable",
"iso_checksum": "{{user `iso_checksum`}}",
......@@ -123,7 +124,6 @@
"execute_command": "{{ .Vars }} cmd /c \"{{ .Path }}\"",
"scripts": [
"./scripts/set-winrm-automatic.bat",
"./scripts/compile-dotnet-assemblies.bat",
"./scripts/uac-enable.bat",
"./scripts/compact.bat"
],
......@@ -135,13 +135,12 @@
"disk_size": "61440",
"disk_type_id": "1",
"headless": "false",
"iso_checksum": "bcdabad84c7a7cc62706bc31ca24ac729da044b2c3290521b0d4eae632a8c382",
"iso_checksum": "4ac2db4bfc90e8bc569646200592b76915aa6dadd5c0b829b0e997db5ad691b8",
"iso_checksum_type": "sha256",
"iso_url": "https://software-download.microsoft.com/sg/Windows_InsiderPreview_Server_17074.iso",
"iso_url": "https://software-download.microsoft.com/sg/Windows_InsiderPreview_Server_17079.iso",
"manually_download_iso_from": "https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver",
"restart_timeout": "5m",
"vhv_enable": "false",
"winrm_timeout": "2h"
}
}
}
\ No newline at end of file
{
"builders": [
{
"boot_wait": "60s",
"boot_command": [
"<enter>"
],
"boot_wait": "1s",
"communicator": "winrm",
"cpu": 2,
"disk_size": "{{user `disk_size`}}",
"enable_secure_boot": true,
"enable_virtualization_extensions": true,
"floppy_files": [
"{{user `autounattend`}}",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1"
"generation": 2,
"secondary_iso_images": [
"./iso/windows_server_insider_unattend.iso"
],
"guest_additions_mode": "disable",
"iso_checksum": "{{user `iso_checksum`}}",
......@@ -150,9 +151,9 @@
"docker_provider": "DockerProvider",
"docker_version": "17.10.0-ee-preview-3",
"headless": "false",
"iso_checksum": "bcdabad84c7a7cc62706bc31ca24ac729da044b2c3290521b0d4eae632a8c382",
"iso_checksum": "4ac2db4bfc90e8bc569646200592b76915aa6dadd5c0b829b0e997db5ad691b8",
"iso_checksum_type": "sha256",
"iso_url": "https://software-download.microsoft.com/pr/Windows_InsiderPreview_Server_17074.iso",
"iso_url": "https://software-download.microsoft.com/pr/Windows_InsiderPreview_Server_17079.iso",
"manually_download_iso_from": "https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver",
"restart_timeout": "5m",
"vhv_enable": "false",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment