1. Overview
In this article, we’ll learn what the hwinfo command is and how to install it on various Linux distributions. Next, we’ll discuss how to use hwinfo by reviewing its different options.
2. hwinfo
hwinfo is a command-line utility that collects and prints information about the system hardware. It provides a detailed report for almost all system components in a modular fashion. In addition, hwinfo has a filtering mechanism to provide details about specific components and format the output based on the given options.
2.1. Installation
hwinfo is available in the package repositories of almost all major Linux distributions. We can install it using a package manager using its canonical name hwinfo:
# Debian, Ubuntu, and derivatives
$ sudo apt install -y hwinfo
# Fedora, RedHat, and CentOS Stream
$ sudo dnf install -y hwinfo
# openSUSE
$ sudo zypper install --non-interactive hwinfo
# Arch, Manjaro, and derivatives
$ sudo pacman -Syu --noconfirm hwinfo
Once installed, let’s verify it:
$ hwinfo --version
21.82
In the next sections, we’ll learn how to use hwinfo.
2.2. Printing Hardware Info
hwinfo is very straightforward to use. Generally, we merely type the command and wait for it to print out the detailed report:
$ hwinfo
============ start debug info ============
libhd version 21.82u (x86-64) [7688]
using /var/lib/hardware
kernel version is 6.8
----- /proc/cmdline -----
BOOT_IMAGE=/boot/vmlinuz-6.8.0-31-generic root=UUID=bda8fef0-0c8a-47f6-9c2d-dadc6882d794 ro quiet splash vt.handoff=7
----- /proc/cmdline end -----
debug = 0xff7ffff7
probe = 0x15938fcdaa17fcf9fffe (+memory +pci +isapnp +net +floppy +misc +misc.serial +misc.par +misc.floppy +serial +cpu +bios +monitor +mouse +scsi +usb -usb.mods +modem +modem.usb +parallel +parallel.lp +parallel.zip -isa -isa.isdn +isdn +kbd +prom +sbus +int +braille +braille.alva +braille.fhp +braille.ht -ignx11 +sys -bios.vbe -isapnp.old -isapnp.new -isapnp.mod +braille.baum -manual +fb +pppoe -scan +pcmcia +fork -parallel.imm +s390 +cpuemu -sysfs -s390disks +udev +block +block.cdrom +block.part +edd +edd.mod -bios.ddc -bios.fb -bios.mode +input +block.mods +bios.vesa -cpuemu.debug -scsi.noserial +wlan -bios.crc -hal +bios.vram +bios.acpi -bios.ddc.ports=0 +modules.pata -net.eeprom +x86emu=dump -max -lxrc)
shm: attached segment 3 at 0x766f4388a000
>> hal.1: read hal data
>> floppy.1: get nvram
>> floppy.2: klog info
>> bios.1: cmdline
>> bios.1.1: apm
...
Notably, it produces a long report with almost all the details. Therefore, it’s a bit tedious to search through the output if we’re looking for specific information. One way to quickly find the required information is to use grep:
$ hwinfo | grep -m 1 flags
flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl xtopology cpuid pni cx16 hypervisor lahf_lm pti
This command prints the first matched line containing the word flags, which effectively prints out the features supported by the CPU. Alternatively, we can also use less:
$ hwinfo | less
Then, we can press “*/“, followed by a search term. It will highlight the found matches. Further, we can press “N*” to go to the next match. In the next sections, we’ll look at some specific command options
2.3. –short
If we don’t need to print out all the details, we can simply use the –short option:
$ hwinfo --short
cpu:
QEMU Virtual CPU version 2.5+, 2791 MHz
QEMU Virtual CPU version 2.5+, 2791 MHz
keyboard:
/dev/input/event3 Adomax QEMU USB Keyboard
mouse:
/dev/input/mice Adomax QEMU USB Tablet
...
monitor:
QEMU Monitor
graphics card:
Red Hat Virtio GPU
...
As we can see, it makes the report shorter and only provides essential information about each component.
2.4. –<HARDWARE_ITEM>
hwinfo makes it easy to print information about specific hardware. For that, we use the –<HARDWARE_ITEM> option. The following are all valid items:
- arch
- bios
- cpu
- disk
- memory
- network
- usb
Moreover, there are additional items, which we can find on the man page for hwinfo. We can print out information about an item by prefixing it with —:
$ hwinfo --bios
01: None 00.0: 10105 BIOS
[Created at bios.186]
Unique ID: rdCR.lZF+r4EgHp4
Hardware Class: bios
BIOS Keyboard LED Status:
Scroll Lock: off
Num Lock: off
Caps Lock: off
Config Status: cfg=new, avail=yes, need=no, active=unknown
Notably, it only prints the BIOS information.
2.5. –only
The –only option narrows down the probing by allowing us to specify devices. For instance, if we’re printing information about disks, we could use –disk. However, for multiple disks, reviewing the output can be a hassle. On that account, we can use –only to be more specific:
$ hwinfo --disk --only /dev/sda
22: IDE 00.0: 10600 Disk
[Created at block.255]
Unique ID: 3OOL.vYf0y9mPKxA
Parent ID: w7Y8.Uq6XLWd5W43
SysFS ID: /class/block/sda
SysFS BusID: 0:0:0:0
...
Usually, we provide device names that correspond to the device names in the/dev directory. In this instance, /dev/sda is the primary hard drive attached to the machine. Similarly, we can provide multiple devices:
$ hwinfo --disk --only /dev/sda --only /dev/sdb
21: SCSI 600.0: 10600 Disk
[Created at block.255]
Unique ID: Mwf_.xva8Wqq1nT2
Parent ID: 8otl.TZR49fTpFS3
SysFS ID: /class/block/sdb
SysFS BusID: 6:0:0:0
...
23: IDE 00.0: 10600 Disk
[Created at block.255]
Unique ID: 3OOL.vYf0y9mPKxA
Parent ID: w7Y8.Uq6XLWd5W43
SysFS ID: /class/block/sda
SysFS BusID: 0:0:0:0
2.6. –save-config and –show-config
The –save-config option lets us save a device configuration to a file:
$ sudo hwinfo --cpu --save-config=all
...
Save Configuration:
rdCR.j8NaKXDZtZ6: ok
wkFv.j8NaKXDZtZ6: ok
The option expects a SPEC, which can be a device name, UDI, or “all“. In addition, we also need to run this command as root because we’ll need write access to the /var directory. The configuration is stored in /var/lib/hardware:
$ cat /var/lib/hardware/udi/rdCR.j8NaKXDZtZ6
hwinfo.hwclasslist = '04000000000000'
hwinfo.subclass = 3 (0x3)
hwinfo.baseclass = 257 (0x101)
...
Similarly, we can use –show-config followed by the UDI to show the config data for that device:
$ hwinfo --show-config rdCR.j8NaKXDZtZ6
01: None 00.0: 10103 CPU
[Created at none.912]
Unique ID: rdCR.j8NaKXDZtZ6
Hardware Class: cpu
Config Status: cfg=new, avail=yes, need=no, active=unknown
2.7. Additional Options
In addition to the essential options, we can use –map to list disk name mappings if they have changed. However, for this to work, we need to have a saved config that has been created before the change. Furthermore, we can dump the hardware database using –dump-db followed by 0 or 1. 0 specifies the external database in /var/lib/hardware and 1 specifies the internal database. Finally, we can write logs using the –log option followed by filename.
3. Conclusion
This article covered how to use the hwinfo tool to print out reports about the system components. We learned how to install hwinfo and use its different options to find hardware details more effectively.