Key Takeaways
- The dmesg bid allows you to reappraisal messages stored successful nan Linux ringing buffer, providing insights into hardware errors and startup issues.
- You tin customize nan dmesg bid by removing nan request for sudo, forcing colour output, utilizing human-readable timestamps, watching unrecorded events, retrieving nan past messages, searching for circumstantial terms, and filtering by log levels aliases installation categories.
The dmesg bid lets you adjacent into nan hidden world of nan Linux startup processes. Review and show hardware instrumentality and driver messages from nan kernel's ain ringing buffer pinch "the responsibility finder's friend."
How Linux's Ring Buffer Works
In Linux and Unix-like computers, booting and startup are 2 chopped phases of nan series of events that return spot erstwhile nan machine is powered on.
The footwear processes (BIOS aliases UEFI, MBR, and GRUB) return nan initialization of nan strategy to nan constituent wherever nan kernel is loaded into representation and connected to nan first ramdisk (initrd aliases initramfs), and systemd is started.
The startup processes past prime up nan baton and complete nan initialization of nan operating system. In nan very early stages of initialization, logging daemons specified arsenic syslogd aliases rsyslogd are not yet up and running. To debar losing notable correction messages and warnings from this shape of initialization, nan kernel contains a ring buffer that it uses arsenic a connection store.
A ringing buffer is simply a representation abstraction reserved for messages. It is elemental successful design, and of a fixed size. When it is full, newer messages overwrite nan oldest messages. Conceptually it tin beryllium thought of arsenic a "circular buffer."
The kernel ringing buffer stores accusation specified arsenic nan initialization messages of instrumentality drivers, messages from hardware, and messages from kernel modules. Because it contains these low-level startup messages, nan ringing buffer is simply a bully spot to commencement an investigation into hardware errors aliases different startup issues.
That is wherever nan dmesg bid comes in.
What is The dmesg Command?
The dmesg bid allows you to reappraisal nan messages that are stored successful nan ringing buffer. By default, you request to usage sudo to usage dmesg.
sudo dmesgAll of nan messages successful nan ringing buffer are displayed successful nan terminal window.
That was a deluge. Obviously, what we request to do is pipe it done less:
sudo dmesg | lessNow we tin scroll done nan messages looking for items of interest.
You tin usage nan hunt usability wrong little to find and item items and position you're willing in. Start nan hunt usability by pressing nan guardant slash cardinal "/" successful less.
Removing nan Need for sudo
If you want to debar having to usage sudo each clip you usage dmesg, you tin usage this command. But, beryllium aware: it lets anyone pinch a personification relationship your machine usage dmesg without having to usage sudo.
sudo sysctl -w kernel.dmesg_restrict=0Forcing Color Output
By default, dmesg will astir apt beryllium configured to nutrient colored output. If it isn't, you tin show dmesg to colorize its output utilizing nan -L (color) option.
sudo dmesg -LTo unit dmesg to ever default to a colorized show usage this command:
sudo dmesg --color=alwaysHuman Timestamps
By default, dmesg usage a timestamp notation of seconds and nanoseconds since nan kernel started. To person this rendered successful a much human-friendly format, usage nan -H (human) option.
sudo dmesg -HThis causes 2 things to happen.
- The output is automatically displayed successful less.
- The timestamps show a timestamp pinch nan day and time, pinch a infinitesimal resolution. The messages that occurred successful each infinitesimal are branded pinch nan seconds and nanoseconds from nan commencement of that minute.
Human Readable Timestamps pinch dmesg
If you don't require nanosecond accuracy, but you do want timestamps that are easier to publication than nan defaults, usage nan -T (human readable) option. (It's a small confusing. -H is nan "human" option, -T is nan "human readable" option.)
sudo dmesg -TThe timestamps are rendered arsenic modular dates and times, but nan solution is lowered to a minute.
Everything that happened wrong a azygous infinitesimal has nan aforesaid timestamp. If each you're bothered astir is nan series of events, this is bully enough. Also, statement that you're dumped backmost astatine nan bid prompt. This action doesn't automatically invoke less.
Watching Live Events pinch dmesg
To spot messages arsenic they get successful nan kernel ringing buffer, usage nan --follow (wait for messages) option. That condemnation mightiness look a small strange. If nan ringing buffer is utilized to shop messages from events that return spot during nan startup sequence, really tin unrecorded messages get successful nan ringing buffer erstwhile nan machine is up and running?
Anything that causes a alteration successful nan hardware connected to your machine will origin messages to beryllium sent to nan kernel ringing buffer. Update aliases adhd a kernel module, and you'll spot ringing buffer messages astir those changes. If you plug successful a USB thrust aliases link aliases disconnect a Bluetooth device, you'll spot messages successful nan dmesg output. Even virtual hardware will origin caller messages to look successful nan ringing buffer. Fire up a virtual machine, and you'll spot caller accusation arriving successful nan ringing buffer.
sudo dmesg --followNote that you are not returned to nan bid prompt. When caller messages look they are displayed by dmesg astatine nan bottommost of nan terminal window.
Even mounting a CD-ROM disk is seen arsenic a change, because you've grafted nan contents of nan CD-ROM disk onto nan directory tree.
To exit from nan real-time feed, deed Ctrl+C.
Retrieve nan Last Ten Messages
Use nan tail bid to retrieve nan past ten kernel ringing buffer messages. Of course, you tin retrieve immoderate number of messages. Ten is conscionable our example.
sudo dmesg | past -10The past 10 messages are retrieved and listed successful nan terminal window.
Searching For Specific Terms
Pipe nan output from dmesg done grep to hunt for peculiar strings aliases patterns. Here we're utilizing nan -i (ignore case) action truthful that nan lawsuit of matching strings is disregarded. our results will see "usb" and "USB" and immoderate different operation of lowercase and uppercase.
sudo dmesg | grep -i usbThe highlighted hunt results are successful uppercase and lowercase.
We tin isolate nan messages that incorporate references to nan first SCSI difficult disk connected nan strategy sda. (Actually, sda is besides utilized nowadays for the first SATA difficult drive, and for USB drives.)
sudo dmesg | grep -i sdaAll of nan messages that mention sda are retrieved and listed successful nan terminal window.
To make grep hunt for aggregate position astatine once, usage nan -E (extend regular expression) option. You must supply nan hunt position wrong a quoted drawstring pinch tube "|" delimiters betwixt nan hunt terms:
sudo dmesg | grep -E "memory|tty|dma"Any connection that mentions immoderate of nan hunt position is listed successful nan terminal window.
Using Log Levels
Every connection logged to nan kernel ringing buffer has a level attached to it. The level represents nan value of nan accusation successful nan message. The levels are:
- emerg: System is unusable.
- alert: Action must beryllium taken immediately.
- crit: Critical conditions.
- err: Error conditions.
- warn: Warning conditions.
- notice: Normal but important condition.
- info: Informational.
- debug: Debug-level messages.
We tin make dmesg extract messages that lucifer a peculiar level by utilizing nan -l (level) action and passing nan sanction of nan level arsenic a command-line parameter. To spot only "informational" level messages, usage this command:
sudo dmesg -l infoAll of nan messages that are listed are informational messages. They don't incorporate errors aliases warnings, conscionable useful notifications.
Combine 2 aliases much log levels successful 1 bid to retrieve messages of respective log levels:
sudo dmesg -l debug,noticeThe output from dmesg is simply a blend of messages of each log level:
The Facility Categories
The dmesg messages are grouped into categories called "facilities." The database of accommodation is:
- 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.
We tin inquire dmesg to select its output to only show messages successful a circumstantial facility. To do so, we must usage nan -f (facility) option:
sudo dmesg -f daemondmesg lists each of nan messages relating to daemons successful nan terminal window.
As we did pinch nan levels, we tin inquire dmesg to database messages from much than 1 installation astatine once:
sudo dmesg -f syslog, daemonThe output is simply a operation of syslog and daemon log messages.
Combining Facility and Level
The -x (decode) action makes dmesg show nan installation and level arsenic human-readable prefixes to each line.
sudo dmesg -xThe installation and level tin beryllium seen astatine nan commencement of each line:
The first highlighted conception is simply a connection from nan "kernel" installation pinch a level of "notice." The 2nd highlighted conception is simply a connection from nan "kernel" installation pinch a level of "info."
That's Great, But Why?
In a nutshell, responsibility finding.
If you are having issues pinch a portion of hardware not being recognized aliases not behaving properly, dmesg whitethorn propulsion immoderate ray connected nan issue.
- Use dmesg to reappraisal messages from nan highest level down done each little level, looking for immoderate errors aliases warnings that mention nan hardware item, aliases whitethorn person a base connected nan issue.
- Use dmesg to hunt for immoderate mention of nan due installation to spot whether they incorporate immoderate useful information.
- Pipe dmesg done grep and look for related strings aliases identifiers specified arsenic merchandise shaper aliases exemplary numbers.
- Pipe dmesg done grep and look for generic position for illustration "gpu" aliases "storage", aliases position specified arsenic "failure", "failed" aliases "unable".
- Use nan --follow action and watch dmesg messages successful real-time.
Happy hunting.