Ozone has a strong absorption band at 9.6 μm. Detection of this absorption band in the transmission spectra of transiting terrestrial exoplanets can provide us with the evidence of the existence of oxygen and thus the biosignature of extrasolar photosynthetic life. In this study, we use a 3D climate-chemistry model to simulate the ozone layer on tidally locked exoplanets in the habitable zone of M dwarfs, with four representative stellar spectra - the solar spectrum, the spectra of two ultraviolet (UV) active M dwarfs, and the spectrum of a UV inactive M dwarf. Our model simulations show that the total ozone abundance on exoplanets irradiated by UV-active M star spectra is comparable to the Earth’s, assuming the oxygen level is the same as that on the present Earth. If the oxygen level is lowered by two orders of magnitude, the exoplanets can still sustain significant ozone layers and a safe surface UV environment. These ozone layers can optimally give rise to a 40-km effective height of the atmosphere, which will be detectable with a photometric precision of 10-5 at 9.6 μm. However, for the UV-inactive M star spectrum, the ozone layer is extremely thin. It is spectroscopically undetectable, and the effect on the surface UV environment is negligible.