  Context: Molecular hydrogen ($\rm{H_2}$) is crucial in galaxy formation and
evolution, serving as the main fuel for star formation (SF). In metal-enriched
environments, $\rm{H_2}$ primarily forms on interstellar dust grain surfaces.
However, due to the complexities of modelling this process, SF in cosmological
simulations often relies on empirical or theoretical frameworks validated only
in the Local Universe to estimate the abundance of $\rm{H_2}$.
  Aims: This study aims to model the connection between star, dust, and
$\rm{H_2}$ formation processes in cosmological simulations.
  Methods: We include $\rm{H_2}$ formation on dust grain surfaces and account
for molecule destruction and radiation shielding into the SF and feedback model
MUPPI.
  Results: The model reproduces key properties of observed galaxies for
stellar, dust, and $\rm{H_2}$ components. The cosmic density of $\rm{H_2}$
($\rho_{\rm{H2}}$) peaks around $z=1.5$, then decreases by half towards $z=0$,
showing milder evolution than observed. The $\rm{H_2}$ mass function since
$z=2$ also shows gentler evolution. Our model successfully recovers the
integrated molecular Kennicutt-Schmidt (mKS) law between surface star formation
rate ($\Sigma_{\rm SFR}$) and surface $\rm{H_2}$ density ($\Sigma_{\rm H2}$) at
$z=0$, already evident at $z=2$ with a higher normalization. We find hints of a
broken power law with a steeper slope at higher $\Sigma_{\rm H2}$, aligning
with some observational findings. Additionally, the $\rm{H_2}$-to-dust mass
ratio in galaxies shows a decreasing trend with gas metallicity and stellar
mass. The $\rm{H_2}$-to-dust mass fraction for the global galaxy population is
higher at higher redshifts. The analysis of the atomic-to-molecular transition
on a particle-by-particle basis suggests that gas metallicity cannot reliably
substitute the dust-to-gas ratio in models simulating dust-promoted $\rm{H_2}$.
