-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix HyperV XML: System.Xml.XmlElement & The minimum amount #13691
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
Conversation
f847001
to
ecf2a26
Compare
ERROR: > New-VagrantVMXML : Cannot convert the "System.Xml.XmlElement" value of type "System.Xml.XmlElement" to type "System.Int32 Valid XML config, which was causing the crash: ```xml <memory> <bank> <dynamic_memory_enabled type="bool">[...]</dynamic_memory_enabled> <limit type="integer">[...]</limit> <reservation type="integer">[...]</reservation> <size type="integer">[...]</size> </bank> </memory> ``` Invalid XML config, what was passing (but would then fail later as `dynamic_memory_enabled` is missing): ```xml <memory> <Bank>2048</Bank> </memory> ``` - - - `$memory` -> `$memoryNode` There is another variable `$Memory`, I believe this is the reason why it was crashing. - - - `<Bank>` -> `<bank>` (lowercase b) REF: https://github.com/mwrock/packer-templates/blob/a96114e3b0918f19cbb6907b797cdd26749cfd11/hyper-v-output/Virtual%20Machines/vm.XML#L397
OS VersionPS C:\> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows Server 2019 Standard Evaluation
OS Version: 10.0.17763 N/A Build 17763
PS C:\> PreparationPS C:\Users\root\Desktop> & 'C:\Program Files\Vagrant\bin\vagrant.exe' box list
There are no installed boxes! Use `vagrant box add` to add some.
PS C:\Users\root\Desktop>
PS C:\Users\root\Desktop> & 'C:\Program Files\Vagrant\bin\vagrant.exe' box add test .\kali-linux-rolling-hyperv-amd64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'test' (v0) for provider:
box: Unpacking necessary files from: file://C:/Users/root/Desktop/kali-linux-rolling-hyperv-amd64.box
box:
==> box: Successfully added box 'test' (v0) for ''!
PS C:\Users\root\Desktop>
PS C:\Users\root\Desktop> mkdir -f test
Directory: C:\Users\root\Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/10/2025 12:02 AM test
PS C:\Users\root\Desktop>
PS C:\Users\root\Desktop> cd .\test\
PS C:\Users\root\Desktop\test>
PS C:\Users\root\Desktop\test> & 'C:\Program Files\Vagrant\bin\vagrant.exe' init -f -m test
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
PS C:\Users\root\Desktop\test> Error/Crash 1PS C:\Users\root\Desktop\test> & 'C:\Program Files\Vagrant\bin\vagrant.exe' up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.
Script: import_vm.ps1
Error:
Cannot convert the "System.Xml.XmlElement" value of type "System.Xml.XmlElement" to type "System.Int32".
PS C:\Users\root\Desktop\test> Configs/Environment
|
Error/Crash 2
|
ERROR: > Invalid startup memory amount assigned for '[...]'. The minimum amount of memory you can assign to this virtual machine is '[...]'. Happens for: Memory, MaxMemory, CPUCount
Working!PS C:\Users\root\Desktop\test> notepad C:\Program Files\Vagrant\embedded\gems\gems\vagrant-2.4.7\plugins\providers\hyperv\scripts\utils\VagrantVM\VagrantVM.psm1^C
PS C:\Users\root\Desktop\test>
PS C:\Users\root\Desktop\test> & 'C:\Program Files\Vagrant\bin\vagrant.exe' up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
default: Setting VM Enhanced session transport type to disabled/default (VMBus)
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: 192.168.100.56
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 192.168.100.56:22
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Preparing SMB shared folders...
default: You will be asked for the username and password to use for the SMB
default: folders shortly. Please use the proper username/password of your
default: account.
default:
default: Username (user[@domain]): root
default: Password (will be hidden):
Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
==> default: Mounting SMB shared folders...
default: C:/Users/root/Desktop/test => /vagrant
PS C:\Users\root\Desktop\test> & 'C:\Program Files\Vagrant\bin\vagrant.exe' ssh
Linux kali 6.12.33+kali-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.12.33-1kali1 (2025-06-25) x86_64
The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
┌──(vagrant㉿kali)-[~]
└─$ |
Hey @taru-garg-hashicorp I tired using the link in the first comment. In short. Should now be done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the contribution! These changes look good!
You are welcome @taru-garg-hashicorp . Thanks for the review! |
ERROR:
Valid XML config, which was causing the crash:
Invalid XML config, what was passing (but would then fail later as
dynamic_memory_enabled
is missing):$memory
->$memoryNode
There is another variable
$Memory
, so renamed to make it clear.<Bank>
-><bank>
(lowercase b)REF: https://github.com/mwrock/packer-templates/blob/a96114e3b0918f19cbb6907b797cdd26749cfd11/hyper-v-output/Virtual%20Machines/vm.XML#L397