Skip to content

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

Merged
merged 2 commits into from
Jul 18, 2025

Conversation

g0tmi1k
Copy link
Contributor

@g0tmi1k g0tmi1k commented Jul 9, 2025

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:

  <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):

  <memory>
    <Bank>2048</Bank>
  </memory>

$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

@g0tmi1k g0tmi1k requested a review from a team as a code owner July 9, 2025 22:30
@g0tmi1k g0tmi1k force-pushed the memory-bank branch 2 times, most recently from f847001 to ecf2a26 Compare July 9, 2025 23:10
Copy link

hashicorp-cla-app bot commented Jul 9, 2025

CLA assistant check
All committers have signed the CLA.

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
@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 10, 2025

OS Version

PS 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:\>

Preparation

PS 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 1

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...
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

PS C:\Users\root\Desktop\test> Get-ChildItem -Recurse  ~/.vagrant.d/boxes/test/


    Directory: C:\Users\root\.vagrant.d\boxes\test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/10/2025   3:54 AM                0


    Directory: C:\Users\root\.vagrant.d\boxes\test\0


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/10/2025   3:54 AM                hyperv


    Directory: C:\Users\root\.vagrant.d\boxes\test\0\hyperv


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/10/2025   3:54 AM                Virtual Hard Disks
d-----        7/10/2025   3:54 AM                Virtual Machines
-a----        7/10/2025   3:54 AM            232 info.json
-a----        7/10/2025   3:54 AM             91 metadata.json
-a----        7/10/2025   3:53 AM            311 Vagrantfile


    Directory: C:\Users\root\.vagrant.d\boxes\test\0\hyperv\Virtual Hard Disks


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2025   3:54 AM    17641242624 kali-linux-rolling-hyperv-amd64.vhdx


    Directory: C:\Users\root\.vagrant.d\boxes\test\0\hyperv\Virtual Machines


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/10/2025   3:54 AM           1214 box.xml


PS C:\Users\root\Desktop\test>
PS C:\Users\root\Desktop\test> cat 'C:\Users\root\.vagrant.d\boxes\test\0\hyperv\Virtual Machines\box.xml'
<?xml version="1.0"?>
<configuration>
  <properties>
    <subtype type="integer">1</subtype>
    <name type="string">kali-linux-rolling-hyperv-amd64</name>
  </properties>
  <settings>
    <processors>
      <count type="integer">2</count>
    </processors>
    <memory>
      <bank>
        <dynamic_memory_enabled type="bool">False</dynamic_memory_enabled>
        <limit type="integer">1048576</limit>
        <reservation type="integer">512</reservation>
        <size type="integer">2048</size>
      </bank>
    </memory>
  </settings>
  <AltSwitchName type="string">Default Switch</AltSwitchName>
  <boot>
    <device0 type="string">Optical</device0>
  </boot>
  <secure_boot_enabled type="bool">False</secure_boot_enabled>
  <secure_boot_template type="string">MicrosoftWindows</secure_boot_template>
  <tpm_enabled type="bool">True</tpm_enabled>
  <notes type="string">
  </notes>
  <vm-controllers>
    <scsi ChannelInstanceGuid="x">
      <controller0>
        <drive0>
          <pathname type="string">..\Virtual Hard Disks\kali-linux-rolling-hyperv-amd64.vhdx</pathname>
          <type type="string">VHD</type>
        </drive0>
      </controller0>
    </scsi>
  </vm-controllers>
</configuration>
PS C:\Users\root\Desktop\test>

@g0tmi1k g0tmi1k changed the title Fix HyperV XML: Cant convert System.Xml.XmlElement Fix HyperV XML: System.Xml.XmlElement & The minimum amount Jul 10, 2025
@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 10, 2025

Error/Crash 2

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
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...
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:

Failed to modify device 'Memory'.

Invalid startup memory amount assigned for 'kali-linux-rolling-hyperv-amd64'.

'kali-linux-rolling-hyperv-amd64' failed to modify device 'Memory'. (Virtual machine ID 1E3B2EE9-8290-4F63-A21B-7B3C2741BD2E)

Invalid startup memory amount assigned for 'kali-linux-rolling-hyperv-amd64'. The minimum amount of memory you can assign to this virtual machine is '32' MB. (Virtual machine ID 1E3B2EE9-8290-4F63-A21B-7B3C2741BD2E)
PS C:\Users\root\Desktop\test>

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
@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 10, 2025

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)-[~]
└─$

@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 10, 2025

I agree'd to the CLA, but its not picking it up for some reason?

image

@taru-garg-hashicorp
Copy link
Contributor

I agree'd to the CLA, but its not picking it up for some reason?

image

Could you visit the CLA link once again? I am guessing there might have been some issue in the service

@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 11, 2025

Could you visit the CLA link once again? I am guessing there might have been some issue in the service

Hey @taru-garg-hashicorp
Thanks for getting back to me.

I tired using the link in the first comment.
Clicking on recheck just took be straight back to GitHub.
If I used the link in the GitHub actions (three dots -> view details), then it works.

In short. Should now be done!

Copy link
Contributor

@taru-garg-hashicorp taru-garg-hashicorp left a 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!

@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Jul 15, 2025

You are welcome @taru-garg-hashicorp .

Thanks for the review!

@taru-garg-hashicorp taru-garg-hashicorp merged commit d3a14ba into hashicorp:main Jul 18, 2025
10 checks passed
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.

2 participants