7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dmesg について

Posted at

勉強前イメージ

カーネルのログってくらいしか知らなかったし、
それ以上の情報もない....

調査

dmesgについて

dmesgはlinuxがブートからファイルシステムがマウントされるまでのログが保存されています。

dmesgは dmesgコマンド/var/log/dmesgファイル がありますが、/var/log/dmesgはdmesgコマンドによって作られます。
違いは以下になります。

  • dmesgコマンド → ブートされる際のメッセージ
  • /var/log/dmesg → 循環ブッファなので起動時にカーネルメッセージが消えないように内容を書き出している

確認方法

dmesgコマンド を使用します。
基本的には以下のように出力されます。

dmesg
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.0-1160.24.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Thu Apr 8 19:51:47 UTC 2021
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.24.1.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet LANG=ja_JP.UTF-8
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable

-Tオプション を付けるとタイムスタンプも表示できます。

dmesg -T
[日 12月  5 23:35:40 2021] Initializing cgroup subsys cpuset
[日 12月  5 23:35:40 2021] Initializing cgroup subsys cpu
[日 12月  5 23:35:40 2021] Initializing cgroup subsys cpuacct
[日 12月  5 23:35:40 2021] Linux version 3.10.0-1160.24.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Thu Apr 8 19:51:47 UTC 2021
[日 12月  5 23:35:40 2021] Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.24.1.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet LANG=ja_JP.UTF-8
[日 12月  5 23:35:40 2021] e820: BIOS-provided physical RAM map:
[日 12月  5 23:35:40 2021] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[日 12月  5 23:35:40 2021] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[日 12月  5 23:35:40 2021] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[日 12月  5 23:35:40 2021] BIOS-e820: [mem 0x0000000000100000-0x00000000dffeffff] usable
[日 12月  5 23:35:40 2021] BIOS-e820: [mem 0x00000000dfff0000-0x00000000dfffffff] ACPI data

例えばUSBの確認をしたい際は以下になります。

dmesg -T | grep usb
[日 12月  5 23:35:41 2021] usbcore: registered new interface driver usbfs
[日 12月  5 23:35:41 2021] usbcore: registered new interface driver hub
[日 12月  5 23:35:41 2021] usbcore: registered new device driver usb
[日 12月  5 23:35:42 2021] usb usb1: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 3.10
[日 12月  5 23:35:42 2021] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[日 12月  5 23:35:42 2021] usb usb1: Product: OHCI PCI host controller
[日 12月  5 23:35:42 2021] usb usb1: Manufacturer: Linux 3.10.0-1160.24.1.el7.x86_64 ohci_hcd
[日 12月  5 23:35:42 2021] usb usb1: SerialNumber: 0000:00:06.0
[日 12月  5 23:35:42 2021] usbcore: registered new interface driver usbserial_generic

重要なメッセージだけ出力する際は -lオプション をつけることができ、上から致命的な内容に絞ることが出来ます。

  • emerge
  • alert
  • crit
  • err
  • warn
  • notice
  • info
  • debug

例えば ctit までに絞りたければ以下のコマンドで確認することが出来ます。

dmesg -l emerg,alert,crit,err
[    2.760601] [drm:vmw_host_log [vmwgfx]] *ERROR* Failed to send host log message.
[    2.761441] [drm:vmw_host_log [vmwgfx]] *ERROR* Failed to send host log message.
[16824.418760] INFO: rcu_sched detected stalls on CPUs/tasks: { 1} (detected by 0, t=81812 jiffies, g=19539, c=19538, q=98)
[31580.903803] e1000 0000:00:03.0 enp0s3: Reset adapter
[64891.713895] INFO: rcu_sched detected stalls on CPUs/tasks: { 1} (detected by 0, t=1255631 jiffies, g=381962, c=381961, q=146)
[64891.714492] INFO: rcu_sched detected stalls on CPUs/tasks: { 1} (detected by 0, t=5653678 jiffies, g=381962, c=381961, q=146)
[80772.937145] INFO: rcu_sched self-detected stall on CPU { 0}  (t=995865 jiffies g=385453 c=385452 q=19)

勉強後イメージ

過去に何回かUSBの確認するために確認したことあるけど、
時間も見れるのかー
知らなかった・・・・見れないの不便だなとは思ってた

参考

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?