HyperV added

Only enabled so far for Archlinux and CentOS. Also, needed to change file endings on ALL THE THINGS. Might or might not show up.
This commit is contained in:
Greg Hellings
2023-08-25 11:51:45 -05:00
parent 7f2ba562a4
commit e2f62a80bd
8 changed files with 83 additions and 20 deletions
+1
View File
@@ -0,0 +1 @@
* text eol=lf
+45 -15
View File
@@ -1,17 +1,47 @@
# Building on Windows
1. Install Cygwin with packages; I install to C:\Cygwin64 as per defaults
* python39
* python39-setuptools
* python39-cryptography
* python39-pip
* openssl-devel
* libffi-devel
* python3-devel
* zlib
* zlib-devel
1. Inside of Cygwin
1. Create a venv *with system packages* enabled
1. Install windows/ansible-requirements.txt into the venv
1. Update the path in ansible/hyperv-wrapper.py to point to your VENV
1. Execute pyinstaller --onefile ansible/hyperv-wrapper.py
1. Be sure that Hyper-V is installed and enabled on your system
1. Download and install packer.exe to your system, and add the folder it is in to your user's PATH environment variable
1. Download the [Windows ADK](https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install) being sure to select
at the least "Deployment Tools" from the feature set.
1. To see more details, including a walkthrough, check [this web page](https://www.makeuseof.com/windows-iso-folder-command-prompt/)
1. Be sure to add the install path for the Oscdimg tool to your Windows PATH.
1. On my system, that path is "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
1. Open PowerShell (on my system I had to run as administrator), and ensure that you have access to python
1. If you type "python" at the prompt and do not have it installed, it should prompt you to install from the Store
1. Do not install the version downloaded from the Internet unless you know what you're doing
1. Create a venv `python -m venv .venv`
1. Activate it `.\.venv\scripts\Activate.ps1`
1. Install the packages in requirements-windows.txt
1. Try a build
1. You can execute directly with the `packer` executable, if you want
1. If you want to wrap up standard options, or build multiple versions/distros at once, use the `build.xsh` file
1. `xonsh build.xsh -d <distro> -b hyperv-iso.x86_64 -v`
1. You can substitute out any of the options with `-a` to build "all" targets that match
### Troubleshooting
Personally, I had issues where the Hyper-V networks were untrusted by Windows. This can manifest itself as the VMs that
need to download Shell files from the Packer http server (NixOS, Archlinux, and others) being unable to reach the
HTTP server on the host. To rectify this:
1. From the Windows Start/Search type "Firewall"
1. Click "Allow and App Through The Firewall"
1. Click "Change Settings"
1. Scroll all the way down to where you find the entries for the packer-hyperv plugin
1. Ensure that all such plugin versions have the box on the left and BOTH boxes on the right checked
1. Click "Ok"
1. Try running your install again.
I also had an issue with my VMs getting a different IP address each time they booted, which means that the IP detected
during install is not the same one during provisioning. In order to address this issue I had to setup a static IP
address for the MAC address "00:00:de:ad:be:ef" in my network DHCP server and tell my machines to use external networking
to reach it.
1. Open Hyper-V Manager
1. In the right hand side, click "Virtual Switch Manager..."
1. Select the `packer-x86_64` switch
1. Set connection type to 'External'
1. In your DHCP server, assign a static IP address to MAC address "00:00:de:ad:be:ef"
1. Personally, I use dnsmasq and my subnet is 10.42.2.1/16 for DHCP, so the appropriate config line is `dhcp-host=00:00:de:ad:be:ef,10.42.2.254`
1. The actual IP address you assign is unimportant, and if you need to spoof a different Mac address, edit the file `sources/hyperv-iso.pkr.hcl`
@@ -36,3 +36,16 @@ groupadd vagrant
useradd vagrant -g vagrant -G wheel -m
[ -d /home/vagrant ] || exit 1
echo "vagrant:vagrant" | chpasswd
# Do host-specific things
virt="$(systemd-detect-virt)"
# Values I've found so far
# "microsoft" == Hyper-V
# "oracle" == VirtualBox
# "KVM" == KVM/Qemu
if [ "${virt}" == "microsoft" ]; then
pacman -S --noconfirm hyperv
systemctl enable hv_fcopy_daemon
systemctl enable hv_kvp_daemon
systemctl enable hv_vss_daemon
fi
+8
View File
@@ -53,5 +53,13 @@ EOF
sed -i -E -e 's/^.*UseDNS.*$/UseDNS no/'
echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/sshd_config
virt="$(systemd-detect-virt)"
if [ "${virt}" == "microsoft" ]; then
yum install -y hyperv-daemons
systemctl enable hpervfcopyd
systemctl enable hypervkvpd
systemctl enable hypervvssd
fi
%end
+2
View File
@@ -5,3 +5,5 @@
provider: virtualbox-iso
- arch: x86_64
provider: vmware-iso
- arch: x86_64
provider: hyperv-iso
+1 -1
View File
@@ -4,7 +4,7 @@ from pathlib import Path
from yaml import load, Loader
BASE = Path(__file__).parent.parent
BASE = Path(__file__).parent.parent.resolve()
class Support:
+2 -2
View File
@@ -1,7 +1,7 @@
source "hyperv-iso" "x86_64" {
iso_url = var.iso.url
iso_checksum = var.iso.checksum
output_directory = "output/libvirt/${local.name}"
output_directory = "output/hyperv/${local.name}"
boot_command = var.boot_command
shutdown_command = var.shutdown_command
@@ -11,7 +11,7 @@ source "hyperv-iso" "x86_64" {
ssh_password = local.ssh.password
ssh_handshake_attempts = local.ssh.handshake_attempts
ssh_private_key_file = local.ssh.private_key_file
vm_name = "packer-${local.name}"
disk_size = "${local.disk_size}000"
cpus = local.cpus
+11 -2
View File
@@ -15,6 +15,10 @@ def get_vagrant_provider(provider):
return "virtualbox"
elif provider.startswith("vmware"):
return "vmware"
elif provider.startswith("hyperv"):
return "hyperv"
else:
return provider
def get_providers():
@@ -56,9 +60,14 @@ def main():
#$RAISE_SUBPROC_ERROR = True
for box in g`output/**/*.box`:
p = pathlib.Path(box)
sed -e f's#@@BOX@@#file:///home/greg/src/vms/vms/{box}#' -e f's/@@BOX_NAME@@/{p.name}/' Vagrantfile.in > Vagrantfile
with open("Vagrantfile.in", "r") as fr:
content = fr.read()
content = content.replace("@@BOX@@", f"file:///home/greg/src/vms/vms/{box}")
content = content.replace("@@BOX_NAME@@", p.name)
with open("Vagrantfile", "w") as fw:
fw.write(content)
vagrant box add @(box) --name @(p.name)
if str(p.parent.name) in ["virtualbox", "libvirt", "vmware"]:
if str(p.parent.name) in ["virtualbox", "libvirt", "vmware", "hyperv"]:
vagrant up --provider @(p.parent.name)
else:
print(f"Now whatcha wanna go and do that for? {box}")