It came from CO2 and other carbon gasses. IIRC, according to current theory, there were 3 major climates in the earth. In the first climate, the atmosphere was volcanic gasses, many of which were blown off into space, leaving the second climate of carbon gases as a residue, and then this was absorbed into rocks as well as consumed by CO2 breathing lifeforms.