Are you having problems with the distribution you just installed? Or after an upgrade? Maybe the display server isn’t working or network interface isn’t showing up. There can be hundreds of problems that you might encounter. The question is what should you do when you face such an issue? First, you’ll need to research the problem by yourself. If that doesn’t work, then you should go to your distribution’s forum or there can be some very good Linux support groups at Facebook. But whatever place you choose, stepping in and posting “My WiFi isn’t working, what should I do?” isn’t gonna do any good neither to the people in the group nor to you. You need to give them some basic details, error reports, logs so that they can understand what’s wrong. But how’re you going to achieve that? Don’t worry. I’m here to help you help the group/forum members help you! Don’t get confused, just continue reading -
I’ll be mentioning 5 commands that’ll help you get those reports. But before talking about those I’d like to take a bit of your time and talk about bash pipelines. If you already know what that is, skip this part. Pipeline is a bash feature that lets us forward one command’s output to another commands parameter. let’s use a simple echo example :
$ echo “lsb”
This will print lsb on the display. Now what if we echo a big big sentence, and we’re asked to find whether that line has the word “Linux” in it or not. This is when a pipeline comes in handy. There’s another command named grep, this prints characters that match a certain parameter(pattern) passed to it. The format of grep is
$ grep pattern FILE
A pattern can be any string. We can use grep and pipelines to get a very convenient log extraction. Let’s see an example :
$ echo “This is Least Significant Bits \You’re reading one of our posts” | grep Significant
What happens when you press enter? The output will have “Significant” highlighted. What happened here is, the output of the echo command, the full string, got forwarded as the second parameter to the grep command. So if we see that above command in stages, this is what’s happening :
stage 1: echo “This is Least Significant Bits \You’re reading one of our posts”stage 2: grep Significant “This is Least Significant Bits \You’re reading one of our posts”
The second stage doesn’t really work that way, because the second param of grep is a file, and here I’ve written a string. So in a pipe command what happens is after the echo command, the output, as it’s not getting printed right then and there, gets into the buffer cache, and grep reads that from the buffer.
Now that we now know how pipelines and grep work, we can talk about those commands that we mentioned earlier.
1: dmesg
According to the manual of the dmesg command,
dmesg is used to examine or control the kernel ring buffer. The default action is to display all messages from the kernel ring buffer.
So what is kernel ring buffer? A kernel ring buffer is a type of buffer that records operations related to the kernel. Why’s this important? Well, in easy words, the kernel loads the drivers and modules on boot, so through dmesg you’ll be able to look in detail, whether the necessary drivers and modules are loaded or not.
Although there are a lot of options for this command, you won’t need most of them. This command is mostly used with a grep pipe like this :
$ dmesg | grep something
If you know what driver or module you need loaded, you can search for that here. For example, suppose you’re using amdgpu display driver, you can check whether the driver and module are loaded on boot or not, by
$ dmesg | grep amdgpu
You can also use lsmod command to list all the listed modules, and use grep pipe to filter only the modules that concern you or the issue. Use it like this,
$ lsmod | grep amdgpu
Although lsmod tells you if the modules are loaded or not, it doesn’t mention any error or reason why something isn’t loaded. You can also shortlist if there’s any error or warning in the kernel ring buffer by
$ dmesg | grep -i warning$ dmesg | grep -i error
The “-i” makes the pattern matching case-insensitive. So “Warning” and “warning” will be the same. This way you won’t leave anything out.
2: lspci
Chances are, you’ll cross paths with this command a hundred times in your future (If you stick to Linux). This command lists all the connected pci devices. List-PCI, hence lspci. You can use this command to check your VGA controller, network adapter model, the driver that it’s using, module name, all. Here are a couple of useful options for this command -
$ lspci -k // Lists all the devices with the driver in use and modules.$ lspci -v // A verbose output. Gives details about each individual devices. Use this if you’re unsure about what to use.$ lspci -vv // More verbose than the previous.$ lspci -vvv // No you won’t really need this, this is a more verbose output than the previous.
More on this command later on this article.
3: lshw
List-Hardware — hence lshw. As the name suggests, this command lists all the hardware that your PC has. This command’s very similar to the previous one. Some important options are,
# lshw -html or lshw -xml // Both outputs the device tree as html and xml page respectively.# lshw -short // Output shows hardware paths.# lshw -businfo // Shows bus information# lshw -C or lshw -class // Shows output specific to hardware classes. More on this later.# lshw -dump filename // Exports the collected information to a file
More on this command later on this article.
4: inxi
This is another handy tool which provides you all the necessary information about your hardware, and much more. Here are some options,
$ inxi -A // Shows audio card information$ inxi -D // Shows your hard drive details$ inxi -C // Shows detailed CPU information$ inxi -F // Shows full inxi output$ inxi -G // Shows graphics card information$ inxi -i // Shows ip addresses, interface names etc
There are too many options for this commands. It’s advised to read the manual. To read the man page, open a terminal, type,
$ man commandname
5 : cat /var/log/filename or cp /var/log/filename ~/
In any system, if anything goes wrong, the first thing anyone should be doing is to look for the logs. Most programs generate a log file, where you can see what went wrong. In Linux, all the log files can be found in /var/log/ location, unless said otherwise(Read the package’s documentation for info). So what you can do is first list all the files present in /var/log/ . You can do this by using
$ ls -al /var/log/
After everything is listed, find the name of the package of which’s log you’re trying to find. Let’s say you’re having issues with xorg server. What you can do is use cat command to see the contents of that file,
# cat /var/log/xorg.0.log
or you can copy the file from that directory to your home directory, then either examine it, or provide that file to the forum/group members. You can also use grep to find errors directly,
# cat /var/log/xorg.0.log | grep error > ~/xorg-error
This will see if the “error” pattern matches with anything in the log file or not, if it does, then it’ll cut that portion and forward that to a file named xorg-error in your home directory. You can also remove the xorg-error file part and just grep error, to just examine the error in the terminal.
So now that you know the basic commands let’s just discuss in short, how and when use those commands. I’ll be showing you two example situations.
Case I :
Let’s say you’ve successfully booted your system, and now, the network connection isn’t working. Here’s what you can do to provide the group/forum members some basic information, so that they can smoothly provide you the solution.
First let’s check whether the network interfaces are detected or not. We can check that with the ip command.
$ ip a
This will list all the network interfaces detected by your OS. If your concern is about any ethernet interface, find interface names like “eth0” or “enp2s0”, they normally start with an “e”. And if you’re concerned about you wireless interface, look for something like “wlan0” or “wlp3s0”. They normally start with a “w”.
Now if you can’t find any interface names, you should check whether your device is detecting your network adapters or not, and if it is, then what are the names of those drivers. We can achieve this by either lspci or lshw. It’s your call. I’ll show you both. With lspci :
$ lspci -v
From here, find “Ethernet” or “Wireless” parts.
With lshw, the process is a bit easier,
# lshw -C Network
This command will list all the hardware components that are a part of the Network class.
You can also use inxi,
$ inxi -N
Now if you can’t find any Networking device from these lists or you found one, but there wasn’t any driver or module mentioned, go to the forum or group, post those outputs, and ask for help. But if you got any device name and driver or module name, it’s time to check whether they were loaded in boot or not using dmesg. Let’s say inxi -N gave you r8168 driver for your ethernet controller (You can also use lsmod before dmesg). Use the following command
$ dmesg | grep r8168
Then post that output in the forum or group.
Case II :
Now, let’s you’re experiencing problem with your display. Maybe xorg isn’t starting, or something else. For this, go to a different tty (I’m considering you are unable to log into any GUI for any possible problem). From there, do the same as before. Collect data about your hardware.
lspci :
$ lspci -v or lspc-k // Find either VGA or Display Controller
lshw :
# lshw -C Display
inxi :
$ inxi -G
If you found any driver or module name, grep that from dmesg output,
$ dmesg | grep displaydriver
Now you can also check for errors inside of the xorg log. Do this by,
# cat /var/log/xorg.0.log | grep error
Now whatever those outputs were, post those along with the question, and trust me, it’ll be much easier to help you.
There you go. A very simple guide to follow that’ll help both, you, to learn more about your hardware, and also the members of the forum or group. Let me clarify one more thing before wrapping this up, all that I mentioned here, are not everything. Those in the group might ask you for some more data. Also, each of those commands has much more to them than just those that I mentioned. But these will help you to start. These will help you learn more about your own system’s hardware. Now if you want to know more about each of those commands, consider reading the man pages by “man commandname”.
Anyway, thank you for reading the whole article. If you’ve read all the way down here, trust me I’m very much grateful. If you liked this article, consider sharing. Sharing will help me a lot. It’ll also help other beginners in getting better help from the forums and groups. Have a nice day. Good Bye. See you later.
Here's a link directed to Medium : https://link.medium.com/ba4fNgE80Y