Answer:
The hard drive is split into many small regions, each containing a few hundred magnetic grains that are used to store one bit.
The writing head of the hard drive contains an electromagnet or similar that can be used to turn magnetism on or off in the magnetic grains. The reading head can then read this information.
The principle is pretty much the same as the one previously used for recordable tapes, whether music cassettes or VHS video tapes.
See related links.