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

Listing 4. The lsdev command provides information on interrupts, ports and direct memory access.


> lsdev
Device          DMA   IRQ  I/O Ports
------------------------------------------------
                        7 
0000:00:1d.0               c480-c49f
0000:00:1d.1               c800-c81f
0000:00:1d.2               c880-c89f
...
... (several lines snipped out)
...
eth0                   29 
fpu                        00f0-00ff
gpio_ich                   0480-04bf 04b0-04bf
i801_smbus             19  0400-041f
i8042                1 12 
iTCO_wdt                   0830-0833 0830-0833 0860-087f 0860-087f
keyboard                   0060-0060 0064-0064
...
... (several lines snipped out)
...
timer                   0 
timer0                     0040-0043
timer1                     0050-0053
uhci_hcd                   c480-c49f c800-c81f c880-c89f cc00-cc1f
uhci_hcd:usb2          23 
uhci_hcd:usb3          19 
uhci_hcd:usb4          18 
uhci_hcd:usb5          16 
vesafb                     03c0-03df

Finally, if you've made it this far, the lshw command is a sort of catch-all that can produce lots of information on all of your installed hardware. The -short option provides a (somewhat) abbreviated listing of everything in your box (see Listing 5, and note some interesting lines, "To Be Filled By O.E.M.", which show that someone was careless when setting up my motherboard). With this command, you get information on the system, buses, memory, processor, display, network and everything else.

Listing 5. The lshw command includes information on all your hardware."


# lshw -short
H/W path               Device      Class          Description
=============================================================
                                   system         To Be Filled 
 ↪By O.E.M.
/0                                 bus            G41M-VS3.
/0/0                               memory         64KiB BIOS
/0/4                               processor      Core 2 Quad (To Be 
 ↪Filled By O.E.M.)
/0/4/5                             memory         128KiB L1 cache
/0/4/6                             memory         4MiB L2 cache
/0/d                               memory         4GiB System Memory
/0/d/0                             memory         4GiB DIMM SDRAM 
 ↪Synchronous
/0/d/1                             memory         DIMM [empty]
/0/100                             bridge         4 Series Chipset 
 ↪DRAM Controller
/0/100/1                           bridge         4 Series Chipset 
 ↪PCI Express Root Port
/0/100/1/0                         display        GK107 [GeForce 
 ↪GT 740]
/0/100/1/0.1                       multimedia     GK107 HDMI Audio 
 ↪Controller
/0/100/1b                          multimedia     NM10/ICH7 Family 
 ↪High Definition Audio Controller
/0/100/1c                          bridge         NM10/ICH7 Family 
 ↪PCI Express Port 1
/0/100/1c.1                        bridge         NM10/ICH7 Family 
 ↪PCI Express Port 2
/0/100/1c.1/0          eth0        network        AR8152 v2.0 Fast 
 ↪Ethernet
/0/100/1d                          bus            NM10/ICH7 Family 
 ↪USB UHCI Controller #1
/0/100/1d/1            usb2        bus            UHCI Host Controller
/0/100/1d.1                        bus            NM10/ICH7 Family 
 ↪USB UHCI Controller #2
/0/100/1d.1/1          usb3        bus            UHCI Host Controller
/0/100/1d.1/1/1                    bus            USB2.0 Hub
/0/100/1d.1/1/1/1                  input          OM
/0/100/1d.1/1/1/2                  input          USB Multimedia 
 ↪Keyboard
/0/100/1d.1/1/1/3                  multimedia     USB2.0 Camera
/0/100/1d.1/1/2                    communication  Bluetooth Dongle 
 ↪(HCI mode)

...several lines snipped out...

/0/1                   scsi2       storage        
/0/1/0.0.0             /dev/sda    disk           500GB WDC 
 ↪WD5000AAKS-0
/0/1/0.0.0/1           /dev/sda1   volume         4102MiB Linux 
 ↪swap volume
/0/1/0.0.0/2           /dev/sda2   volume         461GiB EXT4 volume
/0/1/0.1.0             /dev/sdb    disk           160GB MAXTOR 
 ↪STM316021
/0/1/0.1.0/1           /dev/sdb1   volume         4094MiB Linux 
 ↪swap volume
/0/1/0.1.0/2           /dev/sdb2   volume         145GiB EXT3 volume
/0/2                   scsi3       storage        
/0/2/0.0.0             /dev/sdc    disk           3TB WDC 
 ↪WD30EZRX-00M
/0/2/0.0.0/1           /dev/sdc1   volume         2794GiB EXT4 volume
/0/2/0.1.0             /dev/cdrom  disk           DVD RW AD-7200S

Notice the "class" column in Listing 5. You can get a hint of the full information that lshw can provide by using the -class parameter to limit output. For example, see below the detailed specs on my network card; it shows the vendor, model and plenty of other details (warning: this is the kind of output you get if you don't restrict the command with -short; for my machine, lshw with no extra options produces a listing more than 500 lines long):


# lshw -class network
  *-network               
    description: Ethernet interface
    product: AR8152 v2.0 Fast Ethernet
    vendor: Qualcomm Atheros
    physical id: 0
    bus info: pci@0000:01:00.0
    logical name: eth0
    version: c1
    serial: bc:5f:f4:12:e0:f1
    size: 100Mbit/s
    capacity: 100Mbit/s
    width: 64 bits
    clock: 33MHz
    capabilities: pm msi pciexpress vpd bus_master 
 ↪cap_list ethernet physical tp 10bt 10bt-fd 
 ↪100bt 100bt-fd autonegotiation
    configuration: autonegotiation=on broadcast=yes 
 ↪driver=atl1c driverversion=1.0.1.1-NAPI 
 ↪duplex=full latency=0 link=yes multicast=yes 
 ↪port=twisted pair speed=100Mbit/s
    resources: irq:29 memory:fcfc0000-fcffffff 
 ↪ioport:dc00(size=128)

The lshw command has several other interesting options. For example, it can produce either HTML or XML output (add the -html or -xml options); the former is appropriate for showing in a browser, while the latter is useful if you want to store or process your hardware information. See Figure 1 for just a small part of the full hardware description of my box. For security purposes, the -sanitize option removes sensitive information, such as serial numbers. There's even an -X option to use a graphical interface (I'll get to that later).

Figure 1. The lshw command also can produce HTML or XML output; the former is shown here.

So far, I've discussed several ls* commands, and even if they are not actually a "family", they are my favorite tools. It's easy to remember them by typing ls and letting type-ahead suggest the rest. However, there are more command-line possibilities, so let's take a look.

What's SMBIOS?

How does Linux recognize what devices are installed? Since 1995, the SMBIOS (System Management BIOS) specification has provided this kind of information, doing away with the need for potentially worrisome operations like hardware probing. This standard (used by DMI) is geared to the Intel 32- and 64-bit processor architecture systems. Basically, it defines a structure with appropriate data for each kind of device, such as CPU, RAM, system slots and more. On principle, you could parse and decode this table by yourself, but several of the commands shown in this article already do that job. If you are curious about the specifics of the standard, see the Resources section.

More Command-Line Options

Let's start with some general commands. The first, dmidecode, allows you to dump the computer's DMI (or SMBIOS; see the What's SMBIOS? sidebar) in a more readable format. If the table is found, its contents are dumped record by record, similar to this:


# dmidecode -t 6
# dmidecode 2.12
SMBIOS 2.5 present.

Handle 0x0009, DMI type 6, 12 bytes
Memory Module Information
   Socket Designation: DIMM0
   Bank Connections: 0 1
   Current Speed: Unknown
   Type: DIMM SDRAM
   Installed Size: 4096 MB (Double-bank Connection)
   Enabled Size: 4096 MB (Double-bank Connection)
   Error Status: OK

Handle 0x000A, DMI type 6, 12 bytes
Memory Module Information
   Socket Designation: DIMM1
   Bank Connections: 4 5
   Current Speed: Unknown
   Type: DIMM SDRAM
   Installed Size: Not Installed
   Enabled Size: Not Installed
   Error Status: OK

If you don't want to list the entire table (several hundred lines in my computer), you can restrict the output to a specific type of entry, according to SMBIOS definitions (Table 2).

Table 2. SMBIOS has several record types that you can select with dmidecode.

Type Description
0 BIOS
1 System
2 Baseboard
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On-board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
40 Additional Information
41 Onboard Devices Extended Information
42 Management Controller Host Interface
126 Disabled Entry
127 "End-of-Table" Special Marker
128–255 OEM-specific Data

You also can use specific keywords to restrict the output to a few types (Table 3).

Table 3. You also can use special keywords to get related information from SMBIOS.

SMBIOS Keyword SMBIOS Types
bios 0,13
system 1,12,15,23,32
baseboard 2,10,41
chassis 3
processor 4
memory 5,6,16,17
cache 7
connector 8
slot 9

If I were to give an award for "Most Talkative Command", surely it would go to hwinfo, another command that can dump all the hardware information on your computer. On my machine, running hwinfo without any parameters produces more than 12,000 lines, including several memory dumps of the SMBIOS table. You can produce a much more compact version with the --short option (Listing 6).

Listing 6. The hwinfo command can be quite talkative; using the --short option makes it more manageable.


# hwinfo --short
cpu:                                                            
          Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2670 MHz
          Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2336 MHz
          Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2670 MHz
          Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2670 MHz
keyboard:
          Logitech USB Multimedia Keyboard
mouse:
          Elan Microelectronics OM
monitor:
          SAMSUNG SA300/SA350
          SAMSUNG S20B300
graphics card:
          nVidia VGA compatible controller
sound:
          Intel NM10/ICH7 Family High Definition Audio Controller
          nVidia GK107 HDMI Audio Controller
storage:
          Intel 82801G (ICH7 Family) IDE Controller
          Intel NM10/ICH7 Family SATA Controller [IDE mode]
network:
  eth0    Atheros AR8152 v2.0 Fast Ethernet
network interface:
  lo      Loopback network interface
  eth0    Ethernet network interface
disk:
  /dev/sda   WDC WD5000AAKS-0
  /dev/sdb   MAXTOR STM316021
  /dev/sdc   WDC WD30EZRX-00M

...etc (rest of the listing, snipped out)  

You can restrict hwinfo to a specific type of hardware by adding an option, such as --monitor or --printer. Get the whole list of options with hwinfo --help. For instance, I can dump the optical unit data with hwinfo --cdrom (Listing 7). The --listmd option lets you include RAID devices, which usually aren't included in the standard output.

______________________