-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux_dmesg.txt
190 lines (119 loc) · 5.29 KB
/
linux_dmesg.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
## dmesg:
https://thenewstack.io/a-new-linux-memory-controller-promises-to-save-lots-of-ram/
The Linux kernel is the core of the operating system that controls
access to the system resources, such as CPU, I/O devices, physical
memory, and file systems. The kernel writes various messages to the
kernel ring buffer during the boot process, and when the system is
running. These messages include various information about the
operation of the system.
The kernel ring buffer is a portion of the physical memory that holds
the kernel’s log messages. It has a fixed size, which means once
the buffer is full, the older logs records are overwritten.
The dmesg command-line utility is used to print and control the
kernel ring buffer in Linux and other Unix-like operating systems. It
is useful for examining kernel boot messages and debugging hardware
related issues.
In this tutorial, we’ll cover the basics of the dmesg command.
Using the dmesg Command
The syntax for the dmesg command is as follows:
dmesg [OPTIONS]
Copy
When invoked without any options dmesg writes all messages from the
kernel ring buffer to the standard output:
dmesg
Copy
By default, all users can run the dmesg command. However, on some
systems, the access to dmesg may be restricted for non-root users. In
this situation, when invoking dmesg you will get an error message
like below:
dmesg: read kernel buffer failed: Operation not permitted
Copy
The kernel parameter kernel.dmesg_restrict specifies whether
unprivileged users can use dmesg to view messages from the kernel’s
log buffer. To remove the restrictions, set it to zero:
sudo sysctl -w kernel.dmesg_restrict=0
Copy
Usually, the output contains a lot of lines of information, so only
the last part of the output is viewable. To see one page at a time,
pipe the output to a pager utility such as less or more:
dmesg --color=always | less
Copy
The --color=always is used to preserve the colored output.
If you want to filter the buffer messages, use grep. For example, to
view only the USB related messages, you would type:
dmesg | grep -i usb
Copy
dmesg reads the messages generated by the kernel from the /proc/kmsg
virtual file. This file provides an interface to the kernel ring
buffer and can be opened only by one process. If syslog process is
running on your system and you try to read the file with cat, or
less, the command will hang.
The syslog daemon dumps kernel messages to /var/log/dmesg, so you can
also use that log file:
cat /var/log/dmesg
Copy
Formating dmesg Output
The dmesg command provides a number of options that help you format
and filter the output.
One of the most used options of dmesg is -H (--human), which enables
the human-readable output. This option pipe the command output into a
pager:
dmesg -H
Copy
To print human-readable timestamps use the -T (--ctime) option:
dmesg -T
Copy
[Mon Oct 14 14:38:04 2019] IPv6: ADDRCONF(NETDEV_CHANGE): wlp1s0: link becomes ready
Copy
The timestamps format can also be set using the --time-format <format> option, which can be ctime, reltime, delta, notime, or iso. For example to use the delta format you would type:
dmesg --time-format=delta
Copy
You can also combine two or more options:
dmesg -H -T
Copy
To watch the output of the dmesg command in real-time use the -w (--follow) option:
dmesg --follow
Copy
Filtering dmesg Output
You can restrict the dmesg output to given facilities and levels.
The facility represents the process that created the message. dmesg supports the following log facilities:
kern - kernel messages
user - user-level messages
mail - mail system
daemon - system daemons
auth - security/authorization messages
syslog - internal syslogd messages
lpr - line printer subsystem
news - network news subsystem
The -f (--facility <list>) option allows you to limit the output to specific facilities. The option accepts one or more comma-separated facilities.
For example, to display only the kernel and system daemons messages you would use:
dmesg -f kern,daemon
Copy
Each log message is associated with a log level that shows the importance of the message. dmesg supports the following log levels:
emerg - system is unusable
alert - action must be taken immediately
crit - critical conditions
err - error conditions
warn - warning conditions
notice - normal but significant condition
info - informational
debug - debug-level messages
The -l (--level <list>) option restricts the output to defined levels. The option accepts one or more comma-separated levels.
The following command displays only the error and critical messages:
dmesg -l err,crit
Copy
Clearing the Ring Buffer
The -C (--clear) option allows you to clear the ring buffer:
sudo dmesg -C
Copy
Only root or users with sudo privileges can clear the buffer.
To print the buffer contents before clearing use the -c (--read-clear) option:
sudo dmesg -c
Copy
If you want to save the current dmesg logs in a file before clearing it, redirect the output to a file:
dmesg > dmesg_messages
Copy
Conclusion
The dmesg command allows you to view and control the kernel ring buffer. It can be very useful when troubleshooting kernel or hardware issues.
Type man dmesg in your terminal for information about all available dmesg options.
If you have any questions or feedback, feel free to leave a comment.