Packer hyper-v inside a Vm ware machine

477 views
Skip to first unread message

Morgan Andrew Davis

unread,
Feb 25, 2019, 9:49:32 AM2/25/19
to Packer
Hello again. I am having some issues with the hyper-v builder. I am currently trying to use the hyper-v builder to better automate image creation for the company I work for. I don't have a version of windows capable of hyper-v so I have a vmware machine that is. The builder itself seems to work as I can run a basic build and it will have me manually go through the install. The issue arises when I include a kickstart file to automatically do the install. When I do this, a college and I have come to the conclusion that the boot fails and the dracut emergency shell is invoked. He and I thought this may be because of missing hyper-v drivers. We took steps to include them via dracut, but it doesn 't seem to fix the issue. I'll attach a copy of the json and kickstart file. Is there any advice you can give?

ks.cfg:
# CentOS 7.x kickstart file - centos7.ks
#
# For more information on kickstart syntax and commands, refer to the
# CentOS Installation Guide:
#
# For testing, you can fire up a local http server temporarily.
# cd to the directory where this ks.cfg file resides and run the following:
#    $ python -m SimpleHTTPServer
# You don't have to restart the server every time you make changes.  Python
# will reload the file from disk every time.  As long as you save your changes
# they will be reflected in the next HTTP download.  Then to test with
# a PXE boot server, enter the following on the PXE boot prompt:
#    > linux text ks=http://<your_ip>:8000/ks.cfg

# Required settings
lang en_US.UTF-8
keyboard us
rootpw atomicorp
authconfig --enableshadow --enablemd5
timezone UTC

# Optional settings
install
cdrom
#user --name=vagrant --plaintext --password vagrant
unsupported_hardware
network --device eth0 --bootproto=dhcp
firewall --disabled
selinux --disabled
# The biosdevname and ifnames options ensure we get "eth0" as our interface
# even in environments like virtualbox that emulate a real NW card
bootloader --location=mbr --append="no_timer_check console=tty0 console=ttyS0,115200 net.ifnames=0 biosdevname=0"
text
skipx
zerombr
clearpart --all --initlabel
autopart
firstboot --disabled
reboot

%packages --nobase --ignoremissing --excludedocs
# vagrant needs this to copy initial files via scp
openssh-clients
# Prerequisites for installing VMware Tools or VirtualBox guest additions.
# Put in kickstart to ensure first version installed is from install disk,
# not latest from a mirror.
kernel-headers
kernel-devel
gcc
make
perl
curl
wget
bzip2
dkms
patch
net-tools
selinux-policy-devel
# Core selinux dependencies installed on 7.x, no need to specify
# Other stuffz
sudo
nfs-utils
-fprintd-pam
-intltool

# Microcode updates cannot work in a VM
-microcode_ctl
# unnecessary firmware
-aic94xx-firmware
-alsa-firmware
-alsa-tools-firmware
-atmel-firmware
-b43-openfwwf
-bfa-firmware
-ipw*-firmware
-irqbalance
-ivtv-firmware
-iwl*-firmware
-kernel-firmware
-libertas-usb8388-firmware
-ql*-firmware
-rt61pci-firmware
-rt73usb-firmware
-xorg-x11-drv-ati-firmware
-zd1211-firmware
# Don't build rescue initramfs
-dracut-config-rescue
# no firewalld
-firewalld
-firewalld-filesystem
%end

%post
# configure vagrant user in sudoers
#echo "%vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
#chmod 0440 /etc/sudoers.d/vagrant
#cp /etc/sudoers /etc/sudoers.orig
sed -i "s/^\(.*requiretty\)$/#\1/" /etc/sudoers
# keep proxy settings through sudo
echo 'Defaults env_keep += "HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY NO_PROXY"' >> /etc/sudoers
pushd /etc/dracut.conf.d/
echo 'add_drivers+="hv_vmbus hyperv_fb hid_hyperv hv_storvsc hyperv_keyboard hv_netvsc hv_balloon hv_utils"'
popd
dracut -f
%end

hyper-v1.json:
not sure if the username and password are right, but it never gets to timeout on ssh anyway
{
"builders": [{
"type": "hyperv-iso",
"boot_command": [
"<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort}}/{{ user `kickstart` }}<enter>"
],
"iso_url": "C:/Users/User/Downloads/CentOS-7-x86_64-Minimal-1810.iso",
"iso_checksum": "38d5d51d9d100fd73df031ffd6bd8b1297ce24660dc8c13a3b8b4534a4bd291c",
"iso_checksum_type": "sha256",
"ssh_username": "root",
"ssh_password": "toor",
"ssh_timeout": "10000s",
"generation": "1",
"ram_size": "2048",
"shutdown_command": "echo 'toor' | sudo -S shutdown -P now"
}],
"variables": {
"kickstart": "ks.cfg",
"http_directory": "C:/Users/User/Desktop/kickstart/centos7"
}
}

Megan Marsh

unread,
Feb 25, 2019, 11:09:27 AM2/25/19
to packe...@googlegroups.com
Can your HyperV vm reach the internet? When I've had frustrating boot failures with KS files it's because the vm can't find the files that Packer is serving. Check out this resource on configuring the network: https://www.groovypost.com/howto/share-an-ethernet-or-wireless-network-connection-with-hyper-v-in-windows-10/ . tl;dr is that you need to go to the control panel's network and sharing center and make sure that the eth0 adpater is sharing internet with your hyper-v adapter.
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Morgan Andrew Davis

unread,
Feb 26, 2019, 11:00:27 AM2/26/19
to Packer
Mrs. Marsh, I think my responses on here are being deleted for some reason. I have no idea why that is. Would you rather talk via email? My email is mda...@atomicorp.com.

Megan Marsh

unread,
Feb 26, 2019, 12:34:28 PM2/26/19
to packe...@googlegroups.com
Hi, looks like google flagged your emails as spam for some reason; I've unflagged them, so they're available now.  

The "Default Switch" failing because it is two words is a bug that'll be fixed in the next release. You can find a patched build here: https://github.com/hashicorp/packer/issues/7259

Let me know if using that patched build solves your issue.

Morgan Andrew Davis

unread,
Feb 26, 2019, 12:59:31 PM2/26/19
to Packer
I'll give it a shot. Thanks for your help.

Morgan Andrew Davis

unread,
Feb 26, 2019, 3:02:32 PM2/26/19
to Packer
Alright. So it seemed to have something of an affect. I still end up at the dracut shell but it takes longer and there seems to be another step compared to before. I get a: anaconda failed to fetch kickstart from http://172.17.75.145:0/ks.cfg after a while. Any idea why that might be? Maybe that isn't the correct ip address due to the nested virtualization?


On Tuesday, February 26, 2019 at 12:34:28 PM UTC-5, Megan Marsh wrote:

Megan Marsh

unread,
Feb 26, 2019, 5:08:22 PM2/26/19
to packe...@googlegroups.com
That sounds like the behavior I get when the vm isn't actually sharing the network adapters properly. 

I can't remember all the steps I took to fix this, but my hyperv setup is inside a windows 10 vmware vagrant box.  My vagrantfile has the following changes applied: 

    config.vm.provider :vmware_fusion do |v, override
        v.vmx["memsize"] = "6144"
        v.vmx["numvcpus"] = "2"
        v.vmx["ethernet0.virtualDev"] = "vmxnet3"
        v.vmx["RemoteDisplay.vnc.enabled"] = "false"
        v.vmx["RemoteDisplay.vnc.port"] = "5900"
        v.vmx["scsi0.virtualDev"] = "lsisas1068"
        v.vmx["hypervisor.cpuid.v0"] = "FALSE"
        v.vmx["vhv.enable"] = "TRUE"
        v.vmx['vhv.allow'] = "TRUE"   
        v.vmx['mce.enable'] = "TRUE"    
        v.vmx["vhu.enable"] = "TRUE" 
    end


These pass through to the vmx, so if you aren't using vagrant, just update the vmx file with these values directly. 

then inside the vm, I have to launch the control panel and navigate to control panel > network and internet > network and sharing center.  In the left-hand navigation, you'll see "change adapter settings" . Click it. Look for your Ethernet0 adapter. Click it, then click "change settings of this connection"  at the right side of the top navigation bar. Click the sharing tab in the window that pops up, and make sure it's sharing its connection with your hyperV switch. 

Hope this helps. I have to toggle the network share every time I relaunch my hyperv-enabled vm; for some reason the settings don't seem to save quite properly. 
Screen Shot 2019-02-26 at 2.06.22 PM.png


Morgan Andrew Davis

unread,
Feb 27, 2019, 11:18:42 AM2/27/19
to Packer
Ok. So I followed those instructions as best I can. Some of those values aren't present at all in my vmx file. I don't know if I can just add them or not, so I didn't for fear of breaking my machine. I followed the network instructions as well. I still get the failed to fetch kickstart line, but the ip changed to: http://192.168.137.1:0/ks.cfg. Different ip but same problem. Any idea why that might be?
Reply all
Reply to author
Forward
0 new messages