anhedonic

dynamic soap bubbles

Apr 19, 2025

External Storage Mistakes

Berend De Schouwer

A description of a firmware bug in external USB storage that cause disk error reports, and the way to avoid them.

Problem Description

When you connect an external USB drive you may see:

sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
sd 0:0:0:0: [sda] tag#0 Sense Key : Illegal Request [current] 
sd 0:0:0:0: [sda] tag#0 Add. Sense: Invalid command operation code
sd 0:0:0:0: [sda] tag#0 CDB: Write same(16) 93 08 00 00 00 00 00 00 00 22 00 00 00 06 00 00
critical target error, dev sda, sector 34 op 0x3:(DISCARD) flags 0x0 phys_seg 1 prio class 0
critical target error, dev sda, sector 40 op 0x3:(DISCARD) flags 0x800 phys_seg 1 prio class 2

If the following are true, you have the same problem:

  • You see DISCARD or UNMAP
  • You see Write same(16), and
  • The external storage is a spinning disk
  • You delete a lot of data, or reformat the disk

Explanation

These commands are all the same as what is also known as trim, which is used to tell an SSD disk to mark a data area as re-usable. Spinning disks do not support trim, and so reject it.

The kernel is attempting to run the command because the USB enclosure told the kernel that it supports the commands writesame16 or unmap. The error is reported because that command fails.

Root Cause

The root cause is that the USB enclosure supports the command in firmware, and the spinning disk does not. The USB enclosure fails to negotiate this command with the harddrive before negotiating it with the OS.

This happens when manufacturers use the same USB chips for SSD and spinning disk drives on the cheap.

Solution

The solution is to tell the kernel that this does not work, for this device, by using a udev rule, eg.

/etc/udev/rules.d/99-cheap-disk.rules
ACTION=="add", SUBSYSTEM=="scsi_disk", SUBSYSTEMS=="scsi",
ATTRS{vendor}=="WD", ATTRS{model}=="My Passport *",
OPTIONS="log_level=debug",
PROGRAM="/usr/bin/logger -t udev/99-cheap-disk Found cheap disk",
ATTR{provisioning_mode}="disabled"

In my case, the bad harddrive was a “Western Digital My Passport 2626“, with revision 1034.

Thanks

For the exact same problem and solution for SAN/NAS, see: Chris Hofstaedtler