Linux Administration Cookbook
上QQ阅读APP看书,第一时间看更新

lshw

Should dmidecode not be available, you can also make use of lshw, a command for listing hardware. Again, it makes use of the DMI table on a device.

Very quickly, we can use a format option of lshw to show the bus information of a system:

$ sudo lshw -businfo
Bus info Device Class Description
=====================================================
system VirtualBox
bus VirtualBox
memory 128KiB BIOS
memory 1GiB System memory
cpu@0 processor Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
pci@0000:00:00.0 bridge 440FX - 82441FX PMC [Natoma]
pci@0000:00:01.0 bridge 82371SB PIIX3 ISA [Natoma/Triton II]
pci@0000:00:01.1 scsi1 storage 82371AB/EB/MB PIIX4 IDE
scsi@1:0.0.0 /dev/cdrom disk CD-ROM
pci@0000:00:02.0 display VirtualBox Graphics Adapter
pci@0000:00:03.0 enp0s3 network 82540EM Gigabit Ethernet Controller
pci@0000:00:04.0 generic VirtualBox Guest Service
pci@0000:00:05.0 multimedia 82801AA AC'97 Audio Controller
pci@0000:00:06.0 bus KeyLargo/Intrepid USB
usb@1 usb1 bus OHCI PCI host controller
pci@0000:00:07.0 bridge 82371AB/EB/MB PIIX4 ACPI
pci@0000:00:0d.0 scsi2 storage 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode]
scsi@2:0.0.0 /dev/sda disk 8589MB VBOX HARDDISK
scsi@2:0.0.0,1 /dev/sda1 volume 1GiB Linux filesystem partition
scsi@2:0.0.0,2 /dev/sda2 volume 7167MiB Linux LVM Physical Volume partition
input PnP device PNP0303
input PnP device PNP0f03

This gives us information that instantly suggests a VM, such as the system, bus, and display entries.

We also have an easy-to-read breakdown of the classes available, meaning that we can query those directly, starting with disk in this example:

$ sudo lshw -c disk
*-cdrom
description: DVD reader
product: CD-ROM
vendor: VBOX
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/cdrom
logical name: /dev/sr0
version: 1.0
capabilities: removable audio dvd
configuration: ansiversion=5 status=nodisc
*-disk
description: ATA Disk
product: VBOX HARDDISK
vendor: VirtualBox
physical id: 0.0.0
bus info: scsi@2:0.0.0
logical name: /dev/sda
version: 1.0
serial: VB5cbf266c-3015878d
size: 8GiB (8589MB)
capabilities: partitioned partitioned:dos
configuration: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=000b6a88

Alternatively, if we think that's too much information, we could query the system class:

$ sudo lshw -c system
localhost.localdomain
description: Computer
product: VirtualBox
vendor: innotek GmbH
version: 1.2
serial: 0
width: 64 bits
capabilities: smbios-2.5 dmi-2.5 vsyscall32
configuration: family=Virtual Machine uuid=BDC643B8-8D4D-4288-BDA4-A72F606CD0EA