Last active
May 27, 2022 15:17
-
-
Save jessefmoore/5ae57f5b0ad86312447ec38f40b9d6f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Walk thru video here https://screencast-o-matic.com/content/video/c3n1rjVDms6 | |
| # | |
| ### Take the below code to run Packer to build Win10 in HyperV ###### | |
| packer build --only=hyperv-iso.windows10 ` | |
| --var disk_size=136400 ` | |
| --var switch_name=InternalSwitch ` | |
| --var iso_url=./iso/Win10_21H1_English_x64.iso ` | |
| --var iso_checksum=sha1:78aa5fa0fd332ee0822ef5a533cd2cfe12333274 ` | |
| windows_10.pkr.hcl | |
| ###################################################################### | |
| ############### CODE BELOW to get Win10 Packer on HyperV ############ | |
| packer { | |
| required_plugins { | |
| windows-update = { | |
| version = "0.14.0" | |
| source = "github.com/rgl/windows-update" | |
| } | |
| } | |
| } | |
| variable "autounattend" { | |
| type = string | |
| default = "./answer_files/10/Autounattend.xml" | |
| } | |
| variable "headless" { | |
| type = string | |
| default = "false" | |
| } | |
| variable "disk_type_id" { | |
| type = string | |
| default = "1" | |
| } | |
| variable "iso_checksum" { | |
| type = string | |
| default = "sha256:6C6856405DBC7674EDA21BC5F7094F5A18AF5C9BACC67ED111E8F53F02E7D13D" | |
| } | |
| variable "iso_url" { | |
| type = string | |
| default = "iso/Win10_20H2_v2_English_x64.iso" | |
| } | |
| variable "restart_timeout" { | |
| type = string | |
| default = "5m" | |
| } | |
| variable "vhv_enable" { | |
| type = string | |
| default = "false" | |
| } | |
| variable "vm_name" { | |
| type = string | |
| default = "windows_10" | |
| } | |
| variable "winadmin_password" { | |
| type = string | |
| default = "vagrant" | |
| } | |
| variable "winrm_username" { | |
| type = string | |
| default = "vagrant" | |
| } | |
| variable "winrm_timeout" { | |
| type = string | |
| default = "6h" | |
| } | |
| variable "disk_size" { | |
| type = string | |
| default = "61440" | |
| } | |
| variable "memory" { | |
| type = string | |
| default = "2048" | |
| } | |
| variable "cpu" { | |
| type = string | |
| default = "4" | |
| } | |
| variable "virtio_win_iso" { | |
| type = string | |
| default = "~/virtio-win.iso" | |
| } | |
| variable "vagrantfile_template" { | |
| type = string | |
| default = "" | |
| } | |
| variable "vmx_version" { | |
| type = string | |
| default = "14" | |
| } | |
| variable "switch_name" { | |
| type = string | |
| default = "" | |
| } | |
| locals { | |
| buildtime = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) | |
| } | |
| source "hyperv-iso" "windows10" { | |
| boot_wait = "6m" | |
| communicator = "winrm" | |
| configuration_version = "8.0" | |
| cpus = "${var.cpu}" | |
| disk_size = "${var.disk_size}" | |
| floppy_files = ["${var.autounattend}", "./floppy/WindowsPowershell.lnk", "./floppy/PinTo10.exe", "./scripts/fixnetwork.ps1", "./scripts/disable-screensaver.ps1", "./scripts/disable-winrm.ps1", "./scripts/enable-winrm.ps1"] | |
| guest_additions_mode = "none" | |
| iso_checksum = "${var.iso_checksum}" | |
| iso_url = "${var.iso_url}" | |
| memory = "${var.memory}" | |
| shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" | |
| switch_name = "${var.switch_name}" | |
| vm_name = "${var.vm_name}" | |
| winrm_password = "vagrant" | |
| winrm_timeout = "${var.winrm_timeout}" | |
| winrm_username = "vagrant" | |
| keep_registered = "true" | |
| } | |
| source "virtualbox-iso" "windows10" { | |
| boot_wait = "6m" | |
| communicator = "winrm" | |
| cpus = "${var.cpu}" | |
| disk_size = "${var.disk_size}" | |
| floppy_files = ["${var.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"] | |
| guest_additions_mode = "disable" | |
| guest_os_type = "Windows10_64" | |
| output_directory = "windows_10-virtualbox" | |
| headless = "${var.headless}" | |
| iso_checksum = "${var.iso_checksum}" | |
| iso_url = "${var.iso_url}" | |
| memory = "${var.memory}" | |
| shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" | |
| vm_name = "${var.vm_name}" | |
| winrm_password = "vagrant" | |
| winrm_timeout = "${var.winrm_timeout}" | |
| winrm_username = "vagrant" | |
| } | |
| source "vmware-iso" "windows10" { | |
| boot_wait = "6m" | |
| communicator = "winrm" | |
| cpus = "${var.cpu}" | |
| disk_adapter_type = "lsisas1068" | |
| disk_size = "${var.disk_size}" | |
| disk_type_id = "${var.disk_type_id}" | |
| floppy_files = ["${var.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"] | |
| guest_os_type = "windows9-64" | |
| output_directory = "windows_10-vmware" | |
| headless = "${var.headless}" | |
| keep_registered = "true" | |
| iso_checksum = "${var.iso_checksum}" | |
| iso_url = "${var.iso_url}" | |
| memory = "${var.memory}" | |
| shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" | |
| version = "${var.vmx_version}" | |
| vm_name = "${var.vm_name}" | |
| vmx_data = { | |
| "RemoteDisplay.vnc.enabled" = "false" | |
| "RemoteDisplay.vnc.port" = "5900" | |
| } | |
| vmx_remove_ethernet_interfaces = true | |
| vnc_port_max = 5980 | |
| vnc_port_min = 5900 | |
| winrm_password = "vagrant" | |
| winrm_timeout = "${var.winrm_timeout}" | |
| winrm_username = "vagrant" | |
| } | |
| build { | |
| sources = ["source.hyperv-iso.windows10", "source.virtualbox-iso.windows10", "source.vmware-iso.windows10"] | |
| provisioner "windows-shell" { | |
| execute_command = "{{ .Vars }} cmd /c \"{{ .Path }}\"" | |
| remote_path = "/tmp/script.bat" | |
| scripts = ["./scripts/enable-rdp.bat"] | |
| } | |
| provisioner "powershell" { | |
| scripts = ["./scripts/debloat-windows.ps1"] | |
| } | |
| provisioner "windows-restart" { | |
| } | |
| provisioner "powershell" { | |
| scripts = ["./scripts/set-powerplan.ps1"] | |
| } | |
| # provisioner "windows-update" { | |
| # filters = ["exclude:$_.Title -like '*Preview*'", "include:$true"] | |
| # pause_before = "30s" | |
| # search_criteria = "IsInstalled=0" | |
| # } | |
| # provisioner "windows-restart" { | |
| # } | |
| provisioner "windows-shell" { | |
| execute_command = "{{ .Vars }} cmd /c \"{{ .Path }}\"" | |
| remote_path = "/tmp/script.bat" | |
| scripts = ["./scripts/pin-powershell.bat", "./scripts/compile-dotnet-assemblies.bat", "./scripts/set-winrm-automatic.bat", "./scripts/uac-enable.bat", "./scripts/dis-updates.bat"] //, "./scripts/compact.bat"] | |
| } | |
| # post-processor "compress" { | |
| # output = "output/${var.vm_name}.tar.gz" | |
| # } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment