How to Quickly Pull All the Ins and Outs of Server Hardware in Linux
You SSH into an unfamiliar server and try to figure out what's actually inside. What motherboard is it, how many memory modules are occupied, at what frequency they're running, what mode the disk is in.
Usually you end up using a familiar set of scattered commands: lspci, lsusb, dmidecode, lscpu or reading files in /proc. In the end, you sit there piecing together the overall picture in your head.
The lshw utility (Hardware Lister) solves this routine entirely. It gathers computer configuration data into a unified hardware tree. And it does this not only in the console but also exports everything to ready-made formats like XML or HTML.
What lshw Can Do
The program scans the system through several sources: it queries DMI (SMBIOS) on x86 and EFI, peeks into CPUID, parses PCI/AGP, USB, SCSI, and IDE/ATA bus listings, and on PowerPC architecture reads the OpenFirmware device tree.
As a result, you get a detailed report with all the hardware laid out:
- Precise RAM layout: timings, size of each module, occupied slots, and supported maximum.
- BIOS/UEFI firmware version and motherboard revision.
- Processor configuration, supported instructions, bus frequency, and cache sizes at all levels.
- Storage controllers, network cards, and connected peripherals with the kernel drivers they use.
An extra bonus is that the utility doesn't just output a raw device ID—it pulls readable names from local databases hwdata and /usr/share/misc/.
Output Formats and Practical Scenarios
The plain text output from lshw can sometimes seem too long if you run the command without parameters. But it has flexible flags that make life much easier for admins and infrastructure developers.
Compact Summary
When you need to quickly assess the overall picture without an endless wall of text, the brief mode comes in handy:
sudo lshw -short
It will output a neat table with the status of each node, device paths, and a brief description of components.
Generating HTML Reports
If you need to share inventory with colleagues or attach the server state to a ticket, you can generate a nice HTML file with a single command:
sudo lshw -html > server_spec.html
Such a report is immediately ready to view in a browser, contains understandable collapsible sections, and visually separates controllers from child devices.
Automation via XML and JSON
For inventory scripts or automatic machine audits, the utility can output raw structured data:
sudo lshw -xml > hardware.xml
This XML is easy to parse in Python or feed into a CMDB database when setting up a new server.
Build and Under the Hood
The project is written in C++ and has been around for a very long time. The code compiles even with old compiler versions and doesn't require heavy dependencies.
You can build a binary from source in literally a couple of seconds:
make
sudo make install
If you're building a minimalist image for system recovery (rescue disk), lshw can be compiled statically or compressed with UPX so the binary weighs almost nothing:
make static
make compressed
For GUI enthusiasts, a lshw-gtk build is available (built via make gui), but in practice the console version is more than enough.
Who Will Find It Useful
The utility is probably not needed by those who work exclusively with containers or serverless functions. But if you're setting up bare-metal servers, building a home server, diagnosing memory module detection issues, or writing scripts for inventorying a fleet of machines, lshw saves a ton of time. Just run it once with root privileges and you'll know exactly which hardware is installed in the case.
Related projects