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 provider #119

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Hyper-V provider #119

wants to merge 3 commits into from

Conversation

tsmolka
Copy link

@tsmolka tsmolka commented Jul 28, 2017

I have just tested ubuntu1604 build with Hyper-V provider and I would like your feedback. Would you be interested in adding this provider to boxcutter?

Few notes:

@StefanScherer
Copy link
Contributor

This is awesome. Maybe my next machine at work will have HyperV installed, so I'm looking forward to have some boxcutter VMs for it.
Packer 1.0.4 has your fix for 5184.
Right now I'm not able to test the template, but I'll try soon.

ubuntu.json Outdated
"passwd/user-password={{ user `ssh_password` }} ",
"passwd/user-password-again={{ user `ssh_password` }} ",
"passwd/username={{ user `ssh_username` }} ",
"initrd=/install/initrd.gz -- <enter>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying your pull request with a cherry-pick to update to 16.04.3 ISO URL's (could you please rebase your PR?).

It seems that Packer has some problems with the boot_command. The last key strokes show some errors and I only get initrd=/installngz
bildschirmfoto 2017-08-29 um 11 32 36

I had this several times. After manually fixing the string to initrd=/install/initrd.gz -- and pressing ENTER the Packer build seems to work. I remember that other providers also had timing issues typing long boot commands.

My setup is an Azure VM running Windows Server 2016 with Packer 1.0.4.

One other thing to mention. We have to quote the file name for the -var-file option. Otherwise PowerShell ignores the .json extension. So my command to run your PR was:

 packer build -only=hyperv-iso -var-file="ubuntu1604.json" ubuntu.json

The Azure VM was created using a Terraform template: https://github.com/StefanScherer/packer-windows/tree/my/hyperv/terraform

bildschirmfoto 2017-08-29 um 11 44 06

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Stefan, I have just merged my branch with master to upgrade to 16.04.3 ISO (no issue there). I can reproduce issues with boot_command you are mentioning on Azure VM as well. On physical machine this works as expected.

I have quickly tested "generation": "2" VM where boot_command seems to be more reliable. Since floppy is not supported I had to use preseed/url.

When testing, you will probably need to:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. In the meantime I've opened hashicorp/packer#5291 and it seems a bug in Packer. I went through the sources, but couldn't find the right place. It seems the hyperv builder uses some PowerShell code where the delay between each key stroke should be added.

My Azure VM has the DHCP feature installed and running, so this shouldn't be a problem. And yes, packer.exe should have a firewall exception as for other providers as well.
I will try your latest commit tomorrow.

@StefanScherer
Copy link
Contributor

OK, after adding a firewall rule for packer.exe I make a little progress. But right now the VM has only a black screen, can react on ctrl+alt+delete events. When I type ctrl+alt+f1 I can make the tty visible and login. The VM has an IP address from the Windows DHCP server running on the host machine. I also can ssh into the VM manually.
But packer is not able to fetch the IP address of that VM, the Hyper-V manager also does not show the IP address.

bildschirmfoto 2017-08-31 um 10 38 42

In Azure I have to use an internal VM switch with NAT, the external switch didn't work there.
I'll dig deeper with packer debug logs and see what happens there.
Any hint is very appreciated.

@tsmolka
Copy link
Author

tsmolka commented Aug 31, 2017

This might be caused by the fact that I used linux-headers-$(uname -r) linux-tools-$(uname -r) linux-cloud-tools-$(uname -r) in pkgsel/include instead of linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial as recommended in https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/supported-ubuntu-virtual-machines-on-hyper-v.

I hit similar issues with Debian VM after kernel upgrade.

@StefanScherer
Copy link
Contributor

Tried to remove the "uname -r" packages, installed the lts-xenial packages, rebooted the VM, but Hyper-V Manager still does not show an IP address in the networking tab.

I also tried the example showed in the packer.io docs for hyperv-iso, but it also hangs at the same point.

BTW: Your vagrant box tsmolka/ubuntu1604 works in my Azure VM and shows an IP address and also vagrant ssh is working. Only thing was that the vagrant up timed out after 120 seconds. This is generation 1.

@tsmolka
Copy link
Author

tsmolka commented Aug 31, 2017

Not sure what is causing networking issue then.

This timeout could be caused by SMB synced_folder. You might want to pass mount_options when connecting from linux guest to newer Windows hosts or disable completely if not needed:

config.vm.synced_folder ".", "/vagrant", disabled: false, mount_options: ["vers=3.0"]

@StefanScherer
Copy link
Contributor

Thanks, I'll try that. In the meantime I tried the previous packer template with generation 1 again, but had also no luck seeing the IP address in the Hyper-V Manager. I found out that only two of the three hv-xxx-daemon were running. the hv-kvp-daemon crashed after 60 seconds.

When I start it again with sudo systemctl start hv-kvp-daemon it keeps running, but I still cannot see an IP address in Hyper-V manager. Playing with sudo ifdown eth0 and sudo ifup eth0 which works fine in your Vagrant box (16.04.2, /usr/lib/linux-tools/4.4.0-62-generic/hv_kvp_daemon), but doesn't work in the packer build (16.04.3, /usr/lib/linux-tools/4.4.0-87-generic/hv_kvp_daemon).

I also have tried the generation 2 build with 16.04.2 ISO file with the 4.4.0-62 version, but hv_kvp_daemon also stops after the first minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants