  We develop a model of globular cluster (GC) formation within the cosmological
hierarchy of structure formation. The model is rooted in the `two-phase'
scenario of galaxy formation developed in Paper-I, where the fast accretion of
dark matter halos at high redshift leads to the formation of self-gravitating,
turbulent gas clouds that subsequently fragment into dynamically hot systems of
dense sub-clouds with masses $\sim 10^6$-$10^7 M_\odot$. Here we elaborate on
the formation, evolution, and fate of these sub-clouds, and show that some of
the sub-clouds can be compactified via two distinctive channels into a
'supernova-free' regime to form two distinct populations of GCs. The model is
simple, characterized by a small number of free parameters underpinned by
physical considerations, and can be efficiently implemented into cosmological
N-body simulations to generate a coherent sample of halos, galaxies, and GCs.
Our model can reproduce a range of observations on GCs, including the mass
function, the size-mass relation, the frequency per unit host galaxy/halo mass,
the bimodal metallicity distribution, and the spatial profile. Predictions for
GCs are made for both the local Universe and for redshift up to $z \approx 10$,
and can be tested by upcoming observations.
