What type of bond do magnesium and sulfur form?
An ionic bond.
On the other hand, sulfur,
In this case, magnesium can complete its octet by giving up those two valence electrons, becoming the magnesium cation.
Sulfur, which only needs two electrons to complete it octet, will pick up the two electrons coming from magnesium, becoming the sulfide anion,
The electrostatic force of attraction will then bring the magnesium cations and the sulfur anions together
#color(green)(|bar(ul(color(white)(a/a)color(black)(["Mg"]^(2+)["S"]^(2-) implies "Mg"_2"S"_2 implies "MgS")color(white)(a/a)|)))#