问题描述

我在2019年双十一期间购买了一个海康威视e200p固态硬盘,装在了我4年前的电脑上,准备让它再战五年。操作系统是windows10和ubuntu19双系统。我在使用ubuntu19时会发现有时候硬盘灯长亮,然后电脑卡一下。我用以下命令查看日志文件

gedit /var/log/kern.log

发现在我电脑卡住的时候,会有很多这样的日志记录

Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668534] ata2.00: exception Emask 0x0 SAct 0x4018c000 SErr 0x0 action 0x6 frozen
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668544] ata2.00: failed command: WRITE FPDMA QUEUED
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668556] ata2.00: cmd 61/20:70:e0:fb:7a/00:00:24:00:00/40 tag 14 ncq dma 16384 out
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668556]          res 40/00:01:00:4f:c2/00:00:00:00:00/00 Emask 0x4 (timeout)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668561] ata2.00: status: { DRDY }
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668565] ata2.00: failed command: READ FPDMA QUEUED
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668574] ata2.00: cmd 60/08:78:08:04:bc/00:00:25:00:00/40 tag 15 ncq dma 4096 in
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668574]          res 40/00:01:00:4f:c2/00:00:00:00:00/00 Emask 0x4 (timeout)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668578] ata2.00: status: { DRDY }
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668582] ata2.00: failed command: WRITE FPDMA QUEUED
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668591] ata2.00: cmd 61/38:98:18:41:cb/00:00:2d:00:00/40 tag 19 ncq dma 28672 out
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668591]          res 40/00:ff:00:00:00/00:00:00:00:00/00 Emask 0x4 (timeout)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668594] ata2.00: status: { DRDY }
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668598] ata2.00: failed command: READ FPDMA QUEUED
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668606] ata2.00: cmd 60/08:a0:48:30:ff/00:00:3b:00:00/40 tag 20 ncq dma 4096 in
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668606]          res 40/00:01:00:00:00/00:00:00:00:00/00 Emask 0x4 (timeout)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668609] ata2.00: status: { DRDY }
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668614] ata2.00: failed command: READ FPDMA QUEUED
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668622] ata2.00: cmd 60/08:f0:f8:b1:78/00:00:1f:00:00/40 tag 30 ncq dma 4096 in
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668622]          res 40/00:00:00:00:00/00:00:00:00:00/00 Emask 0x4 (timeout)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668625] ata2.00: status: { DRDY }
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.668631] ata2: hard resetting link
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.983379] ata2: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.983793] ata2.00: configured for UDMA/133
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993891] ata2.00: device reported invalid CHS sector 0
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993916] sd 1:0:0:0: [sda] tag#15 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993922] sd 1:0:0:0: [sda] tag#15 Sense Key : Illegal Request [current]
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993926] sd 1:0:0:0: [sda] tag#15 Add. Sense: Unaligned write command
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993932] sd 1:0:0:0: [sda] tag#15 CDB: Read(10) 28 00 25 bc 04 08 00 00 08 00
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993938] blk_update_request: I/O error, dev sda, sector 633078792 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993967] sd 1:0:0:0: [sda] tag#20 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993971] sd 1:0:0:0: [sda] tag#20 Sense Key : Illegal Request [current]
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993974] sd 1:0:0:0: [sda] tag#20 Add. Sense: Unaligned write command
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993978] sd 1:0:0:0: [sda] tag#20 CDB: Read(10) 28 00 3b ff 30 48 00 00 08 00
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.993982] blk_update_request: I/O error, dev sda, sector 1006579784 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Nov 19 16:51:28 dee-Latitude kernel: [ 1716.994000] ata2: EH complete

设置步骤

经过多次搜索发现可能关闭ncq就可以解决,于是尝试一下:首先打开grub文件

sudo vi /etc/default/grub

然后在grub文件最后添加

GRUB_CMDLINE_LINUX="libata.force=noncq"

最后运行如下代码对“/boot/grub/grub.cfg”进行更新

sudo update-grub

重启之后可以通过如下代码查看NCQ是否已经关闭

dmesg | grep NCQ

如果关闭成功,会显示not used等信息

[    1.313263] ata2.00: 2000409264 sectors, multi 16: LBA48 NCQ (not used)

实验结果

在关闭ncq之后的一天时间里,暂时未发现硬盘灯长亮电脑卡死等情况,日志里也未发现过之前的错误。我猜想可能是我古老的电脑装了比较新的系统和固态硬盘造成的兼容性问题,最后希望国货越来越好!

01-13 01:46