[systemd-devel] [PATCH] detect-virt: detect User-Mode Linux

Lennart Poettering lennart at poettering.net
Mon Jul 15 14:13:32 PDT 2013


On Mon, 15.07.13 22:33, Ramkumar Ramachandra (artagnon at gmail.com) wrote:

> 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.

Looks pretty good! Just one change request: I am a bit afraid that the
check is a bit too broad. I'd really prefer if we could at least check
that this occurs on a line of its own. Maybe look for "\nvendor_id",
then skip all spaces from there, and check if this is followed by ": User
Mode Linux\n"? That should be a pretty safe check I figure, since
newlines are used as field separators in the file and it appears
unlikely that they'd appear unescaped in any of the other fields... And
it would still grant the kernel folks the right to add more inner spaces
for alignment if they wish...

(also, probably needs some minor man page additions)

Thanks!

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list