In a User-Mode Linux session:
$ systemd-detect-virt
none
Although it is possible to reliably detect virtualization:
$ cat /proc/cpuinfo
processor : 0
vendor_id : User Mode Linux
model name : UML
mode : skas
host : Linux kytes 3.11.0-rc1-00009-ge5fd680 (...)
bogomips : 7007.43
So, grep for the string "\nvendor_id\t: User Mode Linux\n" in
/proc/cpuinfo, and say "uml" when asked.
<varname>microsoft</varname>,
<varname>oracle</varname>, <varname>xen</varname>,
<varname>bochs</varname>, <varname>chroot</varname>,
+ <varname>uml</varname>,
<varname>openvz</varname>, <varname>lxc</varname>,
<varname>lxc-libvirt</varname>,
<varname>systemd-nspawn</varname>.</para>
<varname>xen</varname>,
<varname>bochs</varname>,
<varname>chroot</varname>,
+ <varname>uml</varname>,
<varname>openvz</varname>,
<varname>lxc</varname>,
<varname>lxc-libvirt</varname>,
const char *j, *k;
bool hypervisor;
_cleanup_free_ char *hvtype = NULL;
+ _cleanup_free_ char *cpuinfo_contents = NULL;
int r;
/* Try high-level hypervisor sysfs file first:
}
#endif
+
+ /* Detect User-Mode Linux by reading /proc/cpuinfo */
+ r = read_full_file("/proc/cpuinfo", &cpuinfo_contents, NULL);
+ if (r < 0)
+ return r;
+ if (strstr(cpuinfo_contents, "\nvendor_id\t: User Mode Linux\n")) {
+ *id = "uml";
+ return 1;
+ }
+
return 0;
}