【Linux】Linux-dmesgコマンドを一歩一歩学ぶ(74)


00.目次
文書ディレクトリ
  • 00. ディレクトリ
  • 01. コマンド概要
  • 02. コマンドフォーマット
  • 03. 共通オプション
  • 04. 参考例
  • 05. 付録
  • 01.コマンドの概要
    dmesgコマンドは、カーネルのリングバッファをチェックおよび制御するために使用されます.kernelは、ring bufferに電源投入情報を格納します.電源を入れたときに情報を表示できない場合は、dmesgを使用して表示します.起動情報は/var/log/dmesgファイルに保存されます.
    02.コマンドフォーマット
     dmesg [  ]
    

    03.一般的なオプション
      :
     -C, --clear                          (ring butter)
     -c, --read-clear                     
     -D, --console-off                    
     -d, --show-delta                        
     -e, --reltime                              
     -E, --console-on                     
     -F, --file <  >                         
     -f, --facility <  >                  
     -H, --human                       
     -k, --kernel                      
     -L, --color                       
     -l, --level <  >                
     -n, --console-level <  >              
     -P, --nopager                              
     -r, --raw                            
     -S, --syslog                     syslog(2)    /dev/kmsg
     -s, --buffer-size <  >                     
     -T, --ctime                         (      
                                    SUSPEND/RESUME      )
     -t, --notime                        
     -u, --userspace                     
     -w, --follow                     
     -x, --decode                               
    
     -h, --help             
     -V, --version           
     
            :
        kern -     
        user -         
        mail -     
      daemon -       
        auth -   /    
      syslog - syslogd        
         lpr -        
        news -        
    
           (   ):
       emerg -       
       alert -         
        crit -     
         err -     
        warn -     
      notice -         
        info -   
       debug -        
    

    04.参考例
    4.1カーネルにロードされたすべてのドライバを一覧表示dmesgコマンドデバイスのトラブルシューティングは非常に重要です.dmesgコマンドの助けでハードウェアの接続または切断操作を行うと、ハードウェアの検出または切断に関する情報が表示されます.dmesgコマンドは、LinuxおよびUnixベースの多くのオペレーティングシステムで使用できます.
    [root@itcast ~]# dmesg 
    

    4.2検出されたすべてのハードウェアのリスト
    カーネルで検出されたすべてのハードディスクデバイスを表示するには、grepコマンドを使用してsdaキーワードを検索します.
    [root@itcast ~]# dmesg | grep sda
    [    3.051454] sd 0:0:0:0: [sda] 209715200 512-byte logical blocks: (107 GB/100 GiB)
    [    3.051559] sd 0:0:0:0: [sda] Write Protect is off
    [    3.051562] sd 0:0:0:0: [sda] Mode Sense: 61 00 00 00
    [    3.051700] sd 0:0:0:0: [sda] Cache data unavailable
    [    3.051702] sd 0:0:0:0: [sda] Assuming drive cache: write through
    [    3.053408]  sda: sda1 sda2 sda3
    [    3.054299] sd 0:0:0:0: [sda] Attached SCSI disk
    [    3.558354] XFS (sda3): Mounting V5 Filesystem
    [    4.188185] XFS (sda3): Ending clean mount
    [   12.636995] Adding 4194300k swap on /dev/sda2.  Priority:-1 extents:1 across:4194300k FS
    [   12.922553] XFS (sda1): Mounting V5 Filesystem
    [   14.708567] XFS (sda1): Ending clean mount
    [root@itcast ~]# 
    

    4.3 dmesgコマンドの最初の10行のログのみを出力する
    [root@itcast ~]# dmesg | head
    [    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-862.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018
    [    0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.10.0-862.el7.x86_64 root=UUID=6fa6fd5d-0115-4ec3-b993-19322c836a32 ro rhgb quiet LANG=zh_CN.UTF-8
    [    0.000000] Disabled fast string operations
    [    0.000000] e820: BIOS-provided physical RAM map:
    [    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable
    [    0.000000] BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved
    [    0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
    [root@itcast ~]# 
    

    4.4 dmesgコマンドの最後の10行のログのみ出力
    [root@itcast ~]# dmesg | tail
    [117804.072174] IPv6: ADDRCONF(NETDEV_UP): ens33: link is not ready
    [117804.078051] e1000: ens33 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
    [117804.079860] IPv6: ADDRCONF(NETDEV_UP): ens33: link is not ready
    [117804.079873] IPv6: ADDRCONF(NETDEV_CHANGE): ens33: link becomes ready
    [117831.955328] psmouse serio1: VMMouse at isa0060/serio1/input0 lost synchronization, throwing 2 bytes away.
    [117833.738722] psmouse serio1: resync failed, issuing reconnect request
    [124926.680233] IPv6: ADDRCONF(NETDEV_UP): ens33: link is not ready
    [124926.693764] IPv6: ADDRCONF(NETDEV_UP): ens33: link is not ready
    [124932.700536] e1000: ens33 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
    [124932.701799] IPv6: ADDRCONF(NETDEV_CHANGE): ens33: link becomes ready
    [root@itcast ~]# 
    

    4.5特定の文字列を含む検出されたハードウェアの検索
    「dmesg」コマンドの出力が長すぎるため、特定の文字列を検索することは非常に困難です.したがって、「usb」「dma」「tty」「memory」などの文字列を含むログ行をフィルタリングする必要がある.grepコマンドの「-i」オプションは、大文字と小文字を無視することを示します.
    [root@itcast ~]# dmesg | grep -i usb
    [root@itcast ~]# dmesg | grep -i dma
    [root@itcast ~]# dmesg | grep -i tty
    [root@itcast ~]# dmesg | grep -i memory
    

    4.6 dmesgバッファ・ログのクリア
    [root@itcast ~]# dmesg -c
    

    dmesgのログを空にするには、次のコマンドを使用します.このコマンドは、dmesgリングバッファのログを空にします.ただし、'/var/log/dmesg'ファイルに格納されているログは依然として表示できます.どのデバイスに接続してもdmesgログ出力が発生します.
    4.7リアルタイム監視dmesgログ出力
    [root@itcast ~]# tail -f /var/log/dmesg
    [   14.708567] XFS (sda1): Ending clean mount
    [   14.880408] floppy0: no floppy controllers found
    [   14.880489] work still pending
    [   14.988537] device-mapper: uevent: version 1.0.3
    [   14.988785] device-mapper: ioctl: 4.37.0-ioctl (2017-09-20) initialised: [email protected]
    [   15.604238] RPC: Registered named UNIX socket transport module.
    [   15.604240] RPC: Registered udp transport module.
    [   15.604241] RPC: Registered tcp transport module.
    [   15.604242] RPC: Registered tcp NFSv4.1 backchannel transport module.
    [   15.783627] type=1305 audit(1563324893.915:3): audit_pid=581 old=0 auid=4294967295 ses=4294967295 res=1
    
    //  
    [root@itcast ~]# watch "dmesg |tail"
    

    05.付録
    参考:【Linux】一歩一歩Linuxシリーズチュートリアルのまとめ
    参照先:https://linux.cn/article-3587-1.html
    ~]# watch “dmesg |tail”
    
    
    
    ## 05.   
    
      :[【Linux】     Linux      ](https://blog.csdn.net/dengjin20104042056/article/details/94669639)
    
      :https://linux.cn/article-3587-1.html