Hardware Troubleshooting in the Linux Shell

When you’re stuck troubleshooting a problem in Linux, whether it’s a full installation or a recovery USB, it can be useful to know some commands to give you more information about the machine. We’ll start with commands that you might use for troubleshooting from a recovery USB.

GNOME Terminal

An easy command that should be available on almost any system is lscpu which gives us useful information such as CPU Architecture (x86, x86_64, ARM, etc.), the number of cores and threads, the processor speed, and most importantly the model number.

[it@localhost ~]$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
Model name:            Intel(R) Celeron(R) CPU  N2840  @ 2.16GHz

Another easy one is lspci but you might want to filter the output with grep as it can print a lot of information. For more information on how to use grep, look herelspci will give you information about any pci devices, such as USB controller, audio controller, display cards/chips, and network adapters. For example, this can be very useful for discovering what wireless card a laptop has.

[it@localhost ~]$ lspci
00:00.0 Host bridge: Intel Corporation Atom Processor Z36xxx/Z37xxx Series SoC Transaction Register (rev 0e)
00:02.0 VGA compatible controller: Intel Corporation Atom Processor Z36xxx/Z37xxx Series Graphics & Display (rev 0e)
00:14.0 USB controller: Intel Corporation Atom Processor Z36xxx/Z37xxx Series USB xHCI (rev 0e)
00:1a.0 Encryption controller: Intel Corporation Atom Processor Z36xxx/Z37xxx Series Trusted Execution Engine (rev 0e)
00:1b.0 Audio device: Intel Corporation Atom Processor Z36xxx/Z37xxx Series High Definition Audio Controller (rev 0e)
00:1c.0 PCI bridge: Intel Corporation Atom Processor E3800 Series PCI Express Root Port 1 (rev 0e)
00:1f.0 ISA bridge: Intel Corporation Atom Processor Z36xxx/Z37xxx Series Power Control Unit (rev 0e)
01:00.0 Network controller: Intel Corporation Wireless 7260 (rev bb)

As we can see here, this laptop has an intel wireless chip with model number 7260, which can tell you what drivers you need in Windows. The only problem is that if Linux does not have compatible firmware it may not give any information, it may say only that an unknown wireless adapter exists.

While not often as useful, a similar command exists to see information about all USB hubs and devices, lsusb. Here we can see that there is a wireless keyboard and/or mouse on USB device 4.

[it@localhost ~]$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:07dc Intel Corp. 
Bus 001 Device 002: ID 04f2:b48b Chicony Electronics Co., Ltd 
Bus 001 Device 004: ID 062a:4101 Creative Labs Wireless Keyboard/Mouse

A simple command for seeing RAM and swap usage is free which I recommend running with the flag -h to make the output more readable.

[it@localhost ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           3.8G        1.2G        678M        274M        2.0G        2.3G
Swap:          1.3G        236M        1.1G

It should be noted that all this information and more is located in the directory /proc/ (and some in /dev/ ) as readable files (use less or cat). These commands exist because manually finding and reading through this information is not exactly enjoyable, but as a last resort it is always there. If you decide to go through these files grep can help you a great deal.

Next we will look at file system commands. It will almost always be preferable to view the disks and partitions in GNOME Disks or some other graphical disk program, especially if you need to run SMART tests, but there are some cases where the command line can help you out. If you ever are connected over ssh or end up otherwise stuck in a terminal, these are your best bet.

To view file system usage you can use df -h or alternatively lsblk which can give you more specific partition information but may not always be available. As you can see, they are mostly equivalent. If you need to actually modify partitions, use fdisk or gdisk or parted but be absolutely sure of what you’re doing, as these commands can all erase the entire disk!

[it@localhost ~]$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      1.9G     0  1.9G   0% /dev
tmpfs                         1.9G  716K  1.9G   1% /dev/shm
tmpfs                         1.9G  1.5M  1.9G   1% /run
tmpfs                         1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/chromebook0-root   13G  8.5G  3.8G  70% /
tmpfs                         1.9G   19M  1.9G   1% /tmp
/dev/mmcblk0p1                190M  161M   16M  92% /boot
tmpfs                         388M   12K  388M   1% /run/user/42
tmpfs                         388M   24K  388M   1% /run/user/1000

[it@localhost ~]$ lsblk
NAME                                        MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
mmcblk0rpmb                                 179:24   0    4M  0 disk  
mmcblk0boot0                                179:8    0    4M  1 disk  
mmcblk0boot1                                179:16   0    4M  1 disk  
mmcblk0                                     179:0    0 14.7G  0 disk  
├─mmcblk0p1                                 179:1    0  200M  0 part  /boot
└─mmcblk0p2                                 179:2    0 14.5G  0 part  
                                            253:0    0 14.5G  0 crypt 
    ├─chromebook0-root                      253:1    0 13.2G  0 lvm   /
    └─chromebook0-swap                      253:2    0  1.3G  0 lvm   [SWAP]

A very useful command for finding large files and directories is du which works even on mounted NTFS partitions if you want to look through files from Windows. The following command uses sort to make the output more readable, it lists the size of all folders in the present working directory (pwd). This can be used for hunting down large cache files or seeing if someones home directory has any large files in it.

[it@localhost ~]$ du -h --max-depth=1 | sort -h
4.2M	./Pictures
13M	./.local
41M	./Downloads
50M	./bin
91M	./Documents
201M	./code
211M	./.config
345M	./.cache
2.0G	.

Some commands that are more suited for looking at permanent installations include the following:
uname -a which will give you the Kernel version along with some other information

[it@localhost ~]$ uname -a
Linux localhost 4.2.6-200.fc22.x86_64 #1 SMP Tue Nov 10 16:45:19 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

htop which may not be installed by default, it improves upon top as a command line performance monitor.

dmidecode , hwinfo , and inxi are all powerful hardware information tools that may not be installed by default.

For laptops there is also powertop — “A tool to diagnose issues with power consumption and power management to help set power saving settings”

Hopefully these commands are helpful should you ever decide to diagnose issues in Linux. Obviously there are many more tools available, some which vary from distribution to distribution, but these should give you a good start.

[picture source: wikimedia.org]