What's in the Box? Interrogate Your Linux Machine's Hardware

Listing 7. The hwinfo command can restrict its output to specific hardware, as the cdrom device, for example.


# hwinfo --cdrom
25: SCSI 301.0: 10602 CD-ROM (DVD)                              
  [Created at block.249]
  Unique ID: KD9E.SGHalmfn+h9
  Parent ID: w7Y8.xyd+qedQTr5
  SysFS ID: /class/block/sr0
  SysFS BusID: 3:0:1:0
  SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/
↪ata4/host3/target3:0:1/3:0:1:0
  Hardware Class: cdrom
  Model: "SONY DVD RW AD-7200S"
  Vendor: "SONY"
  Device: "DVD RW AD-7200S"
  Revision: "1.61"
  Driver: "ata_piix", "sr"
  Driver Modules: "ata_piix", "sr_mod"
  Device File: /dev/sr0 (/dev/sg3)
  Device Files: /dev/sr0, /dev/cdrom, /dev/cdrw, 
 ↪/dev/disk/by-id/ata-Optiarc_DVD_RW_AD-7200S, 
 ↪/dev/disk/by-path/pci-0000:00:1f.2-ata-2.1, 
 ↪/dev/dvd, /dev/dvdrw
  Device Number: block 11:0 (char 21:3)
  Features: CD-R, CD-RW, DVD, DVD-R, DVD-RW, DVD-R DL, 
 ↪DVD+R, DVD+RW, DVD+R DL, DVD-RAM, MRW, MRW-W
  Drive status: no medium
  Config Status: cfg=no, avail=yes, need=no, active=unknown
  Attached to: #14 (IDE interface)
  Drive Speed: 48

Of the command-line programs I'm covering in this article, inxi is more colorful, even if only moderately (Figure 2).

Figure 2. inxi, even if only a command-line tool, at least tries to use some colors.

If invoked with no parameters, it will just produce a line like the following, showing CPU, kernel, uptime and a few more details:


CPU~Quad core Intel Core2 Quad CPU Q8400 (-MCP-) 
 ↪clocked at 2003.000 Mhz Kernel~4.1.5-1-desktop 
 ↪x86_64 Up~2 days 23:24 Mem~2377.4/3949.4MB 
 ↪HDD~3660.7GB(67.9% used) Procs~202 Client~Shell 
 ↪inxi~1.7.24   

However, you can use lots of options to get specific data. For example, you can set the verbosity level with options -v0 (minimum) through -v7 (maximum verbosity). The -x option allows including extra information for some hardware. Check out inxi -h to get all possible options. For instance, you can get audio information with inxi -A or graphics card data with inxi -G and so on:


# inxi -A
Audio:     Card-1: NVIDIA GK107 HDMI Audio Controller 
 ↪driver: snd_hda_intel Sound: ALSA ver: k4.1.5-1-desktop
           Card-2: Intel NM10/ICH7 Family High 
 ↪Definition Audio Controller driver: snd_hda_intel

Now, let's finish with some GUI options.

The GUI Way

To start with, usbview is a rough graphic equivalent of lsusb or usb-devices, which I discussed earlier. It's quite simple to use, with no options or parameters. It shows two columns: the left one is a tree of all available USB devices, and the right one gives the full details. Figure 3 shows details on my USB keyboard.

Figure 3. The usbview command shows the details of all USB devices in tree form.

Let's move on to a command I already discussed, which shares the display style: lshw -X. Instead of producing a listing (as shown previously), the -X option produces a graphic interface with several columns on the left to let you choose what hardware to inspect. An area to the right shows the full hardware details for the chosen device. Figure 4 shows the result of analyzing my optical DVD reader/writer unit; the provided information includes other details, such as the logical unit name, its capabilities and more.

Figure 4. The lswh -X command produces a graphic interface that lets you browse all hardware devices.

Another interesting program is hardinfo, which "is not dead, but needs a maintainer", according to its GitHub page (see Resources.) This program shows a tree structure to the left with four main branches:

  • Computer shows lots of details about your machine: some are related to software and not to hardware.

  • Devices includes all devices in your box, grouped by category.

  • Network not only shows network card details, but also some other aspects, such as DNS servers or routing.

  • Benchmarks lets you see how your machine fares against other computers, but because of the lack of updates, the comparisons are against old CPUs.

Figure 5 shows sample output.

Figure 5. The hardinfo command includes several extra pieces of data, not limited only to hardware.

There are two more options. The "Information" menu entry allows you to produce a report, in either HTML or plain-text format, choosing whichever parts interest you. The "Network Updater" should let you update the internal program data, including more recent benchmark results, but when I tried to run it, I got a "Contacting HardInfo Central Database (failed)" message. See Figure 6 for a example of the produced HTML report.

Figure 6. The hardinfo command can produce an HTML or text report describing your complete system.

Let's end with KDE's own kinfocenter. This utility (see Figure 7, which shows RAM details for my machine) is similar to the previous tools I've been describing, and it offers a left pane with a tree with all available options and a right pane with more details on the chosen option at the left.

Figure 7. KDE's own kinfocenter shows not only hardware details, but plenty of other system data as well.

The program doesn't restrict itself to hardware details, but shows all kinds of other information, such as "Samba Status", "Energy Information" or "X-Server", just to mention a few.

DIY with /proc and /sys

Linux is full of directories and files, but the /proc and /sys directories are really strange. They don't actually exist, but they allow you to browse them. They are full of zero-length empty files, but you can open and view them. The /proc directory preceded /sys, and it has basically all details about running processes (hence, the /proc name). Over time, more files were added to it, mostly "virtual" ones, which don't actually exist, but are created on the fly if you try to access them. (Most virtual files sport a current timestamp, which shows that they constantly are kept up to date and their contents are the latest possible.) The /sys directory is more modern. It appeared around the time of the 2.6 kernel to introduce more order and a better structure than provided by the older /proc, which had just grown in a sort of haphazard way. Many of the files (but not all) in /proc are duplicated in /sys, and whenever possible, you should pick the files in the latter directory. The /sys directory has several subdirectories:

  • block/ has an entry pointing to each block device.

  • bus/ has directories for each bus type, and within each, two subdirectories: devices/ and drivers/. The former has a directory for each device, pointing to the device's directory in /root, and the latter has a directory for each driver that was loaded for devices on the given bus.

  • class/ has directories for each type of object; some examples are block/, graphics/, net/, sound/ and so on.

  • dev/ provides directories for each type of device (for example, dev/block/ or dev/char/), each with directories for each appropriate device.

  • devices/ contains the global device hierarchy, with every physical device in your system.

  • firmware/ includes directories for firmware-specific objects; for example, acpi/ or memmap/, but the particular directories in your own machine depend on the firmware drivers in your kernel.

  • fs/ has a directory for each filesystem type in your machine, each with further directories for each specific device; for example, I have /sys/fs/ext4/sda2, because the disk mounted as /dev/sda2 uses ext4.

  • kernel/ has several files related to the currently loaded kernel.

  • module/ has a subdirectory for each and every module loaded into the kernel.

  • power/ represents the power subsystem.

When you get to the deepest levels of any branch, you may find any number of individual files, which you can read to get attributes of the given object. What files? That's a hard question to answer, because it depends on which specific branch you are visiting, so you'll have to do a bit of work before you get to extract information from the /sys directory. (See Resources for some pointers about this.) Also, be aware that you can write to some of the files, and that will imply modifying the corresponding parameter—be warned: do this with care! However, if you keep at it, you'll be able to duplicate the functionality of most of the tools shown in this article, which often work the same way.

Conclusion

I've covered a lot of commands that let you query your Linux machine and learn, in more or less detail, what's exactly in it. And if you need to, you even can get at the base data by yourself and whip up your own hardware-inspection tool.

Resources

Read about the SMBIOS standard at http://www.dmtf.org/standards/smbios. At the time of this writing, the latest version is 3.0.0, dated 2/15/2015.

You can find information on sysfs at https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt and more specific documentation at https://www.kernel.org/doc/Documentation/ABI/stable.

Regarding the older procfs, check https://www.kernel.org/doc/Documentation/filesystems/proc.txt.

The USB ID repository at http://www.linux-usb.org/usb-ids.html has the full list of all known IDs used in USB devices.

The PCI ID repository at http://www.pcidatabase.com provides a centralized list of PCI device IDs.

The lscpu and lsblk commands are part of the util-linux package, available at https://www.kernel.org/pub/linux/utils/util-linux. For documentation, check out http://linux.die.net/man/1/lscpu and http://linux.die.net/man/8/lsblk, respectively.

Read about lsscsi options at http://sg.danny.cz/scsi/lsscsi.html and find a manual page at http://linux.die.net/man/8/lsscsi.

For the lsdev man page, see http://linux.die.net/man/8/lsdev.

The lshw home page is at http://www.ezix.org/project/wiki/HardwareLiSter, and its manual page is at http://linux.die.net/man/1/lshw.

See lsusb in the "usbutils" page at https://github.com/gregkh/usbutils, and get more information at http://linux.die.net/man/8/lsusb.

You can find lspci at (home of the "PCI Utilities") and the man page at .

Check out usbview at http://www.kroah.com/linux/usb and its man page at http://linux.die.net/man/8/usbview.

The hardinfo source repository is at https://github.com/lpereira/hardinfo, but first check your distribution's repositories; it's likely to already be there. Note that the program's last update was more than two years ago, and no further maintenance has been done.

You can find KInfoCenter at https://www.kde.org/applications/system/kinfocenter.

______________________