Sedimentary rocks are formed over long periods as mineral particles and rock fragments (sediments) accumulate in layers, compress under weight, and cement together. Igneous rocks form from cooled magma, and metamorphic rocks form from heat and pressure deep underground.