[systemd-devel] [PATCH] detect-virt: detect User-Mode Linux
Ramkumar Ramachandra
artagnon at gmail.com
Mon Jul 15 10:03:13 PDT 2013
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 "User Mode Linux" in /proc/cpuinfo, and say
"uml" when asked.
Cc: Lennart Poettering <lennart at poettering.net>
Signed-off-by: Ramkumar Ramachandra <artagnon at gmail.com>
---
It seems that UM does not have a proper tty system; I force
systemd to use the /dev/console by doing:
$ mv /etc/systemd/system/getty.target.wants/{getty at tty1.service,getty at console.service}
The first step towards supporting UM properly is to detect it, right?
So, here's a small patch. I tested it briefly.
src/shared/virt.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/shared/virt.c b/src/shared/virt.c
index 1c86a3d..25b3016 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -67,6 +67,7 @@ int detect_vm(const char **id) {
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:
@@ -164,6 +165,16 @@ int detect_vm(const char **id) {
}
#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, "User Mode Linux")) {
+ *id = "uml";
+ return 1;
+ }
+
return 0;
}
--
1.8.3.2.736.g869de25
More information about the systemd-devel
mailing list