【转】Linux USB3.0 接移动硬盘频繁卡死问题解决方法

安装命令lsusb

yum install usbutils

卡顿可能原因uas驱动

uas 是USB Attached Storage ,使用的协议是 USB MSC USB Attached SCSI Protocol,
初步判断出是linux内核对uas移动硬盘支持的不好

查看系统内核当前加载的模块:

lsmod
Module                  Size  Used by
xt_conntrack           16384  1
ipt_MASQUERADE         16384  1
nf_nat_masquerade_ipv4    16384  1 ipt_MASQUERADE
nf_conntrack_netlink    36864  0
xt_addrtype            16384  2
iptable_filter         16384  1
iptable_nat            16384  1
nf_conntrack_ipv4      24576  2
nf_defrag_ipv4         16384  1 nf_conntrack_ipv4
nf_nat_ipv4            16384  1 iptable_nat
nf_nat                 20480  2 nf_nat_ipv4,nf_nat_masquerade_ipv4
nf_conntrack          126976  6 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,nf_conntrack_ipv4
overlay                45056  1
binfmt_misc            20480  1
uas                    20480  0
usb_storage            61440  15 uas
bcmdhd               1183744  0
autofs4                40960  3

可以看到 ==uas module==

查看系统的 usb 设备:

$ lsusb -t
/:  Bus 08.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:  Bus 07.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
/:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
            |__ Port 1: Dev 5, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 2: Dev 7, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 3: Dev 10, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 4: Dev 13, If 0, Class=Mass Storage, Driver=uas, 5000M
        |__ Port 2: Dev 4, If 0, Class=Hub, Driver=hub/4p, 5000M
            |__ Port 1: Dev 8, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 2: Dev 11, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 3: Dev 14, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 4: Dev 17, If 0, Class=Mass Storage, Driver=uas, 5000M
        |__ Port 3: Dev 6, If 0, Class=Hub, Driver=hub/4p, 5000M
            |__ Port 1: Dev 22, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 2: Dev 12, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 3: Dev 16, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 4: Dev 23, If 0, Class=Mass Storage, Driver=uas, 5000M
        |__ Port 4: Dev 9, If 0, Class=Hub, Driver=hub/4p, 5000M
            |__ Port 1: Dev 15, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 2: Dev 18, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 3: Dev 19, If 0, Class=Mass Storage, Driver=uas, 5000M
            |__ Port 4: Dev 20, If 0, Class=Mass Storage, Driver=uas, 5000M
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 2: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 3: Dev 5, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 4: Dev 6, If 0, Class=Hub, Driver=hub/4p, 480M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci-platform/1p, 12M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci-platform/1p, 12M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-platform/1p, 480M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-platform/1p, 480M

其中有很多 ==Class=Mass Storage, Driver=uas, 5000M== 就是使用了 uas 作为驱动。

可以选择在系统中完全禁用掉uas

$ sudo vim  /etc/modprobe.d/blacklist.conf

在最后添加,这里不需要添加了,否则超过2T的硬盘可能挂载不了

#blacklist uas

保存然后重启机器。

变更为 usb-storage 驱动

但是,测试发现这么操作会导致上面使用了uas的设备直接找不到驱动无法正常工作。

我们需要为这些设备直接指定使用更基础的 ==usb-storage== 模块作为驱动,同时禁用掉==uas== 。

先获取设备的 idVendor:idProduct

$ lsusb  | awk '{print $6}' | sort -u
05e3:0610
05e3:0626
152d:0578
152d:9561
1d6b:0001
1d6b:0002
1d6b:0003

在 ==/etc/modprobe.d/== 目录下添加一个文件==disable-uas.conf== (名字可以任意定)

$ sudo vim /etc/modprobe.d/disable-uas.conf

添加:

options usb-storage quirks=05e3:0610:u,05e3:0626:u,152d:0578:u,1d6b:0001:u,1d6b:0002:u,1d6b:0003:u

然后输入

// centos7
dracut --force

// ubuntu
sudo update-initramfs -u

sudo reboot

重启机器。

再通过 lsusb -t 查看设备:

# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 4: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
        |__ Port 1: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
        |__ Port 2: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
    |__ Port 4: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M

之前使用 ==uas== 驱动设备都使用了==usb-storage== 。

通过dmesg | grep 'scsi host' -A5 -B5 查看系统日志也可以看出:

# dmesg | grep 'scsi host' -A5 -B5
[    1.587794] ahci 0000:00:17.0: AHCI 0001.0301 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
[    1.587797] ahci 0000:00:17.0: flags: 64bit ncq pm led clo only pio slum part deso sadm sds apst 
[    1.590387] Setting dangerous option alpha_support - tainting kernel
[    1.590994] i915 0000:00:02.0: vgaarb: deactivate vga console
[    1.592639] Console: switching to colour dummy device 80x25
[    1.592971] scsi host0: ahci
[    1.593170] scsi host1: ahci
[    1.593237] ata1: SATA max UDMA/133 abar m2048@0xdf617000 port 0xdf617100 irq 130
[    1.593239] ata2: SATA max UDMA/133 abar m2048@0xdf617000 port 0xdf617180 irq 130
[    1.594095] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    1.594096] [drm] Driver supports precise vblank timestamp query.
[    1.594835] i915 0000:00:02.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=io+mem
--
[   36.986204] usb 2-4.2: Product: ACASIS
[   36.986207] usb 2-4.2: Manufacturer: ACASIS
[   36.986210] usb 2-4.2: SerialNumber: 00A2018C0008
[   37.316434] usb-storage 1-4.1:1.0: USB Mass Storage device detected
[   37.316520] usb-storage 1-4.1:1.0: Quirks match for vid 0bda pid 9210: 800000
[   37.316546] scsi host2: usb-storage 1-4.1:1.0
[   37.316625] usbcore: registered new interface driver usb-storage
[   37.322702] usb 2-4.2: UAS is blacklisted for this device, using usb-storage instead
[   37.322705] usb-storage 2-4.2:1.0: USB Mass Storage device detected
[   37.322809] usb-storage 2-4.2:1.0: Quirks match for vid 152d pid 0583: 800000
[   37.322845] scsi host3: usb-storage 2-4.2:1.0
[   38.350611] scsi 3:0:0:0: Direct-Access     ACASIS                    0208 PQ: 0 ANSI: 6
[   38.351055] sd 3:0:0:0: Attached scsi generic sg1 type 0
[   38.352359] sd 3:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[   38.353249] sd 3:0:0:0: [sdb] Write Protect is off
[   38.353254] sd 3:0:0:0: [sdb] Mode Sense: 53 00 00 08
--
[   69.782460] usb 2-4.1: Enable of device-initiated U1 failed.
[   69.783814] usb 2-4.1: Enable of device-initiated U2 failed.
[   69.784242] usb 2-4.1: UAS is blacklisted for this device, using usb-storage instead
[   69.784247] usb-storage 2-4.1:1.0: USB Mass Storage device detected
[   69.784459] usb-storage 2-4.1:1.0: Quirks match for vid 0bda pid 9210: 800000
[   69.784537] scsi host2: usb-storage 2-4.1:1.0
[   95.087209] usb 2-4.1: reset SuperSpeed Gen 1 USB device number 4 using xhci_hcd
[   95.106101] usb 2-4.1: Enable of device-initiated U1 failed.
[   95.107406] usb 2-4.1: Enable of device-initiated U2 failed.
[  121.053102] usb 2-4.2: USB disconnect, device number 3
[  121.055232] sd 3:0:0:0: [sdb] Synchronizing SCSI cache
--
[  123.078436] usb 2-4.2: Manufacturer: ACASIS
[  123.078438] usb 2-4.2: SerialNumber: 00A2018C0008
[  123.080212] usb 2-4.2: UAS is blacklisted for this device, using usb-storage instead
[  123.080217] usb-storage 2-4.2:1.0: USB Mass Storage device detected
[  123.080504] usb-storage 2-4.2:1.0: Quirks match for vid 152d pid 0583: 800000
[  123.080561] scsi host3: usb-storage 2-4.2:1.0
[  124.029168] usb 2-4.1: USB disconnect, device number 4
[  124.110305] scsi 3:0:0:0: Direct-Access     ACASIS                    0208 PQ: 0 ANSI: 6
[  124.110657] sd 3:0:0:0: Attached scsi generic sg1 type 0
[  126.186941] sd 3:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[  126.187256] sd 3:0:0:0: [sdb] Write Protect is off
--
[  127.329020] usb 2-4.1: Enable of device-initiated U1 failed.
[  127.330292] usb 2-4.1: Enable of device-initiated U2 failed.
[  127.330553] usb 2-4.1: UAS is blacklisted for this device, using usb-storage instead
[  127.330558] usb-storage 2-4.1:1.0: USB Mass Storage device detected
[  127.330846] usb-storage 2-4.1:1.0: Quirks match for vid 0bda pid 9210: 800000
[  127.330895] scsi host2: usb-storage 2-4.1:1.0
[  128.344719] scsi 2:0:0:0: Direct-Access     SanDisk  Ultra 3D NVMe    10WD PQ: 0 ANSI: 6
[  128.345150] sd 2:0:0:0: Attached scsi generic sg2 type 0
[  128.349020] sd 2:0:0:0: [sdc] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[  128.350978] sd 2:0:0:0: [sdc] Write Protect is off
[  128.350980] sd 2:0:0:0: [sdc] Mode Sense: 37 00 00 08

该设备禁用了==uas== ,使用==usb-storage==。

到此已经解决问题。对于其他不同的操作系统比如 Linux on a Raspberry Pi,如果上述方法不生效,可以试一试下面的配置:

$ sudo vim /boot/cmdline.txt

添加:

usb-storage quirks=05e3:0610:u,05e3:0626:u,152d:0578:u,152d:9561:u,1d6b:0001:u,1d6b:0002:u,1d6b:0003:u

然后重启机器。

参考

  1. https://forum.pine64.org/showthread.php?tid=5832
  2. https://forum.pine64.org/showthread.php?tid=5137
  3. https://www.crifan.com/files/doc/docbook/usb_disk_driver/release/html/usb_disk_driver.html?spm=a2c6h.12873639.0.0.4f412263nKhXtS#ch02_msc_basic
  4. https://leo.leung.xyz/wiki/Disable_UAS
  5. https://askubuntu.com/questions/1266804/blacklist-uas-drivers-in-kernel
  6. https://iitii.github.io/2019/08/05/1/
  7. https://www.smartmontools.org/wiki/SAT-with-UAS-Linux
  8. https://developer.aliyun.com/article/48227

转载

https://blog.zongwu233.com/linux-usb3-driver/

最后修改:2023 年 01 月 07 日 10 : 08 AM

发表评论