Formation of Earth's Magnetosphere