The formation of hot gaseous haloes around galaxies