睡眠/唤醒后外部 USB 磁盘 I/O 错误

睡眠/唤醒后外部 USB 磁盘 I/O 错误

我的笔记本电脑(华硕 X550C)的 USB 3.0 端口上连接了一块 1TB 东芝 USB 硬盘。我使用的是 Ubuntu 18.04(内核 4.15.0-166-generic)。

我曾经在连接 USB 驱动器的情况下将计算机睡眠/唤醒,一切恢复正常。但是,自从一次 Ubuntu 更新(我不知道是哪一次)以来,我在唤醒后收到来自 USB 磁盘的 I/O 错误:

user@asus:/media/user/HDD$ ls
ls: reading directory '.': Input/output error

所有从 USB 磁盘打开文件的程序在恢复后都会崩溃,因为它们无法访问该磁盘。

我通过反复试验观察到的情况是:

  • 新程序可以成功访问磁盘。但是,那些经历了睡眠/唤醒周期的程序永远无法恢复访问,即使磁盘再次工作
  • 有一个例外:如果我打开 shell 并指向磁盘中的目录,则会出现 I/O 错误。但是,如果我输入cd .错误,则错误消失并且 HDD 再次正常工作(仅限cd .,任何其他命令都会导致 IO 错误)
  • 如果我将 HDD 连接到 USB 2.0 端口,它会成功唤醒
  • 如果我连接 USB 闪存盘(不是 HDD),它会成功唤醒

对于经过睡眠/唤醒过程的程序来说,当前目录似乎不知何故丢失了。唤醒后打开的程序运行良好。这只发生在连接到 USB 3.0 的 HDD 上(就像某种竞争条件)。

$ sudo fdisk -l
Disk /dev/sda: 447.1 GiB, 480103981056 bytes, 937703088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8cc1ecc7

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048    206847    204800   100M  7 HPFS/NTFS/exFAT
/dev/sda2          206848 440526847 440320000   210G  7 HPFS/NTFS/exFAT
/dev/sda3       440526848 937701375 497174528 237.1G 83 Linux


Disk /dev/sdc: 931.5 GiB, 1000204883968 bytes, 1953525164 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9b0f78c0

Device     Boot     Start        End   Sectors   Size Id Type
/dev/sdc1            2048  983042047 983040000 468.8G  7 HPFS/NTFS/exFAT
/dev/sdc2       983042048 1953525163 970483116 462.8G 83 Linux
$ lsusb 
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 04f2:b40a Chicony Electronics Co., Ltd 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 021: ID 0480:a00c Toshiba America Inc 
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 007: ID 0835:8502 Action Star Enterprise Co., Ltd 
Bus 003 Device 006: ID 0835:8500 Action Star Enterprise Co., Ltd 
Bus 003 Device 005: ID 046d:c31c Logitech, Inc. Keyboard K120
Bus 003 Device 004: ID 046d:c03e Logitech, Inc. Premium Optical Wheel Mouse (M-BT58)
Bus 003 Device 003: ID 0835:8501 Action Star Enterprise Co., Ltd 
Bus 003 Device 002: ID 0835:8500 Action Star Enterprise Co., Ltd 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

使用 USB 3.0 的 dmes 输出(错误重现):

[   80.707547] wlp2s0: deauthenticating from 54:a0:50:e4:82:30 by local choice (Reason: 3=DEAUTH_LEAVING)
[   83.020979] PM: suspend entry (deep)
[   83.020982] PM: Syncing filesystems ... done.
[   83.034082] Freezing user space processes ... (elapsed 0.002 seconds) done.
[   83.036245] OOM killer disabled.
[   83.036246] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[   83.037516] Suspending console(s) (use no_console_suspend to debug)
[   83.056384] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[   83.056445] sd 0:0:0:0: [sda] Stopping disk
[   83.064227] sd 6:0:0:0: [sdb] Synchronizing SCSI cache
[   83.225059] ACPI: EC: interrupt blocked
[   83.244915] ACPI: Preparing to enter system sleep state S3
[   83.252323] ACPI: EC: event blocked
[   83.252325] ACPI: EC: EC stopped
[   83.252326] PM: Saving platform NVS memory
[   83.252516] Disabling non-boot CPUs ...
[   83.268409] IRQ 31: no longer affine to CPU1
[   83.269427] smpboot: CPU 1 is now offline
[   83.294105] smpboot: CPU 2 is now offline
[   83.316526] IRQ 23: no longer affine to CPU3
[   83.316533] IRQ 26: no longer affine to CPU3
[   83.316541] IRQ 29: no longer affine to CPU3
[   83.317557] smpboot: CPU 3 is now offline
[   83.319808] ACPI: Low-level resume complete
[   83.319884] ACPI: EC: EC started
[   83.319885] PM: Restoring platform NVS memory
[   83.321732] Enabling non-boot CPUs ...
[   83.321805] x86: Booting SMP configuration:
[   83.321806] smpboot: Booting Node 0 Processor 1 APIC 0x2
[   83.325400]  cache: parent cpu1 should not be sleeping
[   83.325731] CPU1 is up
[   83.325772] smpboot: Booting Node 0 Processor 2 APIC 0x1
[   83.328403]  cache: parent cpu2 should not be sleeping
[   83.329072] CPU2 is up
[   83.329111] smpboot: Booting Node 0 Processor 3 APIC 0x3
[   83.331670]  cache: parent cpu3 should not be sleeping
[   83.332147] CPU3 is up
[   83.336322] ACPI: Waking up from system sleep state S3
[   83.415767] ACPI: EC: interrupt unblocked
[   83.436652] ACPI: EC: event unblocked
[   83.436704] usb usb3: root hub lost power or was reset
[   83.436709] usb usb4: root hub lost power or was reset
[   83.437112] usb usb1: root hub lost power or was reset
[   83.437889] usb usb2: root hub lost power or was reset
[   83.441029] ehci-pci 0000:00:1a.0: cache line size of 64 is not supported
[   83.441796] ehci-pci 0000:00:1d.0: cache line size of 64 is not supported
[   83.444014] sd 0:0:0:0: [sda] Starting disk
[   83.552768] r8169 0000:03:00.2 enp3s0f2: link down
[   83.734197] usb 2-1: reset high-speed USB device number 2 using ehci-pci
[   83.734220] usb 1-1: reset high-speed USB device number 2 using ehci-pci
[   83.768919] ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[   83.768963] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[   83.770066] ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
[   83.770934] ata1.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[   83.770939] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[   83.771145] ata3.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[   83.771152] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[   83.772458] ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
[   83.772534] ata1.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[   83.772539] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[   83.772644] ata1.00: configured for UDMA/133
[   83.776606] ata3.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[   83.776612] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[   83.778387] ata3.00: configured for UDMA/133
[   84.205989] usb 1-1.3: reset high-speed USB device number 3 using ehci-pci
[   86.415072] OOM killer enabled.
[   86.415075] Restarting tasks ... 
[   86.415368] usb 4-1: USB disconnect, device number 2
[   86.422799] done.
[   86.425772] print_req_error: I/O error, dev sdb, sector 0
[   86.437800] sd 6:0:0:0: [sdb] Synchronizing SCSI cache
[   86.437843] sd 6:0:0:0: [sdb] Synchronize Cache(10) failed: Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
[   86.493540] blk_partition_remap: fail for partition 2
[   86.493568] Buffer I/O error on dev sdb2, logical block 60325888, lost sync page write
[   86.493581] JBD2: Error -5 detected when updating journal superblock for sdb2-8.
[   86.493583] Aborting journal on device sdb2-8.
[   86.493587] blk_partition_remap: fail for partition 2
[   86.493588] Buffer I/O error on dev sdb2, logical block 60325888, lost sync page write
[   86.493590] JBD2: Error -5 detected when updating journal superblock for sdb2-8.
[   86.638576] PM: suspend exit
[   86.746072] IPv6: ADDRCONF(NETDEV_UP): enp3s0f2: link is not ready
[   86.843335] r8169 0000:03:00.2 enp3s0f2: link down
[   86.843517] IPv6: ADDRCONF(NETDEV_UP): enp3s0f2: link is not ready
[   86.846125] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[   86.996625] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[   87.053851] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[   87.320988] usb 4-1: new SuperSpeed USB device number 3 using xhci_hcd
[   87.344753] usb 4-1: New USB device found, idVendor=0480, idProduct=a00c
[   87.344757] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   87.344759] usb 4-1: Product: External USB 3.0
[   87.344760] usb 4-1: Manufacturer: TOSHIBA
[   87.344762] usb 4-1: SerialNumber: 20140114057420
[   87.345967] usb-storage 4-1:1.0: USB Mass Storage device detected
[   87.347590] usb-storage 4-1:1.0: Quirks match for vid 0480 pid a00c: 800000
[   87.347626] scsi host6: usb-storage 4-1:1.0
[   88.175858] wlp2s0: authenticate with 54:a0:50:e4:82:30
[   88.185166] wlp2s0: send auth to 54:a0:50:e4:82:30 (try 1/3)
[   88.186656] wlp2s0: authenticated
[   88.188952] wlp2s0: associate with 54:a0:50:e4:82:30 (try 1/3)
[   88.192934] wlp2s0: RX AssocResp from 54:a0:50:e4:82:30 (capab=0x1411 status=0 aid=5)
[   88.193029] wlp2s0: associated
[   88.214555] IPv6: ADDRCONF(NETDEV_CHANGE): wlp2s0: link becomes ready
[   88.377019] scsi 6:0:0:0: Direct-Access     TOSHIBA  External USB 3.0 5438 PQ: 0 ANSI: 6
[   88.381543] sd 6:0:0:0: Attached scsi generic sg2 type 0
[   88.382630] sd 6:0:0:0: [sdb] 1953525164 512-byte logical blocks: (1.00 TB/932 GiB)
[   88.382979] sd 6:0:0:0: [sdb] Write Protect is off
[   88.382982] sd 6:0:0:0: [sdb] Mode Sense: 23 00 00 00
[   88.383327] sd 6:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[   90.948674]  sdb: sdb1 sdb2
[   90.960736] sd 6:0:0:0: [sdb] Attached SCSI disk
[   92.224427] EXT4-fs (sdb2): recovery complete
[   92.284931] EXT4-fs (sdb2): mounted filesystem with ordered data mode. Opts: (null)

使用 USB 2.0 的 dmes 输出(无错误):

[  101.037552] wlp2s0: deauthenticating from 54:a0:50:e4:82:30 by local choice (Reason: 3=DEAUTH_LEAVING)
[  103.385167] PM: suspend entry (deep)
[  103.385170] PM: Syncing filesystems ... done.
[  103.397551] Freezing user space processes ... (elapsed 0.002 seconds) done.
[  103.399954] OOM killer disabled.
[  103.399955] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[  103.401220] Suspending console(s) (use no_console_suspend to debug)
[  103.433979] sd 6:0:0:0: [sdb] Synchronizing SCSI cache
[  103.433981] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[  103.434395] sd 0:0:0:0: [sda] Stopping disk
[  103.603845] ACPI: EC: interrupt blocked
[  103.623791] ACPI: Preparing to enter system sleep state S3
[  103.755715] ACPI: EC: event blocked
[  103.755717] ACPI: EC: EC stopped
[  103.755718] PM: Saving platform NVS memory
[  103.755866] Disabling non-boot CPUs ...
[  103.771717] IRQ 31: no longer affine to CPU1
[  103.772734] smpboot: CPU 1 is now offline
[  103.797121] smpboot: CPU 2 is now offline
[  103.819706] IRQ 23: no longer affine to CPU3
[  103.819714] IRQ 26: no longer affine to CPU3
[  103.819719] IRQ 27: no longer affine to CPU3
[  103.820738] smpboot: CPU 3 is now offline
[  103.823007] ACPI: Low-level resume complete
[  103.823087] ACPI: EC: EC started
[  103.823089] PM: Restoring platform NVS memory
[  103.824934] Enabling non-boot CPUs ...
[  103.825037] x86: Booting SMP configuration:
[  103.825038] smpboot: Booting Node 0 Processor 1 APIC 0x2
[  103.828655]  cache: parent cpu1 should not be sleeping
[  103.828991] CPU1 is up
[  103.829030] smpboot: Booting Node 0 Processor 2 APIC 0x1
[  103.831690]  cache: parent cpu2 should not be sleeping
[  103.832340] CPU2 is up
[  103.832389] smpboot: Booting Node 0 Processor 3 APIC 0x3
[  103.834918]  cache: parent cpu3 should not be sleeping
[  103.835416] CPU3 is up
[  103.839605] ACPI: Waking up from system sleep state S3
[  103.902963] ACPI: EC: interrupt unblocked
[  103.923403] ACPI: EC: event unblocked
[  103.923449] usb usb3: root hub lost power or was reset
[  103.923454] usb usb4: root hub lost power or was reset
[  103.925642] usb usb1: root hub lost power or was reset
[  103.927446] usb usb2: root hub lost power or was reset
[  103.929543] ehci-pci 0000:00:1a.0: cache line size of 64 is not supported
[  103.931347] ehci-pci 0000:00:1d.0: cache line size of 64 is not supported
[  103.935308] sd 0:0:0:0: [sda] Starting disk
[  104.035971] r8169 0000:03:00.2 enp3s0f2: link down
[  104.225463] usb 1-1: reset high-speed USB device number 2 using ehci-pci
[  104.225473] usb 2-1: reset high-speed USB device number 2 using ehci-pci
[  104.320371] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[  104.320409] ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[  104.321734] ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
[  104.322970] ata1.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[  104.322978] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[  104.323150] ata3.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[  104.323158] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[  104.324340] ata1.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out
[  104.324379] ata1.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[  104.324383] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[  104.324562] ata1.00: configured for UDMA/133
[  104.328629] ata3.00: ACPI cmd ef/10:06:00:00:00:a0 (SET FEATURES) succeeded
[  104.328647] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[  104.330415] ata3.00: configured for UDMA/133
[  104.341631] usb 3-2: reset high-speed USB device number 2 using xhci_hcd
[  104.697412] usb 1-1.3: reset high-speed USB device number 3 using ehci-pci
[  104.837895] OOM killer enabled.
[  104.837899] Restarting tasks ... done.
[  105.098906] PM: suspend exit
[  105.182497] IPv6: ADDRCONF(NETDEV_UP): enp3s0f2: link is not ready
[  105.283583] r8169 0000:03:00.2 enp3s0f2: link down
[  105.283671] IPv6: ADDRCONF(NETDEV_UP): enp3s0f2: link is not ready
[  105.285124] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[  105.433822] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[  105.482910] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[  106.622874] wlp2s0: authenticate with 54:a0:50:e4:82:30
[  106.627239] wlp2s0: send auth to 54:a0:50:e4:82:30 (try 1/3)
[  106.630373] wlp2s0: authenticated
[  106.633249] wlp2s0: associate with 54:a0:50:e4:82:30 (try 1/3)
[  106.649449] wlp2s0: RX AssocResp from 54:a0:50:e4:82:30 (capab=0x1411 status=0 aid=5)
[  106.649543] wlp2s0: associated
[  106.671964] IPv6: ADDRCONF(NETDEV_CHANGE): wlp2s0: link becomes ready

如您所见,两个日志之间的唯一区别是在 USB 3.0 中 HDD 与 USB 总线断开了连接:

...
[   86.415368] usb 4-1: USB disconnect, device number 2
...

因此,当操作系统尝试从 HDD 访问文件时,HDD 尚未准备好,从而发生错误。

知道什么原因可能导致仅在 USB 3.0 下出现断开连接吗?

提前非常感谢您。

答案1

听起来像是 USB3 UAS 问题。请执行以下操作...

总线 004 设备 021:ID 0480:a00c 东芝美国公司

USB 连接 SCSI (UAS) 或 USB 连接 SCSI 协议 (UASP) 是一种计算机协议,用于将数据移入和移出 USB 存储设备,例如硬盘驱动器 (HDD)、固态驱动器 (SSD) 和拇指驱动器。UAS 依赖于 USB 协议,并使用标准 SCSI 命令集。与较旧的 USB 大容量存储批量传输 (BOT) 驱动程序相比,使用 UAS 通常可以提供更快的传输速度。

UAS 是作为 USB 3.0 标准的一部分推出的,但也可以与符合速度较慢的 USB 2.0 标准的设备一起使用,假设使用兼容的硬件、固件和驱动程序。

与旧版 USB 大容量存储批量传输 (BOT) 协议驱动程序相比,UAS 驱动程序通常可提供更快的传输速度。尽管 UAS 是在 USB 3.0 标准中添加的,但只要硬件兼容,它也可以以 USB 2.0 速度使用。

与 SSD 一起使用时,UAS 的随机读写速度比 BOT 快得多,但对于某些写入任务,仍远低于原生 SATA 3 接口的速度。

来源:https://en.wikipedia.org/wiki/USB_Attached_SCSI

# drop this into /etc/modprobe.d/disable_uas.conf
# should look like this:
# -rw-r--r--   1 root root  505 Apr 30 11:36 disable-uas.conf
#
# sources:
# https://unix.stackexchange.com/questions/525290/usb-hdd-not-found
# https://unix.stackexchange.com/questions/239782/connection-problem-with-usb3-external-storage-on-linux-uas-driver-problem
#
# examples for single/multiple disks:
# options usb-storage quirks=059f:105e:u 
# options usb-storage quirks=059f:105f:u,059f:105e:u,174c:1351:u
#
# commands to complete this install:
# sudo update-initramfs -u
# reboot
#
# Toshiba drive
options usb-storage quirks=0480:a00c:u

更新#1:

  • 在 Windows 中,运行chkdsk D: /f并将chkdsk D: /rD: 更改为 NTFS 分区的正确驱动器号。

  • 在 Ubuntu 中,EXT4 分区出现坏块......

注意:不要中止坏块扫描!

注意:不要对 SSD 造成坏块

注意:请先备份您的重要文件!

注意:这将花费很多小时

注意:您可能面临硬盘故障

在“尝试 Ubuntu”模式下启动 Ubuntu Live DVD/USB。

terminal...

sudo fdisk -l# 识别所有“Linux 文件系统”分区

sudo e2fsck -fcky /dev/sdXX# 只读测试

或者

sudo e2fsck -fccky /dev/sdXX# 非破坏性读写测试(受到推崇的)

-k 很重要,因为它会保存之前的坏块表,并将任何新的坏块添加到该表中。如果没有 -k,您将丢失所有之前的坏块信息。

-fccky 参数...

   -f    Force checking even if the file system seems clean.

   -c    This option causes e2fsck to use badblocks(8) program to do
         a read-only scan of the device in order to find any bad blocks.
         If any bad blocks are found, they are added to the bad block
         inode to prevent them from being allocated to a file or direc‐
         tory.  If this option is specified twice, then the bad block scan
         will be done using a non-destructive read-write test.

   -k    When combined with the -c option, any existing bad blocks in the
         bad blocks list are preserved, and any new bad blocks found by
         running badblocks(8) will be added to the existing bad blocks
         list.

   -y    Assume an answer of `yes' to all questions; allows e2fsck to be
         used non-interactively. This option may not be specified at the
         same time as the -n or -p options.

相关内容