How to detect Virtualization using Sys::Detect::Virtualization Perl script?

Updated on September 1, 2017

Off late, I started working on a Cloud security project where I need to detect the type of hypervisor that runs a virtual machine. For experiment, I had setup test environments based on OpenStack cloud platform with KVM as the underlying hypervisor and also standalone KVM with QEMU, Xen and VirtualBox. The idea is to start a virtual machine on top of these environments and see if I can detect the virtualization technology that powers the current VM. Thankfully, it’s super easy.

Note: There are few native Linux commands such as dmesg (analyzing the system log), lshw, dmidecode etc… that helps you to accomplish this job – which I’ll be covering in a separate tutorial.

virtualization detection linux

Here, I’m going to use “Sys::Detect::Virtualization” perl script, which you can download from this link.

How to detect Virtualization type from a Virtual Machine (VM)

Once you have “Sys::Detect::Virtualization” script downloaded from the above link, copy it to a virtual machine and install it as shown below:

[root@vm ]# tar xvfz Sys-Detect-Virtualization-0.107.tar.gz
[root@vm ]# cd Sys-Detect-Virtualization-0.107
[root@vm Sys-Detect-Virtualization-0.107]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Warning: prerequisite ExtUtils::MakeMaker 6.59 not found. We have 6.30.
Warning: prerequisite Test::Deep 0 not found.
Warning: prerequisite Test::Exception 0 not found.
Warning: prerequisite Test::More 0.82 not found. We have 0.62.
Writing Makefile for Sys::Detect::Virtualization

Make

[root@vm Sys-Detect-Virtualization-0.107]# make
cp lib/Sys/Detect/Virtualization.pm blib/lib/Sys/Detect/Virtualization.pm
cp lib/Sys/Detect/Virtualization/linux.pm blib/lib/Sys/Detect/Virtualization/linux.pm
cp lib/Sys/Detect/Virtualization/freebsd.pm blib/lib/Sys/Detect/Virtualization/freebsd.pm
cp script/virtdetect blib/script/virtdetect
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/virtdetect
Manifying blib/man1/virtdetect.1
Manifying blib/man3/Sys::Detect::Virtualization.3pm
Manifying blib/man3/Sys::Detect::Virtualization::freebsd.3pm
Manifying blib/man3/Sys::Detect::Virtualization::linux.3pm

Install

[root@vm Sys-Detect-Virtualization-0.107]# make install
Installing /usr/lib/perl5/site_perl/5.8.8/Sys/Detect/Virtualization.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Sys/Detect/Virtualization/linux.pm
Installing /usr/lib/perl5/site_perl/5.8.8/Sys/Detect/Virtualization/freebsd.pm
Installing /usr/share/man/man1/virtdetect.1
Installing /usr/share/man/man3/Sys::Detect::Virtualization::freebsd.3pm
Installing /usr/share/man/man3/Sys::Detect::Virtualization::linux.3pm
Installing /usr/share/man/man3/Sys::Detect::Virtualization.3pm
Installing /usr/bin/virtdetect
Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Sys/Detect/Virtualization/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod

Detect Virtualization using ‘virtdetect‘ command

[root@vm Sys-Detect-Virtualization-0.107]# virtdetect
Multiple possible virtualization systems detected:
 Linux KVM
 Qemu

You may also run ‘virtdetect‘ on a non-virtualized environment to see what the command outputs.

[peter@non-virtualized-machine ]$ virtdetect
No virtualization detected

Was this article helpful?

Related Articles

Leave a Comment