kvm虚拟机中如何知道自己运行在哪台物理机上

859 阅读1分钟

kvm虚拟机中如何知道自己运行在哪台物理机上

方法

  • 在虚拟机xml中加入smbios配置信息
  <os>
    <smbios mode='sysinfo'/>
    ...
  </os>
  <sysinfo type='smbios'>
    <baseBoard>
      <entry name='asset'>10.145.xx.xx</entry>
    </baseBoard>
  </sysinfo>
  • 然后使用xml创建并运行虚拟机
  • 进入虚拟机内部通过命令dmidecode -t 2进行获取
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 3.2.1 present.
# SMBIOS implementations newer than version 3.0 are not
# fully supported by this version of dmidecode.

Handle 0x0002, DMI type 2, 15 bytes
Base Board Information
	Manufacturer: *****
	Product Name: *****
	Version: *****
	Serial Number: *****
	Asset Tag: 10.145.xx.xx
	Features:
		Board is a hosting board
		Board is replaceable
	Location In Chassis: NULL
	Chassis Handle: 0x0003
	Type: Motherboard
	Contained Object Handles: 0

说明

  • libvirt虚拟机xml官方文档
  • 该方式是通过打标签的方式将宿主机的ip地址注入到smbios中的Base Board Information上了,虚拟机内部通过dmidecode -t 2获取
  • 也可以注入到Chassis Information上,虚拟机内部通过dmidecode -t 3获取