目的
Hyper-Vで仮想マシンを作ったとして、ハイパーバイザから仮想マシンのIPアドレスがわかれば何かと便利です。
実のところ、以下のコマンドでIPアドレスがわかります。
PS C:\Windows\system32> Get-VMNetworkAdapter Ubuntu21.04-testing
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False Ubuntu21.04-testing Default Switch 00155D00071C {Ok} {172.29.216.146, fe80::215:5df...
PS C:\Windows\system32> Get-VMNetworkAdapter Ubuntu21.04-testing | Select IPAddresses
IPAddresses
-----------
{172.29.216.146, fe80::215:5dff:fe00:71c}
ただ、このコマンドで情報を取得するためには、Linux仮想マシンではHyper-V Key Value Pair daemonなどと呼ばれるDaemonを動かす必要があります。
動いていない状態では以下のようになります。
PS C:\Windows\system32> Get-VMNetworkAdapter U20-testing
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False U20-testing Default Switch 00155D000725 {Ok} {}
今回はいくつかのディストリビューションでこのDaemonのインストール方法を調べてみました。
Ubuntu20.04
パッケージはlinux-cloud-tools-commonのようです。
linux-cloud-tools-generic、linux-cloud-tools-virtualなどをインストールしても依存でインストールされます。
正直どちらが適切かはわからないのですが、今回はlinux-cloud-tools-genericにしてみます。
testing@ubuntu:~$ apt show linux-cloud-tools-generic
Package: linux-cloud-tools-generic
Version: 5.4.0.80.84
Priority: optional
Section: kernel
Source: linux-meta
Origin: Ubuntu
Maintainer: Ubuntu Kernel Team <kernel-team@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 18.4 kB
Provides: linux-cloud-tools
Depends: linux-cloud-tools-5.4.0-80-generic
Download-Size: 2464 B
APT-Sources: http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
Description: Generic Linux kernel cloud tools
This package will always depend on the latest generic kernel cloud tools
available.
N: There is 1 additional record. Please use the '-a' switch to see it
testing@ubuntu:~$ sudo apt install linux-cloud-tools-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
linux-cloud-tools-5.4.0-80 linux-cloud-tools-5.4.0-80-generic linux-cloud-tools-common
The following NEW packages will be installed:
linux-cloud-tools-5.4.0-80 linux-cloud-tools-5.4.0-80-generic linux-cloud-tools-common linux-cloud-tools-generic
0 upgraded, 4 newly installed, 0 to remove and 118 not upgraded.
# 以下略
実行ファイルはhv_kvp_daemonです。
インストールするとsystemdのファイルが作成されるので、startします。
(ただ、今回の環境では後述の失敗があったため、他のコマンドを実施してから以下のコマンドを実施しています。)
testing@ubuntu:~$ sudo systemctl start hv-kvp-daemon
testing@ubuntu:~$ sudo systemctl status hv-kvp-daemon
● hv-kvp-daemon.service - Hyper-V KVP Protocol Daemon
Loaded: loaded (/etc/systemd/system/hv-kvp-daemon.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-08-15 10:55:24 UTC; 4min 4s ago
Main PID: 2808 (hv_kvp_daemon)
Tasks: 1 (limit: 2199)
Memory: 1.4M
CGroup: /system.slice/hv-kvp-daemon.service
└─2808 /usr/lib/linux-tools/5.4.0-80-generic/hv_kvp_daemon -n
Aug 15 10:55:24 ubuntu systemd[1]: Started Hyper-V KVP Protocol Daemon.
Aug 15 10:55:24 ubuntu KVP[2808]: KVP starting; pid is:2808
Aug 15 10:55:24 ubuntu KVP[2808]: KVP LIC Version: 3.1
Ubuntuでstartできないとき
インストール後、systemctl start
に失敗することがありました。
ありがちな原因としては以下が考えられます。
- 依存するDeviceの起動に失敗する。
- Kernel本体とバージョンが異なる。
依存するDeviceの起動に失敗する。
実際のところ、今回はこれが発生したため上に記載した手順だけではDaemonが起動できませんでした。
以下のように表示されます。
testing@ubuntu:~$ sudo systemctl start hv-kvp-daemon
A dependency job for hv-kvp-daemon.service failed. See 'journalctl -xe' for details.
ログを確認すると、sys-devices-virtual-misc-vmbus\x21hv_kvp.device: Job sys-devices-virtual-misc-vmbus\x21hv_kvp.device/start timed out.
とあります。
Aug 15 10:44:02 ubuntu systemd[1]: sys-devices-virtual-misc-vmbus\x21hv_kvp.device: Job sys-devices-virtual-misc-vmbus\x21hv_kvp.device/start timed out.
Aug 15 10:44:02 ubuntu systemd[1]: Timed out waiting for device /sys/devices/virtual/misc/vmbus!hv_kvp.
Aug 15 10:44:02 ubuntu systemd[1]: Dependency failed for Hyper-V KVP Protocol Daemon.
Aug 15 10:44:02 ubuntu systemd[1]: hv-kvp-daemon.service: Job hv-kvp-daemon.service/start failed with result 'dependency'.
Aug 15 10:44:02 ubuntu systemd[1]: sys-devices-virtual-misc-vmbus\x21hv_kvp.device: Job sys-devices-virtual-misc-vmbus\x21hv_kvp.device/start failed with result 'timeout'.
ここから、どうやら依存するsys-devices-virtual-misc-vmbus\x21hv_kvp.device
の起動に失敗しているようです。
この場合は、インストール時に追加されたudev ruleを評価するとよいみたいです。
testing@ubuntu:~$ sudo udevadm trigger
testing@ubuntu:~$ dmesg
# 略
[ 2119.953043] hv_utils: VSS: userspace daemon ver. 129 connected
[ 2119.953766] hv_utils: KVP IC version 4.0
[ 2119.953773] hv_utils: KVP IC version 4.0
[ 2119.953773] hv_utils: KVP IC version 4.0
# 略
testing@ubuntu:~$ sudo systemctl start hv-kvp-daemon
仮想マシンを再起動しても同様に解決できます。
Kernel本体とバージョンが異なる。
今回は試しに古いバージョンのlinux-cloud-tools-commonをインストールしてみました。
testing@ubuntu:~$ sudo apt install linux-cloud-tools-common=5.4.0-77.86
サービスは開始できますが、ステータスを確認すると失敗しています。
testing@ubuntu:~$ sudo systemctl start hv-kvp-daemon
testing@ubuntu:~$ sudo systemctl status hv-kvp-daemon
● hv-kvp-daemon.service - Hyper-V KVP Protocol Daemon
Loaded: loaded (/lib/systemd/system/hv-kvp-daemon.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2021-08-15 11:36:18 UTC; 3s ago
Process: 3224 ExecStart=/usr/sbin/hv_kvp_daemon -n (code=exited, status=2)
Main PID: 3224 (code=exited, status=2)
Aug 15 11:36:18 ubuntu systemd[1]: Started Hyper-V KVP Protocol Daemon.
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: WARNING: hv_kvp_daemon not found for kernel 5.4.0-80
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: You may need to install the following packages for this specific kernel:
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: linux-tools-5.4.0-80-generic
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: linux-cloud-tools-5.4.0-80-generic
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: You may also want to install one of the following packages to keep up to date:
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: linux-tools-generic
Aug 15 11:36:18 ubuntu hv_kvp_daemon[3224]: linux-cloud-tools-generic
Aug 15 11:36:18 ubuntu systemd[1]: hv-kvp-daemon.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 15 11:36:18 ubuntu systemd[1]: hv-kvp-daemon.service: Failed with result 'exit-code'.
systemctl status
の結果からわかるように、Kernel本体と同じバージョンでなければDaemonを起動できないようです。
対策としては、適切なバージョンをインストールするかKernel本体をバージョンアップします。
CentOS8 (Stream)
(公式のISOを使ってCentOSをインストールしたところ、Minimal Installでもhypervkvpdがインストールされました。
以下はパッケージをeraseし、再度installすることで確認しています。)
パッケージはhypervkvpdのようです。
hyperv-daemonsをインストールしても依存でインストールされます。
[testing@localhost ~]$ dnf info hypervkvpd
Last metadata expiration check: 0:51:06 ago on Fri 13 Aug 2021 12:53:51 PM EDT.
Available Packages
Name : hypervkvpd
Version : 0
Release : 0.30.20180415git.el8
Architecture : x86_64
Size : 28 k
Source : hyperv-daemons-0-0.30.20180415git.el8.src.rpm
Repository : appstream
Summary : Hyper-V key value pair (KVP) daemon
URL : http://www.kernel.org
License : GPLv2
Description : Hypervkvpd is an implementation of Hyper-V key value pair (KVP)
: functionality for Linux. The daemon first registers with the
: kernel driver. After this is done it collects information
: requested by Windows Host about the Linux Guest. It also supports
: IP injection functionality on the Guest.
[testing@localhost ~]$ sudo dnf install hyperv-daemons
Last metadata expiration check: 0:51:03 ago on Fri 13 Aug 2021 12:56:13 PM EDT.
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
Installing:
hyperv-daemons x86_64 0-0.30.20180415git.el8 appstream 12 k
Installing dependencies:
hyperv-daemons-license noarch 0-0.30.20180415git.el8 appstream 19 k
hypervfcopyd x86_64 0-0.30.20180415git.el8 appstream 19 k
hypervkvpd x86_64 0-0.30.20180415git.el8 appstream 28 k
hypervvssd x86_64 0-0.30.20180415git.el8 appstream 20 k
Transaction Summary
========================================================================================================================
Install 5 Packages
Total download size: 98 k
# 以下略
実行ファイルはhypervkvpdです。
インストールするとsystemdのファイルが作成されるので、startします。
[testing@localhost ~]$ sudo systemctl start hypervkvpd
[testing@localhost ~]$ sudo systemctl status hypervkvpd
● hypervkvpd.service - Hyper-V KVP daemon
Loaded: loaded (/usr/lib/systemd/system/hypervkvpd.service; static; vendor preset: enabled)
Active: active (running) since Fri 2021-08-13 13:50:30 EDT; 6s ago
Main PID: 2256 (hypervkvpd)
Tasks: 1 (limit: 10966)
Memory: 304.0K
CGroup: /system.slice/hypervkvpd.service
└─2256 /usr/sbin/hypervkvpd -n
Aug 13 13:50:30 localhost.localdomain systemd[1]: Started Hyper-V KVP daemon.
Aug 13 13:50:30 localhost.localdomain KVP[2256]: KVP starting; pid is:2256
Aug 13 13:50:30 localhost.localdomain KVP[2256]: KVP LIC Version: 3.1
Fedora34
CentOSと同様で、パッケージはhypervkvpdのようです。
[testing@fedora ~]$ sudo dnf install hyperv-daemons
Last metadata expiration check: 0:07:31 ago on Sun 15 Aug 2021 01:05:20 AM JST.
Dependencies resolved.
================================================================================================
Package Architecture Version Repository Size
================================================================================================
Installing:
hyperv-daemons x86_64 0-0.34.20190303git.fc34 fedora 7.4 k
Installing dependencies:
hyperv-daemons-license noarch 0-0.34.20190303git.fc34 fedora 15 k
hypervfcopyd x86_64 0-0.34.20190303git.fc34 fedora 14 k
hypervkvpd x86_64 0-0.34.20190303git.fc34 fedora 23 k
hypervvssd x86_64 0-0.34.20190303git.fc34 fedora 16 k
Transaction Summary
================================================================================================
Install 5 Packages
Total download size: 75 k
# 以下略
[testing@fedora ~]$ sudo systemctl start hypervkvpd