Virtual or physical?

Charly's Column – VM Detection

Article from Issue 253/2021
Author(s):

To write low-level scripts, as an admin, you need to know whether you are currently on a physical or a virtual machine. Charly finds out with a couple of clever hacks.

Of the systems I work on, about 90 percent are virtualized and 10 percent are legacy hardware servers. For many jobs, this makes no difference, but when I write scripts that call or change hardware-related functions, I need this information.

If I have root privileges on the system and am also allowed to retroactively install software, the problem can be solved very quickly. I install either Facter [1] or virt-what [2]. Facter provides extensive information about the system's hardware, much like lshw, and is actually overkill for answering the "virtual or not" question. Calling facter virtual returns the virtualization platform as the answer, such as vmware or kvm. The same result is returned by a call to virt-what. If I don't need the power of Facter elsewhere, I prefer the leaner virt-what.

If I have root privileges but am not allowed to install software (for example, because of restricted repositories), there is another possibility. The command

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • The sys admin's daily grind: lshw

    In order to avoid complaints from his children, Charly prefers to use lshw instead of a screwdriver to analyze his home firewall PC's hardware details.

  • Charly's Column: Nmon

    Nmon monitors system information. You can use the Nmon’s capture mode to output data to a file, then extract the values you need with a script.

  • Show Me!

    There is nothing that admins hate more than unnecessary typing at the console. That's why Charly's clever alternative exa replaces the classic, but ancient, ls.

  • Virtual Performance

    Virtual performance tuning is a lot like ordinary performance tuning – but not exactly.

  • Charly's Column

    Parallel SSH is the name of an easy-to-configure tool that our resident sys admin, Charly, now routinely deploys whenever he needs to launch the same programs, copy the same files, or kill the same processes simultaneously on multiple computers.

comments powered by Disqus