Linux 中是否有可以唯一标识 VM 实例的 UUID 类型的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8722050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:54:20  来源:igfitidea点击:

Is there a UUID type of value in Linux that can uniquely identify an instance of a VM?

linuxvirtual-machinevirtualizationuuidbios

提问by pktCoder

I have an app that runs in Linux. Each one will try to get a UUID from OS and report to a centralized server. I want to make sure all instance are running with globally unique UUID.

我有一个在 Linux 上运行的应用程序。每个人都会尝试从操作系统获取 UUID 并向中央服务器报告。我想确保所有实例都使用全局唯一的 UUID 运行。

If the linux is on bare metal, it can just read the UUID (say, from dmidecode command). But if it's on VM, the UUID (from dmidecode) can potentially be equal since the VM can be copied or moved.

如果 linux 在裸机上,它只能读取 UUID(例如,从 dmidecode 命令)。但如果它在 VM 上,则 UUID(来自 dmidecode)可能相等,因为 VM 可以被复制或移动。

Any ideas?

有任何想法吗?

By the way, for Linux running on physical hardware (not on VM), if user changes memory, NIC etc, will UUID change?

顺便说一句,对于运行在物理硬件(而不是 VM)上的 Linux,如果用户更改内存、网卡等,UUID 会改变吗?

Thanks in advance.

提前致谢。

采纳答案by Evan Powell

If the linux is on bare metal, it can just read the UUID (say, from dmidecode command). But if it's on VM, the UUID (from dmidecode) can potentially be equal since the VM can be copied or moved.

如果 linux 在裸机上,它只能读取 UUID(例如,从 dmidecode 命令)。但如果它在 VM 上,则 UUID(来自 dmidecode)可能相等,因为 VM 可以被复制或移动。

This is not actually the case for VMware products. The BIOS UUID (the one returned by dmidecode) is used as the inventory UUID property of ESX hosts and vCenter, and duplication of the UUID is not allowed on the same system. This means only one machine can have that UUID per vCenter, or per host if there is no vCenter. I've used this UUID as an identifier in the past with success.

VMware 产品实际上并非如此。BIOS UUID(dmidecode 返回的)用作 ESX 主机和 vCenter 的清单 UUID 属性,并且在同一系统上不允许 UUID 重复。这意味着每个 vCenter 只有一台机器可以拥有该 UUID,如果没有 vCenter,则每个主机都可以拥有该 UUID。我过去曾成功使用此 UUID 作为标识符。

To run your program more than once, they'd have to install it in a VM on a separate host, or in an entirely different vCenter. That's an awful lot of resources required just to run more than one of your program, and I think it's well beyond the diminishing returns of license enforcement.

要多次运行您的程序,他们必须将其安装在单独主机上的虚拟机中,或者安装在完全不同的 vCenter 中。仅仅运行一个以上的程序就需要大量的资源,我认为这远远超出了许可证执行的收益递减。

Workstation uses the same data layout as ESX/vCenter, so I expect that it has the same restriction.

Workstation 使用与 ESX/vCenter 相同的数据布局,因此我希望它具有相同的限制。

回答by John Zwinck

If your UUID does not need to be tied to a specific OS installation, just generate one for your specific application using uuid_generateand friends. From what you've written so far, it sounds like this could be a fine solution for your use case.

如果您的 UUID 不需要绑定到特定的操作系统安装,只需使用uuid_generate和朋友为您的特定应用程序生成一个。从您到目前为止所写的内容来看,这听起来可能是您的用例的一个很好的解决方案。

回答by Михаил Кру

Linux

Linux

root@vmtest:~#dmidecode | grep -i uuid | awk '{print }' | tr '[:upper:]' '[:lower:]'

564d7abb-2403-eb3b-2fde-81cd440fc49b

In Esxi

在埃西

cat vmtest.vmx
...
uuid.bios = "56 4d 7a bb 24 03 eb 3b-2f de 81 cd 44 0f c4 9b"
...

SNMP Esxi

SNMP Esxi

iso.3.6.1.4.1.6876.2.1.1.10.<vmID> = = STRING: "564d7abb-2403-eb3b-2fde-81cd440fc49b"