当 USB HDD 出现故障时,dmesg 中消息的正常顺序是什么?

当 USB HDD 出现故障时,dmesg 中消息的正常顺序是什么?

我有一个连接到 Debian GNU/Linux 服务器上的 USB 硬盘。我尝试使用以下命令将其格式化 (NTFS):

# mkntfs -v /dev/sdd1

这需要几个小时,因为它还要检查磁盘。检查时,dmesg -T显示以下内容:

[Wed Jan 12 15:22:53 2022] sd 9:0:0:0: [sdd] Attached SCSI disk
[Wed Jan 12 18:03:26 2022] usb 1-4: USB disconnect, device number 5
[Wed Jan 12 18:03:26 2022] blk_update_request: I/O error, dev sdd, sector 621745808 op 0x1:(WRITE) flags 0x104000 phys_seg 240 prio class 0
[Wed Jan 12 18:03:26 2022] Buffer I/O error on dev sdd1, logical block 621743760, lost async page write
[Wed Jan 12 18:03:26 2022] Buffer I/O error on dev sdd1, logical block 621743761, lost async page write
   (...and so on for a few lines, then)
[Wed Jan 12 18:03:26 2022] blk_update_request: I/O error, dev sdd, sector 621746048 op 0x1:(WRITE) flags 0x104000 phys_seg 240 prio class 0
[Wed Jan 12 18:03:26 2022] blk_update_request: I/O error, dev sdd, sector 621746288 op 0x1:(WRITE) flags 0x100000 phys_seg 8 prio class 0
[Wed Jan 12 18:03:26 2022] blk_update_request: I/O error, dev sdd, sector 621746296 op 0x1:(WRITE) flags 0x800 phys_seg 16 prio class 0
   (...and so on for a few lines, then)
[Wed Jan 12 18:03:31 2022] buffer_io_error: 9015384 callbacks suppressed
   (...other errors...)

从错误消息的数量来看,我认为硬盘几乎已经坏了,但将它连接到 Windows PC 上似乎可以正常工作。此外,第一个错误 ( usb 1-4: USB disconnect, device number 5) 先于其他错误出现dmesg,这让我怀疑问题不是硬盘本身,而是导致硬盘断开连接的其他原因,而后续错误可能是断开连接的明显后果。

但是我对输出不是很有经验dmesg,所以很可能我读错了。

编辑:根据 NiKiZe 的要求,以下是输出smartctl -a /dev/sdd

# smartctl -a /dev/sdd
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-5.10.0-3-amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Blue Mobile
Device Model:     WDC WD10SPCX-00KHST0
Serial Number:    WD-WXF1A95F0J3X
LU WWN Device Id: 5 0014ee 65b7e0332
Firmware Version: 01.01A01
User Capacity:    1.000.204.886.016 bytes [1,00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 1.5 Gb/s)
Local Time is:    Thu Jan 13 11:04:19 2022 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART Status not supported: Incomplete response, ATA output registers missing
SMART overall-health self-assessment test result: PASSED
Warning: This result is based on an Attribute check.

General SMART Values:
Offline data collection status:  (0x00) Offline data collection activity
                    was never started.
                    Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0) The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:        (16080) seconds.
Offline data collection
capabilities:            (0x7b) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    Offline surface scan supported.
                    Self-test supported.
                    Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:    (   2) minutes.
Extended self-test routine
recommended polling time:    ( 184) minutes.
Conveyance self-test routine
recommended polling time:    (   5) minutes.
SCT capabilities:          (0x7035) SCT Status supported.
                    SCT Feature Control supported.
                    SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0027   190   184   021    Pre-fail  Always       -       1500
  4 Start_Stop_Count        0x0032   081   081   000    Old_age   Always       -       19048
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   073   073   000    Old_age   Always       -       20415
 10 Spin_Retry_Count        0x0032   100   100   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   100   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       188
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       43
193 Load_Cycle_Count        0x0032   187   187   000    Old_age   Always       -       41054
194 Temperature_Celsius     0x0022   119   095   000    Old_age   Always       -       28
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   100   253   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

假设这个硬盘真的坏了,那些错误信息是dmesg真的坏扇区造成的,为什么会dmesg显示断开连接而不是之后的坏扇区消息?

答案1

首先发生断开连接,然后您会收到由断开连接引起的多种错误,其中生成磁盘写入的各个层都会注意到出现了问题。

大多数 I/O 都以具有磁盘支持的“脏”内存页的形式发生,内核最终会将其刷新到磁盘,此时距离应用程序确认写入已经过去很久了,并且唯一仍然对请求感兴趣的驱动层是内存子系统(想知道是否可以释放该页面)和文件系统(在写入数据后,需要生成更多写入来更新元数据)——上述所有内容都已被拆除。

一些请求不经过内存子系统(例如 SMART 状态查询),一些请求(如读取)可能仅附加到内存子系统,因为文件系统已查找了块映射并且不再需要参与。

因此,由于断开连接而收到的错误消息没有特定的顺序——它们发生在请求生成、提交和由于设备离线而拒绝时。如果某些请求之间存在因果关系(例如反映中止数据传输后新状态的日志条目——毕竟日志可能位于不同的设备上),那么这定义了一些顺序。

我可能会尝试在适当的 SATA 端口上使用该磁盘,并使用良好电源供电——USB 转 SATA 外壳中的电压转换器通常有点不稳定。

答案2

请认为驱动器已死。

通常情况下,格式化驱动器不会花太长时间。但是,对坏块进行重试和重置确实需要时间。

当然,这可能是由于电源故障或其他原因造成的。

并非所有 USB 设备都支持智能直通,但请尝试: smartctl -a /dev/sdd特别查找Reallocated_Sector_Ct、、,如果其中任何一个具有除之外的,我会尝试避免将磁盘用于非重要数据以外的任何用途。Reallocated_Event_CountCurrent_Pending_SectorOffline_UncorrectableRAW_VALUE0

如果磁盘上没有数据,您可以尝试擦除它,使用类似(这里要小心!!!dd if=/dev/zero of=/dev/sdd bs=4M status=progress。之后您将需要重新创建分区表。

相关内容