Answer: According to the solar nebula, a hot burning star immediately after burning up all its fuel, exploded, releasing a huge amount of matter and energy and forms a cloud of dust particles and gases. After millions of years, the cloud got collapsed and due to gravitational pull, the materials all got accumulated becoming a huge ball and angular momentum caused the cloud to flattened into a disc. And this way, the solar system gradually formed and subsequently formed the planets.
The planetesimals are derived from this solar system later, after the formation of sun, due to the accumulation of materials along with various dust particles surrounding the sun in an orbit, because of the presence of gravity.