By definition, you can’t. Any software level solution will fail since you can just move the drive somewhere else. It must be baked into the hardware and firmware.
Edit to add further clarification. Do you need it to be failing on every device or just on a device that you control? Since as stated before, moving a mass storage will completely overthrow any software solution