Linux Troubleshooting & Diagnostics

General Troubleshooting Commands in Linux

Hardware

Getting ram information

cat /proc/meminfo

or if you want to get just the amount of ram you can do:

cat /proc/meminfo | head -n 1

Another fun thing to do with ram is actually open it up and take a peek. This next command will show you all the string (plain text) values in ram.

sudo dd if=/dev/mem | cat | strings

Getting CPU info

Sometimes in troubleshooting, we want to know what processor we are dealing with along with how much CPU is currently being used by our OS and programs. We can do this with these two commands.

cat /proc/cpuinfo

top

Linux top command

Check the temperature of your CPU

Keeping a computer within a safe temperature is the key to maintaining a stable system.

cat /proc/acpi/thermal_zone/THRM/temperature

Check Linux Temperaturecat linux temperature

List PCI and USB devices

To list all the PCI devices in your system issues the following command:

lspci

For USB use:

lsusb

Check out how much hard drive space is left

df -h

Linux show hard drive space

See what hard drives are currently detected

It is oftentimes helpful to know what hard drives are connected to a system and what name was given them in the Linux directory. This info allows us to mount the hard drive and manipulate it.

sudo fdisk -l

fdisk -l

Installed Programs

Packages

Ever want to find all the packages that are installed on your system? You can find all the packages and also find out why they are on your system. You can even determine what packages depend on them if any.

Find all installed packages

dpkg --get-selections | less

Find out why a package is installed and what depends on it

aptitude why packagename

Find out where the package stores all of its files

dpkg -L packagename

Kill a process

ps -A | grep ProgramName
kill 7207

Linux kill firefox

Miscellaneous

Go to a terminal

Ctrl + Alt + f3
return with, Ctrl + Alt + f7

Show all network connections

There are many great network scanners and assessment tools available for Linux but netstat is very easy to use often the first step in troubleshooting network issues. We will leave the rest of the network tools for a later article as there is so much to cover.

netstat

List all files that are currently open on the system

This command will allow you to see all the files that are currently open on your system. Limiting the directory or coupling this command with grep is often useful for finding files that are still openly restricting the ability to unmount a device. Lsof will also output the process id or PID. You can then kill the process using the kill command above.

lsof

Keep an eye on something for awhile

The watch command will repeat a command at a set interval (default 2 seconds) and output the response. This is useful for watching directories that change, watching hard drives fill up when a lot of data is being transferred, or using it with lsusb to watch for USB devices being plugged in.

watch ls
watch df -h

Find where a binary is stored and its libraries

Often times when running a cron command you want to include the absolute path to the command. Sometimes I run scheduled PHP tasks. This can be accomplished by using the ‘whereis’ command.

whereis php5

Logs

See if you have kernel boot issues

dmesg | less

For more logs just cd into the /var/log directory and start using, catlesstailgrepfind or any other tool to view and search.

Linux Diagnostics

This is a set of tools designed for technical/advanced users who wish to know more about their hardware and related components for servicing. This tool comes with various commands namely lsvpd, lscfg, lsmcode, lsvio & vpdupdate. Let’s proceed below to know more about them.

What are these diagnostic tools?


It is a hardware inventory database program designed to re-implement AIX’s (IBM version of UNIX) related commands.

  • lsvpd lists all the VPD associated with the FRU
  • lscfg list the hardware configuration
  • lsmcode list the microcode and firmware levels
  • lsvio lists virtual I/O adapters and devices
  • while vpdupdate updates the database of VPD

So what is VPD?

​Vital Product Data contains information about your hardware or software. They include the configuration such as serial numbers, manufacturers, part numbers, etc.

What is FRU?

​Field Replaceable Unit refers to those components of the Circuit board in which any faulty part can be replaced by a technician or non-technician lacking deep knowledge about the hardware.

Installing Linux diagnostic tools

​As of now, the tool is not available in the official Ubuntu repository but hey good news! The authors made a *.deb package version for you so you don’t have the headache of compiling it yourself. Head over here and download the package.

Then fire up your terminal and cd to the required directory and key in this command –

sudo dpkg -i lsvpd_1.3.3-1_i386.deb
install lsvpd linux diagnostic tool

Running the tool

​Now let’s run one of the tools: lsvpd; which is a viable one for now. But before that you have to know all the above-mentioned tools require root privileges, then again you have to update the VPD at least once. Alright then –

sudo vpdupdate
sudo lsvpd ​

We have the following field:

how to run lsvpd tool

​The one highlighted green stands alone from other fields and the blue arrowed below shows similar output associated with various hardware.

Well, that alone is not understandable and the documentation is read as “machine-readable” so here are some of the few terms –

  • TM stands for Model of the hardware
  • SE is the serial
  • MF is the manufacturer of the hardware

Passing arguments

​If you want more output then you have to pass the “debug” argument to lsvpd this way –

all lsvpd tool arguments
sudo lsvpd -D ​

If you want output that distinguishes a global VPD (********) and partition private (========) then –

lsvpd -m argument

sudo lsvpd -m

​You could also pass hardware serial and type model explicitly to get info about it using -s and -t respectively. However, that is not recommended.

And for the nerdy users, you can point your VPD database file to a different directory bypassing –

path=Database_directory argument.

Running the other ls… tools

​Here is a sample running lscfg tool –

sudo lscfg
running lscfg tool

​And a sample screenshot running lsmcode with debugging enabled.

sudo lsmcode -D
lamcode -D

Trade-off

​Installing and living with the Linux Diagnostic Tools is not pretty though because:

  • vpdupdate will run at startup. So get ready to delay your boot-up time by 4-6 seconds.
  • you might encounter this error dialog at every boot-up.
ubuntu system program problem detected

​And later you’ll have to find a way out of this error while updating VPD using vpdupdate tool.

vpdupdate tool

​The solution I found out was to archive the VPD database in this way. sudo vpdupdate -a ​Otherwise, you could also delete all the contents of /var/lib/lsvpd/ and that helps too. Don’t forget to rerun vpdupdate tool again.

Conclusion

​This is pretty much about it. In case you wish to learn more about a tool, it’s best you refer to it using man. Otherwise here are the two websites I recommend you to read: lsvpd and lscfg.