On a recently-booted system, checking the output of the dmesg command may be sufficient to detect if a running system is a virtual guest. Below are examples of the command under different virtualization technologies:
Xen
$ dmesg | grep -i virtual 
Xen virtual console successfully installed as xvc0
VMWare
 $ dmesg | grep -i virtual  
     VMware vmxnet virtual NIC driver         Vendor: VMware    Model: Virtual disk      Rev: 1.0  
     hda: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive
QEMU or KVM
$ dmesg | grep -i virtual    
   CPU: AMD QEMU Virtual CPU version 0.9.1 stepping 03
Alternatively, the dmidecode command can also be to get information from the system BIOS. Examples of this command under different virtualization technologies are below:
VMWare:
# dmidecode | egrep -i 'manufacturer|product'   
    Manufacturer: VMware, Inc.       Product Name: VMware Virtual Platform
QEMU or KVM:
# dmidecode | egrep -i 'vendor' 
   Vendor: QEMU