virt: detect Amazon EC2 Nitro instance

Amazon EC2 Nitro hypervisor is technically based on KVM[1], which
systemd-detect-virt identify propely from CPUID. However the lack of
CPUID on aarch64 (A1, T4 instance type) prevents a correct
identification, impacting hostnamectl and systemd-random-seed. Instead
it's possible to identify virtualization from DMI vendor ID.

Prior to this commit:
  # hostnamectl
     Static hostname: n/a
  Transient hostname: ip-10-97-8-12
           Icon name: computer
          Machine ID: 8e3772fbcfa3dd6f330a12ff5df5a63b
             Boot ID: b7b7e2fe0079448db664839df59f9817
    Operating System: Gentoo/Linux
              Kernel: Linux 5.4.69-longterm
        Architecture: arm64

After this commit:
  # hostnamectl
     Static hostname: n/a
  Transient hostname: ip-10-97-8-12
           Icon name: computer-vm
             Chassis: vm
          Machine ID: 8e3772fbcfa3dd6f330a12ff5df5a63b
             Boot ID: bd04da57084e41078f20541101867113
      Virtualization: amazon
    Operating System: Gentoo/Linux
              Kernel: Linux 5.4.69-longterm
        Architecture: arm64

[1] https://aws.amazon.com/ec2/faqs/
This commit is contained in:
Bertrand Jacquin
2021-04-30 09:31:34 -07:00
committed by Noah Meyerhans
parent c068a17f6a
commit b6eca3731d
5 changed files with 15 additions and 4 deletions
+6 -3
View File
@@ -149,6 +149,7 @@ static int detect_vm_dmi(void) {
int id;
} dmi_vendor_table[] = {
{ "KVM", VIRTUALIZATION_KVM },
{ "Amazon EC2", VIRTUALIZATION_AMAZON },
{ "QEMU", VIRTUALIZATION_QEMU },
{ "VMware", VIRTUALIZATION_VMWARE }, /* https://kb.vmware.com/s/article/1009458 */
{ "VMW", VIRTUALIZATION_VMWARE },
@@ -344,8 +345,9 @@ int detect_vm(void) {
/* We have to use the correct order here:
*
* → First, try to detect Oracle Virtualbox, even if it uses KVM, as well as Xen even if it cloaks as Microsoft
* Hyper-V. Attempt to detect uml at this stage also since it runs as a user-process nested inside other VMs.
* → First, try to detect Oracle Virtualbox and Amazon EC2 Nitro, even if they use KVM, as well as Xen even if
* it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also since it runs as a user-process
* nested inside other VMs.
*
* → Second, try to detect from CPUID, this will report KVM for whatever software is used even if info in DMI is
* overwritten.
@@ -353,7 +355,7 @@ int detect_vm(void) {
* → Third, try to detect from DMI. */
dmi = detect_vm_dmi();
if (IN_SET(dmi, VIRTUALIZATION_ORACLE, VIRTUALIZATION_XEN)) {
if (IN_SET(dmi, VIRTUALIZATION_ORACLE, VIRTUALIZATION_XEN, VIRTUALIZATION_AMAZON)) {
r = dmi;
goto finish;
}
@@ -914,6 +916,7 @@ bool has_cpu_with_flag(const char *flag) {
static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {
[VIRTUALIZATION_NONE] = "none",
[VIRTUALIZATION_KVM] = "kvm",
[VIRTUALIZATION_AMAZON] = "amazon",
[VIRTUALIZATION_QEMU] = "qemu",
[VIRTUALIZATION_BOCHS] = "bochs",
[VIRTUALIZATION_XEN] = "xen",
+1
View File
@@ -10,6 +10,7 @@ enum {
VIRTUALIZATION_VM_FIRST,
VIRTUALIZATION_KVM = VIRTUALIZATION_VM_FIRST,
VIRTUALIZATION_AMAZON,
VIRTUALIZATION_QEMU,
VIRTUALIZATION_BOCHS,
VIRTUALIZATION_XEN,