使用dmesg 查看linux系统启动信息和处理硬件故障

内容目录

最近,使用Nvida TX2的时候,USB 和 以太网口识别不了,上网查了一下如何使用dmesg查看内核信息和定位处理硬件故障,现将其总结成文。


目录

kernel会将启动信息存储在内核环缓冲区中,dmesg则是用于检测和控制内核环缓冲,它可以用来帮助用户了解系统的启动信息,也就是系统启动过程中输出的信息。这些信息包括系统架构、CPU、连接的设备和内存等等。

基本方法:

dmesg + [options]

查看启动信息

dmesg 

配合使用pipe

dmesg | less
dmesg | more
dmesg | tail

输出前20行日志

dmesg | head  -20

输出最新20行日志

dmesg | tail -20

查看硬件信息

列出所有usb信息

    dmesg | grep -i usb
nvidia@nvidia:~$ dmesg | grep -i usb
[    0.206822] ACPI: bus type USB registered
[    0.206822] usbcore: registered new interface driver usbfs
[    0.206822] usbcore: registered new interface driver hub
[    0.206822] usbcore: registered new device driver usb
[    1.088554] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.088570] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    1.088583] uhci_hcd: USB Universal Host Controller Interface driver
[    1.088722] xhci_hcd 0000:00:14.0: new USB bus registered, assigned bus number 1
[    1.089946] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    1.089948] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.089949] usb usb1: Product: xHCI Host Controller
[    1.089950] usb usb1: Manufacturer: Linux 4.13.0-45-generic xhci-hcd
[    1.089951] usb usb1: SerialNumber: 0000:00:14.0
[    1.090078] hub 1-0:1.0: USB hub found
[    1.090431] xhci_hcd 0000:00:14.0: new USB bus registered, assigned bus number 2
[    1.090462] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003
[    1.090463] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.090465] usb usb2: Product: xHCI Host Controller
[    1.090466] usb usb2: Manufacturer: Linux 4.13.0-45-generic xhci-hcd
[    1.090467] usb usb2: SerialNumber: 0000:00:14.0
[    1.090584] hub 2-0:1.0: USB hub found
[    1.420429] usb 1-5: new high-speed USB device number 2 using xhci_hcd
[    1.594407] usb 1-5: New USB device found, idVendor=5986, idProduct=0670
[    1.594409] usb 1-5: New USB device strings: Mfr=3, Product=1, SerialNumber=2
[    1.594410] usb 1-5: Product: Lenovo EasyCamera
[    1.594411] usb 1-5: Manufacturer: Bison
[    1.594412] usb 1-5: SerialNumber: 200901010001
[    1.716054] usb 1-7: new full-speed USB device number 3 using xhci_hcd
[    1.858024] usb 1-7: New USB device found, idVendor=0bda, idProduct=0821
[    1.858026] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.858027] usb 1-7: Product: Bluetooth Radio 
[    1.858028] usb 1-7: Manufacturer: Realtek 
[    1.858029] usb 1-7: SerialNumber: 00e04c000001
[    2.468090] usbcore: registered new interface driver btusb
[    2.525568] input: Lenovo EasyCamera: Lenovo EasyC as /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0/input/input10
[    2.525608] usbcore: registered new interface driver uvcvideo
[    2.525609] USB Video Class driver (1.1.1)

列出所有串口信息

    dmesg | grep -i tty
nvidia@nvidia:~$ dmesg | grep -i tty
[    0.000000] ACPI: SSDT 0x000000009BFBC000 000215 (v02 LENOVO TbtTypeC 00000000 INTL 20160527)
[    0.000000] console [tty0] enabled
[   10.860649] Bluetooth: RFCOMM TTY layer initialized

查看可使用物理内存

    dmesg | grep -i memory
nvidia@nvidia:~$ dmesg | grep -i memory
[    0.000000] Scanning 1 areas for low memory corruption
[    0.000000] Base memory trampoline at [ffff9de000060000] 60000 size 24576
[    0.000000] Early memory node ranges
[    0.000000] Reserving Intel graphics memory at 0x000000009d800000-0x000000009f7fffff
[    0.000000] PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
[    0.000000] PM: Registered nosave memory: [mem 0x00058000-0x00058fff]
[    0.000000] PM: Registered nosave memory: [mem 0x0008c000-0x000fffff]
[    0.000000] PM: Registered nosave memory: [mem 0x88f24000-0x88f24fff]
[    0.000000] PM: Registered nosave memory: [mem 0x88f25000-0x88f25fff]
[    0.000000] PM: Registered nosave memory: [mem 0x8e30c000-0x8e6a5fff]
[    0.000000] PM: Registered nosave memory: [mem 0x8e6a6000-0x9b197fff]
[    0.000000] PM: Registered nosave memory: [mem 0x9b198000-0x9b798fff]
[    0.000000] PM: Registered nosave memory: [mem 0x9b799000-0x9bffefff]
[    0.000000] PM: Registered nosave memory: [mem 0x9c000000-0x9f7fffff]
[    0.000000] PM: Registered nosave memory: [mem 0x9f800000-0xdfffffff]
[    0.000000] PM: Registered nosave memory: [mem 0xe0000000-0xefffffff]
[    0.000000] PM: Registered nosave memory: [mem 0xf0000000-0xfe00ffff]
[    0.000000] PM: Registered nosave memory: [mem 0xfe010000-0xfe010fff]
[    0.000000] PM: Registered nosave memory: [mem 0xfe011000-0xffffffff]
[    0.000000] Memory: 3647236K/3893844K available (12300K kernel code, 2481K rwdata, 4012K rodata, 2368K init, 2372K bss, 246608K reserved, 0K cma-reserved)
[    0.039832] Freeing SMP alternatives memory: 36K
[    0.092167] x86/mm: Memory block size: 128MB
[    1.074965] Freeing initrd memory: 56976K
[    1.075278] Scanning for low memory corruption every 60 seconds
[    1.161411] Freeing unused kernel memory: 2368K
[    1.181020] Freeing unused kernel memory: 2024K
[    1.181227] Freeing unused kernel memory: 84K
[    1.294737] [drm] Memory usable by graphics device = 4096M

查询HDD(S)是否处于DMA模式

dmesg | grep -i dma
nvidia@nvidia:~$ dmesg | grep -i usb
[    0.206822] ACPI: bus type USB registered
[    0.206822] usbcore: registered new interface driver usbfs
[    0.206822] usbcore: registered new interface driver hub
[    0.206822] usbcore: registered new device driver usb
[    1.088554] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.088570] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    1.088583] uhci_hcd: USB Universal Host Controller Interface driver
[    1.088722] xhci_hcd 0000:00:14.0: new USB bus registered, assigned bus number 1
[    1.089946] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    1.089948] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.089949] usb usb1: Product: xHCI Host Controller
[    1.089950] usb usb1: Manufacturer: Linux 4.13.0-45-generic xhci-hcd
[    1.089951] usb usb1: SerialNumber: 0000:00:14.0
[    1.090078] hub 1-0:1.0: USB hub found
[    1.090431] xhci_hcd 0000:00:14.0: new USB bus registered, assigned bus number 2
[    1.090462] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003
[    1.090463] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.090465] usb usb2: Product: xHCI Host Controller
[    1.090466] usb usb2: Manufacturer: Linux 4.13.0-45-generic xhci-hcd
[    1.090467] usb usb2: SerialNumber: 0000:00:14.0
[    1.090584] hub 2-0:1.0: USB hub found
[    1.420429] usb 1-5: new high-speed USB device number 2 using xhci_hcd
[    1.594407] usb 1-5: New USB device found, idVendor=5986, idProduct=0670
[    1.594409] usb 1-5: New USB device strings: Mfr=3, Product=1, SerialNumber=2
[    1.594410] usb 1-5: Product: Lenovo EasyCamera
[    1.594411] usb 1-5: Manufacturer: Bison
[    1.594412] usb 1-5: SerialNumber: 200901010001
[    1.716054] usb 1-7: new full-speed USB device number 3 using xhci_hcd
[    1.858024] usb 1-7: New USB device found, idVendor=0bda, idProduct=0821
[    1.858026] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.858027] usb 1-7: Product: Bluetooth Radio 
[    1.858028] usb 1-7: Manufacturer: Realtek 
[    1.858029] usb 1-7: SerialNumber: 00e04c000001
[    2.468090] usbcore: registered new interface driver btusb
[    2.525568] input: Lenovo EasyCamera: Lenovo EasyC as /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0/input/input10
[    2.525608] usbcore: registered new interface driver uvcvideo
[    2.525609] USB Video Class driver (1.1.1)
nvidia@nvidia:~$ dmesg | grep -i dma
[    0.000000]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.000000]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.000000]   DMA zone: 64 pages used for memmap
[    0.000000]   DMA zone: 72 pages reserved
[    0.000000]   DMA zone: 3978 pages, LIFO batch:0
[    0.000000]   DMA32 zone: 9037 pages used for memmap
[    0.000000]   DMA32 zone: 578315 pages, LIFO batch:31
[    1.074996] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    1.288856] ata3: SATA max UDMA/133 abar m2048@0xd222d000 port 0xd222d200 irq 16
[    1.288858] ata4: SATA max UDMA/133 abar m2048@0xd222d000 port 0xd222d280 irq 16
[    1.606129] ata3.00: ATA-9: Lenovo SSD ST510 240G, Q0526A, max UDMA/133
[    1.606899] ata3.00: configured for UDMA/133

将启动信息保存

dmesg > boot_messages.txt

打印并清空内核环形缓冲区

dmesg -c
打赏作者