Aims. The production of molecular hydrogen and its deuterated forms onto carbonaceous dust grains is investigated in detail. The goal of this study is to estimate the importance of the chemistry occuring on grain surfaces for the deuteration of H 2 . Furthermore, we aim to find a robust and general surface chemical model that can be used in different astrophysical environments. Methods. Surface processes are described for the cases of graphitic and amorphous-carbon grains, where laboratory work is available. Langmuir-Hinshelwood, as well as Eley-Rideal surface chemistries are included in the model and their relative contributions highlighted. Analytic expressions are derived for H 2 , HD, and D 2 formation efficiencies for both types of grains. Rate equations are tested against stochastic methods. Results. As expected, rate equations and stochastic methods diverge for grain sizes below a critical value a crit . For these sizes, D 2 formation decreases to favour HD formation. The formation efficiencies of H 2 and D 2 can be calculated by adding a correction factor to the rate equations methods (this factor is a simple exponential factor that becomes unity when a > a crit ). We find that, because of the presence of chemisorbed sites, which can store atoms to form molecules up to high grain temperatures, the formation efficiency of HD and D 2 is very high compared to models where only physisorption sites are taken into account. When considering a realistic distribution of dust grains, we find that the formation rates of H 2 and HD are enhanced by an order of magnitude if small grains are taken into account. The formation of D 2 , on the other hand, comes from the contribution of small (≤100 Å) and big (≥100 Å) grains, depending on the D/H ratio, the grain temperature, and the volume density. The processes described in this paper, which allow a strong enhancement of the deuterated forms of molecular hydrogen, could explain the high degree of deuterium fractionation observed in protostellar environments.