Answer is: magnetism.
In rock formation, the tiny particles of iron in rock aligned at the same time with Earth's magnetic field.
Ferromagnetism is mechanism in which certain materials (for examle iron) form permanent magnets or are attracted to magnets.