35+ stories, thoughts and ideas.35+ stories, thoughts and ideas.


stories, thoughts and ideas.

USB外置存储、易驱线与smartctl适配

问题

部分型号希捷的USB外置存储和使用VIA芯片(如VL711)的易驱线连接的硬盘,接入Linux后,无法正常使用smartctl获取硬盘SMART信息。

$ sudo smartctl -x /dev/sda
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-43-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

Read Device Identity failed: scsi error unsupported field in scsi command

A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.

原因

此问题为USB硬件芯片与内核兼容的问题,出现在采用了UASP模式的USB存储器。

解决方法

配置usb_storage模块的quirks解决此问题,有2种方法:
1、禁用UASP模式,会有性能损失,毕竟UASP对USB传输性能有提升,尤其是小文件传输。参数为VID:PID:u,如:0bc2:331a:u
2、继续保持UASP模式,参数为VID:PID:,如:0bc2:331a:
多个不同型号的USB设备,使用逗号分隔

配置方法

  1. 使用lsusb检测USB传输模式

其中Driver=uas说明是UASP模式,Driver=usb-storage则不是。

$ lsusb -tv
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=uas, 480M
        ID 0bc2:331a Seagate RSS LLC Desktop HDD 5TB (ST5000DM000)
  1. Ubuntu 20

在 /etc/modprobe.d 新建一个.conf 文件,配置参数在里面,如下:

$ cat /etc/modprobe.d/disable-uas.conf 
options usb-storage quirks="2109:0711:,0bc2:331a:"
  1. Ubuntu 22

ubuntu 22以后,第二步的方法不能生效,可以修改grub的 GRUB_CMDLINE_LINUX参数来生效,修改后需要执行一次update-grub

$ cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="usb_storage.quirks=0bc2:331a:"          <========

$ sudo update-grub
  1. 检查生效

参数修改后需要重启,重启后检查/sys/module/usb_storage/parameters/quirks 内容是否与配置内容一致,然后执行smartctl看是否能成功读取SMART信息。

$ cat /sys/module/usb_storage/parameters/quirks 
0bc2:331a:

参考文章

本原创文章未经允许不得转载 | 当前页面:35+ stories, thoughts and ideas. » USB外置存储、易驱线与smartctl适配

评论