  Magnetic fields are known to be dynamically important in the interstellar
medium of our own Galaxy, and they are ubiquitously observed in diffuse gas in
the halos of galaxies and galaxy clusters. Yet, magnetic fields have typically
been neglected in studies of the formation of galaxies, leaving their global
influence on galaxy formation largely unclear. We extend our MHD implementation
in the moving-mesh code Arepo to cosmological problems which include radiative
cooling and the formation of stars. In particular, we replace our previously
employed divergence cleaning approach with a Powell 8-wave scheme, which turns
out to be significantly more stable, even in very dynamic environments. We
verify the improved accuracy through simulations of the MRI in accretion disks,
that reproduce its correct linear growth rate. Using this new MHD code, we
simulate the formation of isolated disk galaxies similar to the Milky Way using
idealized initial conditions with and without magnetic fields. We find that the
magnetic field is quickly amplified in the initial starburst and the
differential rotation of the forming disk until it eventually saturates when it
becomes comparable to the thermal pressure. The additional pressure component
leads to a lower star formation rate at late times compared to simulations
without magnetic fields, and induces changes in the spiral arm structures of
the gas disk. In addition, we observe highly magnetized fountain-like outflows
from the disk. These results are robust with numerical resolution and are
largely independent of the initial magnetic seed field assumed in the initial
conditions, as the amplification process is rapid and self-regulated. Our
findings suggest an important influence of magnetic fields on galaxy formation
and evolution, cautioning against their neglect in theoretical models of
structure formation.
