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

Hyper-v builder based on an existing hyper-v export. #4664

Closed
wants to merge 8 commits into from

Conversation

quantang
Copy link

Hello guys,

I tried to implement a hyper-v builder based on an existing hyper-v exports.

It follows the hyper-v iso builder approach with an additional step_import_vm function provided. The ISO installer and virtual machine creation related configuration, such as CPU and RAM, are also removed in this builder. A very simple test and documentation are provided.

It has been tested on Windows Server 2016. If anyone could help test on Windows Server 2012, that would be better. The builder will try to find the first match configuration file from source directory, which could be a XML file for Windows Server 2012 or a VMCS file for Windows Server 2016.

Any feedback is welcome.

Cheers,
Quan

@ebjornset
Copy link

@quantang I just ran a quick test of your hyperv-vhd builder on a Win 8.1 machine, and it ran without any problems. I used a "Windows Server 2016 Core" VM created and exported by the hyperv-iso builder.

Based on the name I must admit that I don't quite understand why you import an existing VM. I had expected that you should copy a .vhd(x) file and create a new VM with that disk?

@quantang
Copy link
Author

Hi @ebjornset,

Sorry for the confusing naming. My intention is to import some existing hyper-v export so that I can do some further processing based on the existing one, such as install/update libraries and additional products into the base image. So that I don't need to install the OS and build the image from the beginning every time.

Any suggestion is welcome.

@ebjornset
Copy link

@quantang I'm also eager to find a way to reuse images:-). I think we also can achieve this goal if the builder creates a new virtual machine from an exported .vhd(x) file.

If you took this approach, we would have more flexibility in how we configure the new VM. In fact you could probably support all the hyperv-iso builder's configuration options, except disk_size, and the iso stuff.

@quantang
Copy link
Author

@ebjornset Sure, I will take a look and try to make it. Thanks for your feedback.

@ebjornset
Copy link

@quantang your welcome. Thanks for the effort making this new builder!

I just noticed that the VirtualBox and VMware builders uses 'source_path' as the configuration option for the input file, so that might be a good choice here as well.

@quantang
Copy link
Author

@ebjornset Yes, you are right. Let's make it consistent across the different builders.

@ebjornset
Copy link

@quantang, I ran the builder with an existing, but empty "source_dir", and think the error I got was a bit imprecise:

==> hyperv-vhd: Error importing virtual machine: PowerShell error: Import-VM : Cannot bind argument to parameter 'Path' because it is null. ==> hyperv-vhd: At D:\TEMP.ebj\ps603412273.ps1:4 char:84 ==> hyperv-vhd: + ... _.FullName } | Import-VM -Copy -GenerateNewId -VhdDestinationPath $path | % { $_ ... ==> hyperv-vhd: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ==> hyperv-vhd: + CategoryInfo : InvalidData: (:) [Import-VM], ParameterBindingValidationException ==> hyperv-vhd: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.HyperV.PowerShell.Commands.ImportVMCommand ...

@quantang
Copy link
Author

@ebjornset
Oh, yes, I need update this part of logic to make it more robust.
Sorry that I may make it a little later due to some personal issue.

@pvandervelde
Copy link
Contributor

@quantang How is the progress on this? Did you manage to add the ability to just use a VHD(X) file as the hard-drive?

@quantang
Copy link
Author

@pvandervelde Sorry, not yet finished this part.

@pvandervelde
Copy link
Contributor

@quantang I've been using your branch (after I rebased it on master a while ago) to build a Ubuntu machine on Win10 Hyper-V. It works nicely as long as I build from an imported image that was build on the same machine. If I want to build on a different machine I need to change the network settings (different network switch). So it would still be cool if we could just use the VHD(X) file and then specify the VM settings.

Other than that it works well so far. Will try building a windows box as well and see how that goes

@mwhooker mwhooker requested a review from taliesins May 8, 2017 17:20
@taliesins
Copy link
Collaborator

@quantang can you fix the merge conflicts for your pull request

@quantang
Copy link
Author

Hi @taliesins, I am not sure whether I did it right, as I merged the master branch to resolve the conflicts. I also update some incorrect path name in the code. Please feel free to tell me if anything wrong.

Hi @pvandervelde, I am so sorry that I did not update it for a long time since I start working in my job to catch a release. I plan to make it better after that, I hope it works for you. Sorry again.

@taliesins
Copy link
Collaborator

@quantang and @pvandervelde and @ebjornset I think we should consider rather accepting pull request #4944 and closing this pull request. It is good work but I think the other approach covers all the bases.

The other pull request covers:

  1. Import from folder
  2. Clone vm
  3. Use vhd and vhdx files

@pvandervelde
Copy link
Contributor

@taliesins That sounds good to me. I'm going to have to build a copy of packer with those changes to test it.

@taliesins
Copy link
Collaborator

@mwhooker
Copy link
Contributor

Thanks for the PR @taliesins.

Please close this out if we're moving to #4944

@taliesins
Copy link
Collaborator

@quantang are you happy we close this in favour of #4944

@quantang
Copy link
Author

quantang commented May 31, 2017 via email

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

Successfully merging this pull request may close these issues.

5 participants