  Magnetic fields have been included in cosmological simulations of galaxy
formation only recently, due to advances in numerical techniques and a better
understanding of the galaxy formation physics. In this paper, we develop a new
subgrid model for the turbulent dynamo that takes place in the supersonic
interstellar medium in star-forming galaxies. It is based on a mean-field
approach that computes the turbulent kinetic energy at unresolved scales (the
so-called subgrid scales) and modifies the induction equation to account for
the corresponding $\alpha$ dynamo. Our subgrid model depends on one free
parameter, the quenching parameter, that controls the saturation of the subgrid
dynamo. Thanks to this mean-field approach, we can now model the fast
amplification of the magnetic field inside turbulent star-forming galaxies,
without relying on artificially strong initial fields or without using
prohibitively expensive high-resolution simulations. We show that the evolution
of the magnetic field in our zoom-in Milky Way-like galaxy is consistent with a
simple picture, in which the field is in equipartition with the turbulent
kinetic energy inside the star-forming disc, with a field strength around 10
$\mu$G at low redshift, while at the same time strong galactic outflows fill
the halo with a slightly weaker magnetic field, whose strength (10 nG) is
consistent will the ideal MHD dilution factor. Our results are in good
agreement with recent theoretical and numerical predictions. We also compare
our simulation with Faraday depth observations at both low and high redshift,
seeing overall good agreement with some caveats. Our model naturally predicts
stronger magnetic fields at high redshift (around 100 $\mu$G in the galaxy and
1 $\mu$G in the halo), but also stronger depolarisation effects due to stronger
turbulence at early time.
