Commit e691e099 authored by Stefan Scherer's avatar Stefan Scherer Committed by GitHub

Merge pull request #71 from PatrickLang/hyperv-insider-gen2

Work in progress: Moving insider images to Hyper-V Generation 2 VMs
parents 1cd40df5 65b26f4b
......@@ -11,6 +11,7 @@
/packer_cache/
*.log
*~
*.swp
/output/
*.webm
tmp
......
......@@ -139,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:
......@@ -147,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
# 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
......@@ -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"
],
......@@ -143,5 +143,4 @@
"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`}}",
......
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