Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder/hyper-v should have provider to create a packer image from a VHD(X) file #4487

Closed
pvandervelde opened this issue Jan 31, 2017 · 22 comments

Comments

@pvandervelde
Copy link
Contributor

Adding a Hyper-V builder that could take a VHD(X) file would allow creating packer images of pre-patched base installs. That way you can create a single base image for an OS with all updates / patches installed. Especially for Windows this will be a great benefit because installing updates can take a very long time. A hyperv-vhd builder could take the pre-patched VHD and use that as base, thereby avoiding the additional effort of having to apply the patches for every packer run.

@mwhooker
Copy link
Contributor

Would be happy to take a look at any PR that comes in for this.

However, this has low chance of being a priority for us anytime soon, so we'd rather close this issue than have it stagnate for more years to come. The best way to get this implemented would be to submit a PR. If you do so, we'd welcome this work. If you want to discuss how to go about doing this, feel free to reach out. I can help answer questions and do pre-reviews.

The reason we're more aggressively closing these issues at the moment is because we're pushing towards a 1.0 release, and reviewing all open issues as part of that process. Please see the mailing list for more details on 1.0.

Again, just want to say thank you for suggesting this and I DO think its a reasonable idea. But, since this is a feature request, it requires some work to add it to the project and we don't plan on doing that soon. But as this is also an open source project we welcome contributions. Thanks!

@pvandervelde
Copy link
Contributor Author

Ok that seems fair. Is there anybody who can write up some pointers on where / how to get started with this. I'd like to have an attempt at it but I have no idea where to get started. I looked at the code for the Hyper-V provider but I have some trouble making sense out of it.

@mwhooker
Copy link
Contributor

I wonder if @taliesins had any thoughts on this. Unfortunately my windows-foo is limited.

Packer can be kind of intimidating if you're just getting started.

I can answer any specific questions you might have about what the code is doing.

One way you might start is by copying the builder/hyperv/iso directory to builder/hyperv/vhd, and start renaming things so they apply to vhd instead of iso.

There's some good information about how builders work here https://www.packer.io/docs/extend/builder.html

You'll want to understand how the ISO builder works. Look at where the ISO builder uses the ISO file, and see how you could translate that to use the VHD(X) files.

@ebjornset
Copy link

Hi @pvandervelde ,

Have you had any attempt at this yet? I made a quick hack today and have an initial version that works on my machine. I followed the hint from @mwhooker, and copied the hyperv-iso builder, and currently I have a lot of duplicated code. I'm a go newbe, but I can continue to refine the code. On the other hand, if you're also working on this issue, I'm happy to give way.

@pvandervelde
Copy link
Contributor Author

No I've been too busy with other work unfortunately :( I had a look at the code but that's as far as I got. If you want me to help testing I can make time for that but in the next few weeks I'm swamped at work as we have a major release coming up.

@taliesins
Copy link
Collaborator

https://github.com/taliesins/packer/tree/hyperv-vmcx

Hopefully I will have it completed and tested soon. :>

@ebjornset
Copy link

Great, then I just nuke my initial experiment and wait:-)

I'm courious about how you plan this feature to work. Will it be more or less like the virtualbox-ovf / vmware-vmx, but with Hyper-V specific parameters?

Btw. Would you like some help, e.g. with the documentation or anything?

@taliesins
Copy link
Collaborator

@ebjornset Can you test Windows Server 2012?

@ebjornset
Copy link

@taliesins I can give it a try. Do you mean Windows Server 2012 and/or Windows Server 2012 R2?

@pvandervelde
Copy link
Contributor Author

@taliesins I'll be happy to test as well, but I don't have a Win2012 server (anymore). Only Win2016, win10 and win8.1

@quantang
Copy link

Hello guys,

I had a different implementation that build hyper-v image based on an existing hyper-v export. Maybe someone could help take a look, which has been submitted here: #4664

The main difference to @taliesins 's implementation is, I import the existing hyper-v export for further processing, instead of cloning an existing virtual machine.

Thanks.

@taliesins
Copy link
Collaborator

@quantang the clone approach is export and then import the results in place. So it should be trivial to extend it to support an import as well. Would be ideal if we could set the url to a zip and it would download and extract it.

The other feature I have been thinking about is linked clones. This makes golden image creation for environments via Packer easy.

Assuming that as you are using Packer, I would guess that using this builder means you are not in charge of image creation. So Ram and Cpu settings may need to be changed during initial base box creation. Even adding the OS iso can be useful (e.g. drivers).

I think this is were we really diverge is. As I am hoping to script as many parts of the customization process as possible.

@quantang
Copy link

quantang commented Mar 14, 2017

@taliesins Right now, we are using Packer to build hyper-v image of ubuntu, however, we don't want to build the image from the beginning every time, which would take a lot of time.

Therefore, we would like to split it into two parts: the first is to build a base image by hyperv-iso builder, then build the final image based on the first one with our product included. So that, we could run the second build quickly and frequently in our daily development.

Thanks.

@taliesins
Copy link
Collaborator

@quantang I understand the speed benefits of a golden images. How are you guys sharing the base boxes and building them? At the moment I am using Teamcity and rebuilding them on every checking of my base boxes repo.

I am curious what other people are doing. Are you guys using a provisioner like Ansible, Puppet or Chef as well? Often this further optimization / specialization takes place in the provisioning stage. At the moment we are doing Vagrant / Ansible & Chef.

You might like to try Ansible host on Windows. Check out: https://github.com/taliesins/win-ansible

One day I will get to adding hyperv support to terraform. Vagrant/Ruby just doesn't seem like it's the optimal solution. This really begins to show when you want to spin up multiple machines in parallel.

@quantang
Copy link

Hello @taliesins,

Hyper-v is one of our target platforms. We would like to deliver hyper-v, VMware and VirtualBox images for our product at the same time. Right now, we are using Jenkins and Packer to build them and keeping all the boxes in our internal shared file system. For the provisioner, we are just using the Packer internal ones, which are mainly some remote shell commands and file upload.

It is great to know lots of your sharing in this area, which are helpful.
Thanks.

@ebjornset
Copy link

Hi,

A follow up list on my part:

@taliesins, Regarding testing of Win 2012, did you mean on a Win 2012 host? And are we talking about Win 2012 R2 or plain Win 2012?

@quantang I can take a look at your PR tomorrow, as I'm on a trip until tonight.

My inspiration when I searched and found this issue was this blog post about Best Practices with Packer and Windows. I would like to follow this workflow with Hyper-V instead of Virtual Box. From what you've written it seems like this is more or like the same motivations as yours?

I must admit that it was @quantang approch I had in mind, but I can see @taliesins point that it is easy to implement both starting from an existing VM and from an exported VM, since the code already does the import.

I'm coming from the dev side and is new to Packer. Currently my plan is to use Maven to distribute the VMs, since it has a strong dependency management story, and I've used it for years on onther projects. I'm working on a Maven structure that I intend to open source on Github when I have removed all hard coded license keys etc.

I have been playing a bit with Chef and the Hyper-V driver for test kitchen, and it looks promising. I'm planning to investigate that further when I feel I have a Packer infrastructure in place.

Terraform has also been on my horizon, so Hyper-V support for Terraform would be very interesting. @taliesins, do you have a Github issue or something I can subscribe to, so I can follow the progress of that effort?

@michaeltlombardi
Copy link

@taliesins Thanks for working on this, your update is exactly what I went googling for today. I'm also available to help with testing / documentation.

@ebjornset
Copy link

@taliesins I got an error when I tested the new builder, see this Gist.

@pvandervelde
Copy link
Contributor Author

@taliesins Have you got a Packer build anywhere that I can test. If not that's cool, I can build one from your branch

@kuoirad
Copy link

kuoirad commented Jun 30, 2017

Has there been any further movement on the packer-vhcx project? I am trying to support developers in a situation similar to @quantang's, where we're currently having to install an Ubuntu vm from scratch every time we want to do a new build. Being able to have a "golden vm" to start from with packer would be a godsend.

@taliesins
Copy link
Collaborator

@ebjornset when you say tested the new builder are you talking about #4944

Its much easier for me to track if you put testing comments on the actual pull request.

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants