[Linux]dmesg 명령어로 커널 링 버퍼(커널 메세지 버퍼)를 조회하는 방법

dmesg 명령어는 리눅스 시스템의 커널 링 버퍼를 조회하여 부팅과 관련된 로그 및 커널 메시지를 출력하는 명령어입니다. “dmesg”는 “display message”의 줄임말로, 커널이 부팅 중 및 운영 중에 생성한 메시지를 표시합니다. 이 명령어를 통해 시스템의 부팅 문제, 하드웨어 감지, 드라이버 로딩, 에러 메시지 등 다양한 정보를 확인할 수 있습니다. 즉, dmesg는 실시간으로 커널 링 버퍼의 내용을 가져와 화면에 표시합니다.

커널 링 버퍼가 무엇인가?

부팅 프로세스 중에 콘솔은 시스템 시작의 초기 단계에 대한 많은 중요한 정보를 제공합니다. 초기 메시지의 손실을 방지하기 위해 커널은 링 버퍼라는 것을 활용합니다. 이 버퍼는 부팅 메시지를 포함하여 커널 코드 내의 printk() 함수에 의해 생성된 모든 메시지를 저장합니다. 그런 다음 커널 링 버퍼의 메시지를 읽고 영구 저장소(예: syslog 서비스)의 로그 파일에 저장합니다.(“한눈에 보이는 리눅스 로그(Linux Log) 총정리, 그리고 관련 명령어” 글 참고
위에서 언급한 버퍼는 고정된 크기를 갖는 순환 데이터 구조(cyclic data structure)이며 커널에 하드 코딩되어 있습니다. 사용자는 dmesg 명령이나 /var/log/boot.log 파일을 통해 커널 링 버퍼에 저장된 데이터를 표시할 수 있습니다. 링 버퍼가 가득 차면 새 데이터가 이전 데이터를 덮어씁니다.

커널 링 버퍼를 조회하는 dmesg 명령어의 사용법을 알아보겠습니다.

dmesg [options] 형식으로 커널 링 버터를 조회합니다. 주요 옵션으로는,

-C, --clear: 커널 링 버퍼를 비우기
-c, --read-clear : 커널 닝 버퍼를 비우기 전에 화면에 출력
-H, --human : human readable
-k, --kernel : 커널 메시지를 출력
-f, --facility <list> : 지정한 facility들에 대한 메시지 출력
-l, --level <list> : 지정한 level들에 대한 메시지 출력
-L, --color : Colored Messages 출력
-S, --syslog : /dev/kmsg 대신에 syslog를 통해 메시지 출력
-x, --decode : facility와 level을 텍스트로 전환
-T, --ctime : human readable timestamp
-t, --notime : 타임 스탬프를 출력하지 않음

Supported log facilities:
    kern - kernel messages
    user - random user-level messages
    mail - mail system
  daemon - system daemons
    auth - security/authorization messages
  syslog - messages generated internally by syslogd
     lpr - line printer subsystem
    news - network news subsystem

Supported log levels (priorities):
   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

주로 사용하는 방법은 -T, -x와 함께 –facility와 –level를 조합하여 출력합니다.

[root@centos8 log]# dmesg -T -x --level=emerg,alert,crit,err,warn
kern  :warn  : [Wed Nov 22 00:29:40 2023] acpi PNP0A03:00: fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.
kern  :crit  : [Wed Nov 22 00:29:41 2023] Warning: Unmaintained hardware is detected:  e1000:100E:8086 @ 0000:00:03.0
kern  :err   : [Wed Nov 22 00:29:41 2023] [drm:vmw_host_printf [vmwgfx]] *ERROR* Failed to send host log message.
kern  :crit  : [Wed Nov 22 00:29:41 2023] Warning: Unmaintained hardware is detected:  e1000:100E:8086 @ 0000:00:08.0
kern  :warn  : [Wed Nov 22 00:29:43 2023] printk: systemd: 16 output lines suppressed due to ratelimiting
kern  :warn  : [Fri Nov 24 10:54:49 2023] hrtimer: interrupt took 5416645 ns

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다