in its first billion years, the earth had a lot of volcanic activity meaning lots of carbon dioxide, nitrogen and water vapour was released into the atmosphere.
there were also small amounts of methane and ammonia
the water vapour condensed to form oceans
2.7 billion years ago, plants and algae formed. They took in carbon dioxide and produced oxygen
the CO2 was buried in sediment forming oil and trapping the gas
coal is a sedimentary rock formed by dead plants
limestone is a sedimentary rock that is made up of shells and skeletons of marine organisms