{"id":14064581,"url":"https://github.com/marcinbojko/hv-packer","last_synced_at":"2025-04-09T15:09:34.487Z","repository":{"id":38858472,"uuid":"110365350","full_name":"marcinbojko/hv-packer","owner":"marcinbojko","description":"Hyper-V Generation 2 Packer Templates for Windows 2019/2022,  AlmaLinux 8.x/AlmaLinux 9.x/RockyLinux 8.x/9.x/OracleLinux 8.x/9.x Ubuntu 20.04/Ubuntu 22.04/Ubuntu 24.04","archived":false,"fork":false,"pushed_at":"2024-06-03T11:20:53.000Z","size":4559,"stargazers_count":199,"open_issues_count":0,"forks_count":73,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-09T15:09:22.479Z","etag":null,"topics":["almalinux","centos","hyper-v","linux","oracle","oracle-linux","packer","powershell","rockylinux","ubuntu","vagrant","windows"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcinbojko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-11T17:28:38.000Z","updated_at":"2025-04-02T12:14:32.000Z","dependencies_parsed_at":"2023-12-08T10:30:29.979Z","dependency_job_id":"3260215d-85c9-4395-ac20-5b35be34e3c3","html_url":"https://github.com/marcinbojko/hv-packer","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.42553191489361697","last_synced_commit":"0ca2b8fa4665280faa7cd8ab3483ac1f897a5690"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcinbojko%2Fhv-packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcinbojko%2Fhv-packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcinbojko%2Fhv-packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcinbojko%2Fhv-packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcinbojko","download_url":"https://codeload.github.com/marcinbojko/hv-packer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["almalinux","centos","hyper-v","linux","oracle","oracle-linux","packer","powershell","rockylinux","ubuntu","vagrant","windows"],"created_at":"2024-08-13T07:03:56.602Z","updated_at":"2025-04-09T15:09:34.463Z","avatar_url":"https://github.com/marcinbojko.png","language":"PowerShell","funding_links":["https://www.buymeacoffee.com/marcinbojko"],"categories":["PowerShell"],"sub_categories":[],"readme":"# Set of Hashicorp's `Packer's` templates to create Microsoft Hyper-V virtual machines\n\n![RockyLinux](https://img.shields.io/badge/Linux-Rocky-brightgreen)\n![OracleLinux](https://img.shields.io/badge/Linux-Oracle-brightgreen)\n![AlmaLinux](https://img.shields.io/badge/Linux-Alma-brightgreen)\n![UbuntuLinux](https://img.shields.io/badge/Linux-Ubuntu-orange)\n![Windows2019](https://img.shields.io/badge/Windows-2019-blue)\n![Windows2022](https://img.shields.io/badge/Windows-2022-blue)\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/marcinbojko)\n\nConsider buying me a coffee if you like my work. All donations are appreciated. All donations will be used to pay for pipeline running costs\n\n\u003c!-- TOC --\u003e\n\n- [Set of Hashicorp's Packer's templates to create Microsoft Hyper-V virtual machines](#set-of-hashicorps-packers-templates-to-create-microsoft-hyper-v-virtual-machines)\n  - [Requirements](#requirements)\n  - [Requirements - Quick Start](#requirements---quick-start)\n    - [Install packer from Chocolatey](#install-packer-from-chocolatey)\n    - [Install required plugins](#install-required-plugins)\n    - [Use account with Administrator privileges for Hyper-V](#use-account-with-administrator-privileges-for-hyper-v)\n    - [Add firewal exclusions for TCP ports 8000-9000 default range](#add-firewal-exclusions-for-tcp-ports-8000-9000-default-range)\n    - [Adjust Hyper-V settings](#adjust-hyper-v-settings)\n    - [Default passwords](#default-passwords)\n  - [Scripts](#scripts)\n    - [Windows Machines](#windows-machines)\n    - [Linux Machines](#linux-machines)\n      - [Ansible Playbooks CentOS/AlmaLinux/RockyLinux/OracleLinux](#ansible-playbooks-centosalmalinuxrockylinuxoraclelinux)\n  - [Usage](#usage)\n    - [hv_generic.ps1 parameters](#hv_genericps1-parameters)\n    - [Building Microsoft Windows](#building-microsoft-windows)\n      - [Building iso files needed for provisioning](#building-iso-files-needed-for-provisioning)\n      - [Examples for Windows](#examples-for-windows)\n    - [Building AlmaLinux Machines](#building-almalinux-machines)\n      - [Examples for AlmaLinux](#examples-for-almalinux)\n    - [Building RockyLinux Machines](#building-rockylinux-machines)\n      - [Examples for RockyLinux](#examples-for-rockylinux)\n    - [Building OracleLinux Machines](#building-oraclelinux-machines)\n      - [Examples for OracleLinux](#examples-for-oraclelinux)\n    - [Building Ubuntu Machines](#building-ubuntu-machines)\n      - [Examples for Ubuntu](#examples-for-ubuntu)\n  - [Known issues](#known-issues)\n    - [I have general problem not covered here](#i-have-general-problem-not-covered-here)\n    - [I'd like to contribute](#id-like-to-contribute)\n    - [Infamous UEFI/Secure boot WIndows implementation](#infamous-uefisecure-boot-windows-implementation)\n    - [~~On Windows Server 2019/Windows 10 1809 image boots to fast for packer to react~~](#on-windows-server-2019windows-10-1809-image-boots-to-fast-for-packer-to-react)\n    - [~~When Hyper-V host has more than one interface Packer sets {{ .HTTPIP }} variable to inproper interface~~](#when-hyper-v-host-has-more-than-one-interface-packer-sets--httpip--variable-to-inproper-interface)\n    - [~~Packer version 1.3.0/1.3.1 have bug with windows-restart provisioner~~](#packer-version-130131-have-bug-with-windows-restart-provisioner)\n    - [Packer won't run until VirtualSwitch is created as shared](#packer-wont-run-until-virtualswitch-is-created-as-shared)\n    - [I have problem how to find a proper WIM  name in Windows ISO to pick proper version](#i-have-problem-how-to-find-a-proper-wim--name-in-windows-iso-to-pick-proper-version)\n    - [On Windows machines, build break during updates phase, when update cycles are interfering with each other](#on-windows-machines-build-break-during-updates-phase-when-update-cycles-are-interfering-with-each-other)\n    - [Why don't you use ansible instead of shell scripts for provisioning](#why-dont-you-use-ansible-instead-of-shell-scripts-for-provisioning)\n  - [Support me](#support-me)\n  - [About](#about)\n\n\u003c!-- /TOC --\u003e\n\n## Requirements\n\n- packer \u003e=`1.10.0`. Do not use packer below 1.7.0 version. For previous packer versions use previous releases from this repository\n- Microsoft Hyper-V Server 2016/2019 or Microsoft Windows Server 2016/2019 (not 2012/R2) with Hyper-V role installed as host to build your images\n- firewall exceptions for `packer` http server (look down below)\n- [OPTIONAL] Vagrant \u003e= `2.3.4` - for `vagrant` version of scripts. Boxes (prebuilt) are already available here: [https://app.vagrantup.com/marcinbojko](https://app.vagrantup.com/marcinbojko)\n- be aware, for 2016 - VMs are in version 8.0, for 2019 - VMs are in version 9.0. There is no way to reuse higher version in previous operating system. If you need v8.0 - build and use only VHDX.\n- properly constructed virtual switch in Hyper-v allowing virtual machine to get IP from DHCP and contact Hyper-V server on mentioned packer ports. This is a must, if kickstart is reachable over the network.\n\n## Requirements - Quick Start\n\n### Install packer from Chocolatey\n\n```cmd\nchoco install packer --version=1.10.0 -y\n```\n\n### Install required plugins\n\nIn root folder of a repository\n\n```cmd\npacker init --upgrade config.pkr.hcl\n```\n\n\u003c!-- ### Install vagrant from Chocolatey\n\n```cmd\nchoco install vagrant --version=2.3.4 -y\n``` --\u003e\n\n### Use account with Administrator privileges for Hyper-V\n\n### Add firewal exclusions for TCP ports 8000-9000 (default range)\n\n```powershell\nRemove-NetFirewallRule -DisplayName \"Packer_http_server\" -Verbose\nNew-NetFirewallRule -DisplayName \"Packer_http_server\" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8000-9000\n```\n\n### Adjust Hyper-V settings\n\nTo adjust to your Hyper-V, please check variables below and/or in ./variables files\n\n- (variable `vlan_id` in /variables/variables.*.pkvars.hcl) - proper VLAN ID . Look up to find your build server vEthernet setings.\n- (variable `switch_name` in /variables/variables.*.pkvars.hcl) - proper Hyper-V Virtual Switch name (access to Internet will be required). Make sure you're using pre-existing switch in your Hyper-V server - creation of new switch by packer, instead of reusing existing one can cause lack of Internet access, thus failing the build.\n\n```yaml\n# example of mentioned variables\nvlan_id = \"\"\nswitch_name = \"vSwitch\"\n```\n\n### Default passwords\n\n|OS|username|password|\n|--|--------|--------|\n|Windows|Administrator|password|\n|CentOS/RHEL|root|password|\n|Ubuntu|ubuntu|password|\n\n## Scripts\n\n### Windows Machines\n\n- all available updates will be applied (3 passes)\n- latest version of chocolatey\n- packages from a list below:\n\n  |Package|Version|Mandatory/Optional|\n  |-------|-------|------------------|\n  |dotnetfx|latest|Mandatory|\n  |sysinternals|latest|Mandatory|\n  |tabby|latest|Optional|\n\n### Linux Machines\n\n- Repositories:\n\n  |Repository|Package|switch|default|\n  |----------|------------|---|---|\n  |Epel 7/8/9|epel-release|can be switched off by setting \"install_epel\" to `false`|true|\n  |Webmin |webmin|can be switched on by setting \"install_webmin\" to `false`|false|\n  |Cockpit |cockpit|can be switched on by setting \"install_zabbix\" to `true`|true|\n  |Hyper-V |SCVMM Agent|can be switched off by setting \"install_hyperv\" to `false`|true|\n  |Neofetch  |neofetch|can be switched off by setting \"install_neofetch\" to `false`|true|\n\n  Be aware, turning off latest System Center Virtual Machine Agent will cause System Center fail to deploy machines\n\n#### Ansible Playbooks (CentOS/AlmaLinux/RockyLinux/OracleLinux)\n\nDuring deployment ansible-base and ansible are installed in operating system. After deployment ends, these packages are removed.\nPlaybooks are held in `/extra/playbooks` folder, with proper OS variables.\n\n- adjust `./variables/*.yml` files to achieve override for ansible\n\n```yaml\ninstall_epel:                  true  # install Epel\ninstall_webmin:                true  # install Webmin\ninstall_hyperv:                true  # install Hyper-v and scvmm agent\ninstall_cockpit:               false # install Cockpit\ninstall_docker_workaround:     true  # add `fsck.repair=yes` to grub\ninstall_neofetch:              true  # install neofetch\ninstall_updates:               true  # install updates\ninstall_extra_groups:          true  # install extra groups\ndocker_prepare:                false # prepare extra volumen for docker\nextra_device:                  \"\"    # prepare mkfs and mount extra block device for docker\ninstall_motd:                  true  # install motd (neofetch run)\n```\n\n## Usage\n\nBuilding machines is realised through a dedicated script `hv_generic.ps1` with proper parameters.\n\n### `hv_generic.ps1` parameters\n\n### Building Microsoft Windows\n\n#### Building iso files needed for provisioning\n\nFor Generation 2 prepare `secondary.iso` with folder structure:\n\n```example\n- ./extra/files/windows/2022/std/Autounattend.xml     =\u003e /Autounattend.xml\n- ./extra/scripts/hyper-v/bootstrap.ps1            =\u003e /bootstrap.ps1\n```\n\nThis template uses this image name in Autounattendes.xml. If youre using different ISO you'll have to adjust that part in proper file and rebuild `secondary.iso` image.\n\n```xml\n\u003cInstallFrom\u003e\n    \u003cMetaData wcm:action=\"add\"\u003e\n        \u003cKey\u003e/IMAGE/NAME \u003c/Key\u003e\n        \u003cValue\u003eWindows Server 2022 SERVERSTANDARD\u003c/Value\u003e\n    \u003c/MetaData\u003e\n\u003c/InstallFrom\u003e\n```\n\n|Action|Version|Template|Log|OS|\n|-------|-------|--------|---|-|\n|`build`|windows_server_2019_std|windows|0/1|Microsoft Server 2019 Standard|\n|`build`|windows_server_2019_dc|windows|0/1|Microsoft Server 2019 Datacenter|\n|`build`|windows_server_2022_std|windows|0/1|Microsoft Server 2022 Standard|\n|`build`|windows_server_2022_dc|windows|0/1|Microsoft Server 2022 Datacenter|\n\n#### Examples for Windows\n\n```powershell\n\nExample for Windows 2019 Standard\n\n```powershell\n./hv_generic.ps1 -Action build -Version windows_server_2019_std -Template windows -Log 0\n```\n\nExample for Windows 2019 Datacenter\n\n```powershell\n./hv_generic.ps1 -Action build -Version windows_server_2019_dc -Template windows -Log 0\n```\n\nExample for Windows 2022 Standard\n\n```powershell\n./hv_generic.ps1 -Action build -Version windows_server_2022_std -Template windows -Log 0\n```\n\nExample for Windows 2022 Datacenter\n\n```powershell\n./hv_generic.ps1 -Action build -Version windows_server_2022_dc -Template windows -Log 0\n```\n\n### Building AlmaLinux Machines\n\n|Action|Version|Template|Log|OS|\n|-------|-------|--------|---|-|\n|`build`|almalinux-8.9|rhel|0/1|Alma Linux 8.9|\n|`build`|almalinux-9.4|rhel|0/1|Alma Linux 9.4|\n\n#### Examples for AlmaLinux\n\n```powershell\n.\\hv_generic.ps1 -Action build -Version almalinux-8.9 -Template rhel -Log 0\n.\\hv_generic.ps1 -Action build -Version almalinux-9.4 -Template rhel -Log 0\n```\n\n### Building RockyLinux Machines\n\n|Action|Version|Template|Log|OS|\n|-------|-------|--------|---|-|\n|`build`|rockylinux-8.9|rhel|0/1|Rocky Linux 8.9|\n|`build`|rockyinux-9.4|rhel|0/1|Rocky Linux 9.4|\n\n#### Examples for RockyLinux\n\n```powershell\n.\\hv_generic.ps1 -Action build -Version rockylinux-8.9 -Template rhel -Log 0\n.\\hv_generic.ps1 -Action build -Version rockylinux-9.4 -Template rhel -Log 0\n```\n\n### Building OracleLinux Machines\n\n|Action|Version|Template|Log|OS|\n|-------|-------|--------|---|-|\n|`build`|oraclelinux-8.9|rhel|0/1|Oracle Linux 8.9|\n|`build`|oraclelinux-9.4|rhel|0/1|Oracle Linux 9.4|\n\n#### Examples for OracleLinux\n\n```powershell\n.\\hv_generic.ps1 -Action build -Version oraclelinux-8.9 -Template rhel -Log 0\n.\\hv_generic.ps1 -Action build -Version oraclelinux-9.4 -Template rhel -Log 0\n```\n\n### Building Ubuntu Machines\n\n|Action|Version|Template|Log|OS|\n|-------|-------|--------|---|-|\n|`build`|ubuntu-20.04|ubuntu|0/1|Ubuntu 20.04|\n|`build`|ubuntu-22.04|ubuntu|0/1|Ubuntu 22.04|\n|`build`|ubuntu-24.04|ubuntu|0/1|Ubuntu 24.04|\n\n#### Examples for Ubuntu\n\n```powershell\n.\\hv_generic.ps1 -Action build -Version ubuntu-20.04 -Template ubuntu -Log 0\n.\\hv_generic.ps1 -Action build -Version ubuntu-22.04 -Template ubuntu -Log 0\n.\\hv_generic.ps1 -Action build -Version ubuntu-24.04 -Template ubuntu -Log 0\n```\n\n## Known issues\n\n### I have general problem not covered here\n\nPlease create an issue in github. There is slim chance I'll find the time to be your personal helpdesk ;)\n\n### I'd like to contribute\n\nSure. If I can ask - create your PR in smaller sizes, this is repo used for my work, so smaller changes - bigger chances to succeed.\n\n### Infamous UEFI/Secure boot WIndows implementation\n\nDuring the deployment secure keys are stored in `*.vmcx` file and are separated from `*.vhdx` file. To countermeasure it - there is added extra step in a form of (`/usr/local/bin/uefi.sh`) script that will check for existence of CentOS folder in EFI and will add extra entry in UEFI.\nIn manual setup you can run it as a part of your deploy. In SCVMM deployment I'd recommend using `RunOnce` feature.\n\n### ~~On Windows Server 2019/Windows 10 1809 image boots to fast for packer to react~~\n\n[https://github.com/hashicorp/packer/issues/7278#issuecomment-468492880](https://github.com/hashicorp/packer/issues/7278#issuecomment-468492880)\n\nFixed in version 1.4.4.  Do not use previous versions\n\n### ~~When Hyper-V host has more than one interface Packer sets {{ .HTTPIP }} variable to inproper interface~~\n\nFixed in version 1.4.4. Do not use lower versions\n~~No resolution so far, template needs to be changed to pass real IP address, or there should be connection between these addresses. Limiting these, end with timeout errors.**~~\n\n### ~~Packer version 1.3.0/1.3.1 have bug with `windows-restart` provisioner~~\n\n[https://github.com/hashicorp/packer/issues/6733](https://github.com/hashicorp/packer/issues/6733)\n\n### Packer won't run until VirtualSwitch is created as shared\n\n[https://github.com/hashicorp/packer/issues/5023](https://github.com/hashicorp/packer/issues/5023)\nWill be fixed in 1.4.x revision\n\n### I have problem how to find a proper WIM  name in Windows ISO to pick proper version\n\nYou can use number. If you have 4 images on the list of choice - use `ImageIndex` with proper `Value`\n\n```xml\n\u003cImageInstall\u003e\n    \u003cOSImage\u003e\n        \u003cInstallFrom\u003e\n            \u003cMetaData wcm:action=\"add\"\u003e\n                \u003cKey\u003e/IMAGE/INDEX \u003c/Key\u003e\n                \u003cValue\u003e2\u003c/Value\u003e\n            \u003c/MetaData\u003e\n        \u003c/InstallFrom\u003e\n        \u003cInstallTo\u003e\n            \u003cDiskID\u003e0\u003c/DiskID\u003e\n            \u003cPartitionID\u003e2\u003c/PartitionID\u003e\n        \u003c/InstallTo\u003e\n    \u003c/OSImage\u003e\n\u003c/ImageInstall\u003e\n```\n\n### On Windows machines, build break during updates phase, when update cycles are interfering with each other\n\nIncrease variable  `update_timeout` in `./variables/*.json` file - this will create longer pauses between stages, allowing cycles to complete before jumping to another one.\n\n### Why don't you use ansible instead of shell scripts for provisioning\n\nI wish. In short - Windows. These builds should be done with minimum effort (Hyper-V role is enough). Building custom ansible station with lots of checks right now fails in my tryouts.\n\n## Support me\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/marcinbojko)\n\nConsider buying me a coffee if you like my work. All donations are appreciated. All donations will be used to pay for pipeline running costs\n\n## About\n\n- Marcin Bojko - marcin(at)bojko.com.pl\n- [https://marcinbojko.dev/](https://marcinbojko.dev/)\n\nWork based on [https://github.com/jacqinthebox/packer-templates.git](https://github.com/jacqinthebox/packer-templates.git)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcinbojko%2Fhv-packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcinbojko%2Fhv-packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcinbojko%2Fhv-packer/lists"}