Given a sufficiently smart adversary with significant resources, you can't.
There are five potential attack vectors:
- Malware on the disk within a partition.
- Malware within the boot sector.
- Malformed partition or filesystem structures that exploit bugs in your OS (example)
- Malware within disk firmware.
- Modified hardware (e.g. replace the firmware PROM with mask ROM containing malware)
Malware on a filesystem on the drive is easily defeated by formatting the disk when you get it.
Boot sector malware is a little trickier. Whilst an OS install would overwrite the boot sector anyway, this doesn't apply to drives that are going to just be used for data. This kind of thing can be fixed by doing a low-level wipe of the disk with dd or a similar tool, or by re-writing the boot sector with a disk maintenance tool.
Malformed partitions or filesystems can be killed with dd, but then you still have to get into an OS to run the command. It's a good idea to do the first format operation from a Live CD with no other persistent storage attached.
The modified firmware issue is a very tricky one. We know that hard disk firmware can be modified, and there are surely patch vectors from the OS level. Detecting malicious firmware is a tricky task, and you can only really get assurance of firmware integrity by manually (i.e. at the electrical interface level) overwriting the firmware with a manufacturer-supplied and digitally signed firmware image. Since you'd be interfacing directly with the EEPROM, and would be able to read the image back and verify its integrity, you'd have strong assurance that the "safe" firmware was written. This doesn't fix the problem of backdoors at the manufacturer's end, though.
Finally, there's the potential for modified hardware. In such a case, the firmware EEPROM could be ignored in favour of a mask ROM, stored either externally or inside the controller IC package, so that flashing the firmware seems to work but does not actually succeed in changing the firmware code that is actually executed by the device.
At the end of the day, though, does it even matter? Most of the time you're going to get a clean hard disk, and things have to be going very wrong somewhere in the world if you end up with boot sector malware on a signed-and-sealed disk. If an adversary can find out that you've got a hard disk on order from Amazon, get another of that exact drive, backdoor its firmware or hardware in a useful way, break into the delivery truck, and replace the disk with a modified one without anyone noticing, then you are screwed no matter what.
In summary, I'd like to quote from an excellent paper by James Mickens:
If your adversary is the Mossad, YOU’RE GONNA DIE AND THERE’S NOTHING THAT YOU CAN DO ABOUT IT. The Mossad is not intimidated by the fact that you employ https://. If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone, and when you die of tumors filled with tumors, they’re going to hold a press conference and say “It wasn’t us” as they wear t-shirts that say “IT WAS DEFINITELY US,” and then they’re going to buy all of your stuff at your estate sale so that they can directly look at the photos of your vacation instead of reading your insipid emails about them.