In igneous rocks, sulfur can be present as a primary mineral, such as pyrite (FeS2) or chalcopyrite (CuFeS2), which crystallize from magma.
In metamorphic rocks, sulfur can be remobilized and concentrated during metamorphic processes, forming sulfur-rich minerals such as pyrrhotite (Fe1-xS) or graphite (C).
In sedimentary rocks, sulfur can be present as a result of chemical precipitation from seawater, forming evaporite minerals such as gypsum (CaSO4·2H2O) or anhydrite (CaSO4). Additionally, sulfur can be introduced into sedimentary rocks through the decomposition of organic matter, forming sedimentary pyrite.