skip to Main Content

I’m trying to configure a Debian 11 Virtual Machine (Gen 2) Network in Hyper-V with a PowerShell Script. It uses Linux Integration Services (LIS) and Hyper-V Daemon to allow the Virtual Machine communicate with Hyper-V.

What I have done and general specifications
  • I make sure to have installed both and have Key-Value Pair Exchange Enabled.
  • Install init-system-helpers libc6 lsb-base packages installed in my Debian.
  • The script provided only runs on Windows PowerShell. PowerShell 7 don’t have .GetRelated() method.
  • I’m running Hyper-V on Windows 11
Steps to reproduce the Error
  1. Run Get-VMNetworkAdapter -VMName debian-vm | Set-VMNetworkConfiguration -IPAddress 192.168.1.23 -Subnet 255.255.255.0 -DNSServer 8.8.8.8 -DefaultGateway 192.168.1.1
  • I get a response with the same info: Msvm_Error Value --> 15090: failed to modify resources
  1. I inspect the VM: tail /var/log/syslog and it showed the following error…
  • test KVP: Failed to execute cmd '/usr/libexec/hypervkvpd/hv_set_ifconfig /var/lib/hyperv/ifcfg-eth0'; error: 2 No such file or directory
    • I look info on blogs and some said sometimes the file hv_set_ifconfig was in other location, but I search in the whole system and there was no such as file anywhere.

I appreciate any help with this. Below I leave the function I use when trying to config the IP. Thank you!

Function Set-VMNetworkConfiguration {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true,
                   Position=1,
                   ParameterSetName='DHCP',
                   ValueFromPipeline=$true)]
        [Parameter(Mandatory=$true,
                   Position=0,
                   ParameterSetName='Static',
                   ValueFromPipeline=$true)]
        [Microsoft.HyperV.PowerShell.VMNetworkAdapter]$NetworkAdapter,
  
        [Parameter(Mandatory=$true,
                   Position=1,
                   ParameterSetName='Static')]
        [String[]]$IPAddress=@(),
  
        [Parameter(Mandatory=$false,
                   Position=2,
                   ParameterSetName='Static')]
        [String[]]$Subnet=@(),
  
        [Parameter(Mandatory=$false,
                   Position=3,
                   ParameterSetName='Static')]
        [String[]]$DefaultGateway = @(),
  
        [Parameter(Mandatory=$false,
                   Position=4,
                   ParameterSetName='Static')]
        [String[]]$DNSServer = @(),
  
        [Parameter(Mandatory=$false,
                   Position=0,
                   ParameterSetName='DHCP')]
        [Switch]$Dhcp
    )
  
    $VM = Get-WmiObject -Namespace 'rootvirtualizationv2' -Class 'Msvm_ComputerSystem' | Where-Object { $_.ElementName -eq $NetworkAdapter.VMName } 
    $VMSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' }    
    $VMNetAdapters = $VMSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData') 
  
    $NetworkSettings = @()
    foreach ($NetAdapter in $VMNetAdapters) {
        if ($NetAdapter.Address -eq $NetworkAdapter.MacAddress) {
            $NetworkSettings = $NetworkSettings + $NetAdapter.GetRelated("Msvm_GuestNetworkAdapterConfiguration")
        }
    }
  
    $NetworkSettings[0].IPAddresses = $IPAddress
    $NetworkSettings[0].Subnets = $Subnet
    $NetworkSettings[0].DefaultGateways = $DefaultGateway
    $NetworkSettings[0].DNSServers = $DNSServer
    $NetworkSettings[0].ProtocolIFType = 4096
  
    if ($dhcp) {
        $NetworkSettings[0].DHCPEnabled = $true
    } else {
        $NetworkSettings[0].DHCPEnabled = $false
    }
  
    $Service = Get-WmiObject -Class "Msvm_VirtualSystemManagementService" -Namespace "rootvirtualizationv2"
    $setIP = $Service.SetGuestNetworkAdapterConfiguration($VM, $NetworkSettings[0].GetText(1))
  
    if ($setip.ReturnValue -eq 4096) {
        $job=[WMI]$setip.job 
  
        while ($job.JobState -eq 3 -or $job.JobState -eq 4) {
            start-sleep 1
            $job=[WMI]$setip.job
        }
  
        if ($job.JobState -eq 7) {
            write-host "Success"
        }
        else {
            $job.GetError()
        }
    } elseif($setip.ReturnValue -eq 0) {
        Write-Host "Success"
    }
}

2

Answers


  1. I believe this is the same problem that I experienced on Ubuntu 22.04. Everything was working fine on earlier versions of Ubuntu. This was my fix.

    sudo ln -s /usr/sbin /usr/libexec/hypervkvpd

    Login or Signup to reply.
  2. Issue is present on U20, I resolved by running the following commands as root:

    # mkdir /usr/libexec/hypervkvpd/
    # ln -s /usr/sbin/hv_get_dhcp_info /usr/libexec/hypervkvpd/hv_get_dhcp_info
    # ln -s /usr/sbin/hv_get_dns_info /usr/libexec/hypervkvpd/hv_get_dns_inf
    

    Full system details for my U20 build are as follows:

    # cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.04
    DISTRIB_CODENAME=focal
    DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
    # uname -a
    Linux <hostname> 5.15.0-1022-azure #27~20.04.1-Ubuntu SMP Mon Oct 17 02:03:50 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
    

    Referenced the following bug report to identify the issue – https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1766857

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search