Hardware Discovery and Fault Diagnostics

A Couple of neat tricks I learned while trying to establish a wi-fi Internet connection through the command line are the command line instructions for discovering a computer’s hardware and the device drivers that make them work. Those commands are:

lshw

lspci

lsusb

and

lsdev

The first three of those commands are available on most, if not all, Linux environments. lsdev must be installed using sudo apt-get install procinfo .

You should run them as the root user either by adding sudo before the command else by typing sudo su (followed by pressing the return) key as your first instruction. If you use sudo su then remember to type exit after you’ve finished issuing commands.

Although these particular commands are safe to use as root, issuing any instruction whilst root involves risk so please be careful.

The lshw, lspci, lsusb and lsdev commands will tell you almost everything you need to know to establish the hardware that makes up your computer, the details of that hardware, whether that hardware has been properly installed or not, which device driver is allowing the Linux Kernal to interface with that hardware, and the the I/O addresses plus the IRQ & DMA channels used by that hardware.

If you know a device is connected to your machine but the output from running any of these commands doesn’t display information about it then that device could be improperly connected to your machine, improperly detected by your machine or defective. Solving device problems is beyond the scope of this article so if you have problems with any of your devices then you wil need to find solutions elsewhere.

As with all Linux commands, you can have the results posted to a text file instead of posted to the screen; and you can pipe that text file directly into a text editor for immediate perusal.

For example, lshw  > hardwarelist.txt | kate hardwarelist.txt

would run the lshw command then post the results into a file called hardwarelist.txt which would the be opened in the kate text editor.

Were you working with a desktopless environment then you could use nano, vi or edit in place of kate which is a graphical editor of the kde environment.

Remember that results do not post to the screen when posted to a file.

When piping the information to a text editor (or web browser) be aware that the test editor might open before the data has been posted to the file so you might need to refresh the page before you can view the data.

So, here’s what those useful command do:

lshw extracts detailed information about your machine’s hardware then posts it directly to the screen else to a file.

It has several operands. The most useful being -html which posts to an html file, -xml which posts to an xml file, -class which posts information about a specific type of hardware, -short which posts brief information about the device (its  path, its name, its class and its description).

Examples:

lshw -short

would print a compact list of information about a machine’s devices. That information includes the devices’ class type.

lshw -class network

would post detailed information about all devices of the class network (class obtained from the output of lshw -short).

lshw -html

would post to the screen detailed information about all a machine’s devices in an html format.

lshw -html > hardwarelist.html

would post the result of lshw -html into an html file called hardwarelist.html. The result would not be posted to the screen.

The html formatted list displays as a hardware tree. Open a terminal and copy or type sudo lshw -html > hardwareinfo.html | konqueror hardwareinfo.html . Feel free to change konqueror to your web browser of choice e.g firefox or opera. You might need to refresh the open browser page to get it to display (the page might open before the data is written to it). The data will not be written until you’ve entered your sudo access password.

lspci displays information about a system’s PCI buses and the devices plugged into them.

The default information provided by lspci is brief. To increase the amount of provided information use -v or for more -vv or for even more -vvv e.g lspci -vvv gives more information than lspci -v

Use the -t option to have the information display as a tree.

Use the -k option to have each device’s kernal driver information displayed (this is provided by the -v option too).

Example:

lspci -vvv > lspciresults.txt

would provide very verbose (-vvv) information about the pci buses and devices attached to the buses. This information would be posted to a file called lspciresults.txt.

To view that file (lspciresults.txt) type nano lspciresults.txt or edit lspciresults.txt or kate lspciresults.txt . The exact instruction to view the file depends on whether you have nano or edit installed as command line text editors or kate installed as a graphical editor for your desktop environment. Any other text editor will also work.

To run that command, post the results to a text file and have the text editor open, you could write a single line instruction, viz,

lspci -vvv > lspciresults.txt | nano lspciresults.txt

lsusb displays information about the USB buses and devices connected to a system.

By default, the information provided by lsusb is basic. To get more information use the -v option.

Use the -t option to have the information display as a tree.

Example:

lsusb -v

would display verbose (-v) information about the USB buses and devices attached to a system.

lsdev extracts information about your computer’s installed hardware from the interrupts, ioports and dma files in the /proc directory. It provides a quick overview of which hardware uses what I/O addresses and what IRQ and DMA channels. This command has no associated options.

I’ve detailed the basic options (also know as switches) used by lshw, lspci and lsusb. For further information use the -h or –help switch.

Sharing is caring!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of