How To Blacklist a Disk on Linux
Full disclosure: I got this from Claude after a bunch of more traditional research didn’t get me there.
Use case:
- you have a server with a bad disk
- and low urgency to replace the disk
- automation which detects and uses available disks
- also, the drive numbering is non-deterministic at boot
- so you want that disk to not be used until you get around to replacing it
The basic workaround to disable a disk, for example:
echo offline > /sys/block/sdd/device/state
That is fine until you reboot. You need something more robust.
Above, I suggested you had “automation which detects and uses available disks” so you could implement a blacklist mechanism in your automation. I thought I would mention that.
Okay, so, here’s the solution that Claude gave me. It works for me so now share with you.
First, get the serial number that udev sees. For example:
> udevadm info --query=property --name=/dev/sdd | grep ID_SERIAL_SHORT= ID_SERIAL_SHORT=abc123
And tell udev to … I think this means “when you add it, delete it”
> cat /etc/udev/rules.d/99-blacklist-baddisk.rules
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd?", ENV{ID_SERIAL_SHORT}=="abc123", ATTR{device/delete}="1"
Okay, so, why am I posting some AI slop? Well, because I like the idea that if you search for an answer on the Internet it ought to be out there somewhere. And whatever advice you find on online, in a blog, in a forum, or from an LLM, you need to test that out yourself. I found a solution that works for me, so I am posting it online for others to find, and test, and use.
I don’t reckon anyone is going to get on my case, but I figured I would offer that description and the caveat up top just so we’re all on the same page.
Comment
Tiny Print:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>