7

I recently had some trouble with a wireless card, and an online forum suggested searching dmesg with grep firmware. That helped, I was able to find the problem immediately! However, the previous hour was spent looking at dmesg and I couldn't identify anything relevant due to the overwhelming quantity of information!

How does on know what to grep for in dmesg?

Sure, this was a hardware issue but I myself would never have thought to grep for the string "firmware". For someone not intimately familiar with the output of dmesg, how might I make some educated guesses about what to grep for?

dotancohen
  • 15,864
  • 3
    I'm afraid that this question is not answerable as is. There're thousands of various stuff you can look for. – yo' Aug 11 '14 at 16:17
  • 3
    Thousands, yes, but surely there may be some guidelines. There are thousands of words in English, but there are guidelines on how to google a problem! – dotancohen Aug 11 '14 at 16:23
  • @dotancohen Can you please elaborate on the issue with the card? Also, you can try lspci -vnn | grep -i net taken from this answer in super user – Simply_Me Aug 11 '14 at 16:40
  • It seems that what you are looking for is some sort of documentation on the output of dmesg. Is this correct? – ctrl-alt-delor Aug 11 '14 at 17:07
  • @richard: That is what I was googling for, when I decided that I had better ask this question! I'm looking for ideas about how to build the intuition about what to grep for. – dotancohen Aug 11 '14 at 18:25
  • @Simply_Me: I've already resolved the issue with the wireless card, but I realized that I don't have the intuition to know what to grep for. Thus, here we are as I ask for guidelines. – dotancohen Aug 11 '14 at 18:26
  • 1
    Take a look at this maybe. The question of which lexicon is used with messages in the logs is related. You can explore it! –  Aug 11 '14 at 18:55
  • WARNING: dmesg reads from the kernel ring buffer, which means that if there are lot of messages the older ones get overwritten. Generally items that would be retrieval via dmesg get written via syslog (if appropriately configured) to the system log file (usually /var/log/messages). – mdpc Aug 11 '14 at 18:58
  • @illuminÉ: Great link, thank you! I will definitely get some ideas from the script. – dotancohen Aug 11 '14 at 19:02
  • @dotancohen thankyou for clarifying. – ctrl-alt-delor Aug 12 '14 at 10:20

1 Answers1

16

Something like this would be useful:

dmesg | grep -iC 3 "what you are looking for" 

For example, if looking for your video card, you could try:

dmesg | grep -iC 3 "video"

Or:

dmesg | grep -iC 3 "graphics" 

The C 3 flag will print 3 lines before and after the matched string, just to give you some context on what the results are. But as @tohecz said, there are thousands of possibilities.

All depends on what you are looking for... sound, wifi, usb, serial, reader....

If you expect a usb key to appear in there, you can try grepping for /dev/sd.


Just found this page, that contains sound advice on how to grep stuff in there:

Because of the length of the output of dmesg, it can be convenient to pipe its output to grep, a filter which searches for any lines that contain the string (i.e., sequence of characters) following it. The -i option can be used to tell grep to ignore the case (i.e., lower case or upper case) of the letters in the string. For example, the following command lists all references to USB (universal serial bus) devices in the kernel messages:

dmesg | grep -i usb

And the following tells dmesg to show all serial ports (which are represented by the string tty):

dmesg | grep -i tty

The dmesg and grep combination can also be used to show how much physical memory (i.e., RAM) is available on the system:

dmesg | grep -i memory

The following command checks to confirm that the HDD(s) is running in DMA (direct memory access) mode:

dmesg | grep -i dma
jimm-cl
  • 1,128