DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Running Ansible From Windows Using Virtualization
  • Google Cloud “GCP” native NixOS images build
  • How to Create Custom Azure Pipelines Build Agent Fully Automated
  • How to Quickly Build a Progressive Web App Using Lightning Web Components

Trending

  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Integration Isn’t a Task — It’s an Architectural Discipline
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Create Hyper-V Images With Packer

How to Create Hyper-V Images With Packer

In this posts, Matt Wrock will discuss how you can use Taliesin Sisson's PR #2576 in order to build Hyper-V images with Hyper-V.

By 
Matt Wrock user avatar
Matt Wrock
·
Oct. 06, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
10.9K Views

Join the DZone community and get the full member experience.

Join For Free

I've been playing with some new significant changes to my Packer build process. This includes replacing the Boxstarter based install with a Chef cookbook and also using a native Hyper-V builder. I'll be blogging about the Chef stuff later. This post will discuss how to use Taliesin Sisson's PR #2576 to build Hyper-V images with Hyper-V.

The State of Hyper-V Builders

Packer currently comes bundled with builders for the major cloud providers, some local hypervisors like VirtualBox, VMware, Parallels, and QEMU as well as OpenStack and Docker. There is no built-in Hyper-V builder (the native hypervisor on Windows).

The packer ecosystem does provide a plugin model for supporting third-party builders. In early 2015, it was announced that MSOpenTech had built a usable Hyper-V builder plugin and there were hopes to pull that into Packer core. This never happened. I personally see this like two technology asteroids rocketing past each other. The Hyper-V builder came in on a version of GO that Packer did not yet support but by the time it did, Packer and Hyper-V had moved on.

I started playing with Packer in July of 2015 and when I tried this builder on Windows 10 (a technical preview at the time) it just did not work. Likely this is because some things in Hyper-V, like its virtual machine file format, had completely changed. Hard to say but as a Packer newcomer and wanting to just get an image built I quickly moved away from using a Hyper-V builder.

Converting VirtualBox to Hyper-V

After ditching the hope of building Hyper-V images with Packer, I resurrected my daughter's half-busted laptop to become my VirtualBox Packer builder. It worked great.

I also quickly discovered that I could simply convert the VirtualBox images to VHD format and create a Vagrant Hyper-V provider box without Hyper-V. I blogged about this procedure here and I think it is still a good option for creating multiple providers on a single platform.

It's great to take the exact same image that provisions a VirtualBox VM to also provision a Hyper-V VM. However, its sometimes a pain to have to switch over to a different environment. My day-to-day dev environment uses Hyper-V and, ideally, this is where I would develop and test Packer builds as well.

A Hyper-V Builder That Works

So early this year I started hearing mumblings of a new PR to Packer for an updated Hyper-V builder. My VirtualBox setup worked fine and I needed to produce both VirtualBox and Hyper-V providers anyways so I was not highly motivated to try out this new builder.

I spoke at Hashiconf about creating Windows Vagrant boxes with Packer. It sure would be nice not to have to bring my VirtualBox rig and just use a Hyper-V builder on my personal laptop.

So, I finally took this PR for a spin last week and I was pretty amazed when it just worked. One thing I have noticed in contemporary DevOps tooling is that the chances of the tooling working on Windows is sketchy and as for Hyper-V? Good luck! No one uses it in the communities where I mingle (except for me, it sometimes seems). If few are testing the tooling and most building the tooling are not familiar with Windows environment nuances, it's not a scenario optimized for success.

Using PR #2576 to Build Hyper-V Images

For those unfamiliar with working with Go source builds, getting the PR built and working is probably the biggest blocker to getting started. It's really not that bad at all. Hand here is a step-by-step walkthrough to building the PR:

  1. Install golang using Chocolatey: cinst golang -y. This puts Go in c:\tools\go.
  2. Create a directory for Go development: c:\dev\go and set $env:gopath to that path.
  3. From that path, run go get github.com/mitchellh/packer, which will put packer's master branch in c:\dev\go\src\github.com\mitchellh\packer.
  4. Navigate to that directory and add a git remote to Taliesin Sisson's PR branch: git remote add hyperv https://github.com/taliesins/packer.
  5. Run git fetch hyperv and then git checkout hyperv. Now, the code for this PR is on the disk.
  6. Build it with go build -o bin/packer.exe.
  7. Now, the built packer.exe is at C:\dev\go\src\github.com\mitchellh\packer\bin\packer.exe.

You can now run C:\dev\go\src\github.com\mitchellh\packer\bin\packer.exe build and this builder will be available!

Things to Know

If you have used the VirtualBox builder, this builder is really not much different at all. The only thing that surprised and tripped me up a bit at first is that unless you configure it differently, the builder will create a new switch to be used by the VMs it creates. This switch may not be able to access the internet and your build might break. You can easily avoid this and use an existing switch by using the switch_name setting.

A Working Template

As I mentioned above, I've been working on using Chef instead of Boxstarter to provision the packer image. I've been testing this building a Windows Server 2016 TP5 image. Here is the Hyper-V template. The builder section is as follows:

 "builders": [
    {
      "type": "hyperv-iso",
      "guest_additions_mode": "disable",
      "iso_url": "{{ user `iso_url` }}",
      "iso_checksum": "{{ user `iso_checksum` }}",
      "iso_checksum_type": "md5",
      "ram_size_mb": 2048,
      "communicator": "winrm",
      "winrm_username": "vagrant",
      "winrm_password": "vagrant",
      "winrm_timeout": "12h",
      "shutdown_command": "C:/Windows/Panther/Unattend/packer_shutdown.bat",
      "shutdown_timeout": "15m",
      "switch_name": "internal_switch",
      "floppy_files": [
        "answer_files/2016/Autounattend.xml",
        "scripts/winrm.ps1"
      ]
    }
  ]
Documentation

Fortunately, this PR includes updated documentation for the builder. You can view it in markdown here. 

Hyper-V Git Virtual Machine VirtualBox Build (game engine)

Published at DZone with permission of Matt Wrock, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Running Ansible From Windows Using Virtualization
  • Google Cloud “GCP” native NixOS images build
  • How to Create Custom Azure Pipelines Build Agent Fully Automated
  • How to Quickly Build a Progressive Web App Using Lightning Web Components

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!