You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
由于老旧的 USB 设备对获取设备功能的请求的支持存在问题,因此 Linux 内核默认不会尝试请求相关数据,进而无法探测 USB 连接的存储设备是否支持 trim 功能。可以使用 `lsblk --discard` 或查看 `/sys/block/sdX/queue/discard_max_bytes` 确认(以下 `sda` 为 USB 磁盘设备):
154
+
155
+
```console
156
+
$ lsblk --discard
157
+
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
158
+
sda 0 512B 0 0
159
+
├─sda1 0 512B 0 0
160
+
├─sda2 0 512B 0 0
161
+
├─sda3 0 512B 0 0
162
+
└─sda4 0 512B 0 0
163
+
nvme0n1 0 512B 2T 0
164
+
├─nvme0n1p1 0 512B 2T 0
165
+
├─nvme0n1p2 0 512B 2T 0
166
+
└─nvme0n1p3 0 512B 2T 0
167
+
```
168
+
169
+
不过,Linux 允许用户手动覆盖这一行为。由于 USB 设备一般都以 USB Attached SCSI (UAS) 或 USB Mass Storage (UMS) 的形式连接,因此其由内核的 SCSI 子系统管理,可以发送 SCSI 命令来确认设备是否支持 trim 功能。
170
+
171
+
安装 `sg3-utils` 包后,使用 `sg_vpd` 查询 unmap 支持情况:
172
+
173
+
```console
174
+
$ sudo sg_vpd --all /dev/sda
175
+
Supported VPD pages VPD page:
176
+
Supported VPD pages [sv]
177
+
Unit serial number [sn]
178
+
Device identification [di]
179
+
Block limits (SBC) [bl]
180
+
Block device characteristics (SBC) [bdc]
181
+
Logical block provisioning (SBC) [lbpv]
182
+
(省略)
183
+
Block limits VPD page (SBC):
184
+
Write same non-zero (WSNZ): 0
185
+
Maximum compare and write length: 0 blocks [Command not implemented]
echo 1073741824 | sudo tee /sys/block/sda/queue/discard_max_bytes
229
+
```
230
+
231
+
其他介绍可参考:
232
+
233
+
- [Enabling TRIM on an external SSD on a Raspberry Pi](https://www.jeffgeerling.com/blog/2020/enabling-trim-on-external-ssd-on-raspberry-pi)
234
+
- [Gentoo Wiki: Discard over USB](https://wiki.gentoo.org/wiki/Discard_over_USB)
235
+
- [Superuser: No TRIM/DISCARD with a SATA SSD connected through an UASP-enabled USB adapter?](https://superuser.com/a/1741030)
236
+
- [scsi: sd: Enable modern protocol features on more devices](https://git.kernel.org/pub/scm/linux/kernel/git/mkp/linux.git/commit/?h=5.18/discovery&id=916740efdd2208564decee40a6049674f2063811)
0 commit comments