Animals will certainly feel the effect of an earthquake and react to it. Whether animals "know" is a tough question to answer. They probably don't have the concept of "earthquake". But some of them might have instincts that kick in when an earthquake is taking place.
Yes, the sentence 'How will you know if you passed it?' is grammatically correct. 'I'm pretty sure I passed my English exam.' 'How will you know if you passed it?' 'I'll find out when I go back to school on Monday.'
When an earthquake happens, seismic waves are formed. They are formed after two tectonic plates slide passed each other. When they slide passed each other, they get stuck, and when too much stress builds up there is a sudden release of energy. That is when the earthquake happens.