Some, but not all, earthquakes are related to volcanoes. For example, most earthquakes are along the edges of tectonic plates. This is where most volcanoes are too. However, most earthquakes are caused by the interaction of the plates not the movement of magma.
Most earthquakes directly beneath a volcano are caused by the movement of magma. The magma exerts pressure on the rocks until it cracks the rock. Then the magma squirts into the crack and starts building pressure again. Every time the rock cracks it makes a small earthquake. These earthquakes are usually too weak to be felt but can be detected and recorded by sensitive instruments. Once the plumbing system of the volcano is open and magma is flowing through it, constant earthquake waves, called harmonic tremor, are recorded (but not felt).
The distribution of earthquakes provides information about magma pathways and the structure of volcanoes. The red dots show earthquakes associated with magma movement. They define the east and southwest rifts of Kilauea. The blue dots show earthquakes associated the sliding of the south flank of Kilauea. Photograph courtesy of U.S. Geological Survey.