Oxygen gains two electrons when it bonds to form a complete outer shell and magnesium loses two electrons when bonding to gain its full outer shell.
As electrons are negative, the oxygen (which gains electrons) will become negative and the magnesium (which loses electrons) will become positive.
The negative and positive ions will then attract to one another due to the magnetic pull of the positive and negative.
Weathering and erosion produce ever smaller rock particles which,
when mixed with dust and decayed organic matter over time ,
result in different types of soil .
[hope this helps]