The sun is a big ball of hot plasma which contains free electrons. However, how does the absence of metallic elements in the sun generate the magnetic field to orchestrate these free electrons to display such beautiful solar phenomenon?
Magnetic fields are generated by currents - i.e. by the motion of charged particles. As you say, the Sun is full of freely moving charged particles, and these generate currents which in turn generate magnetic fields. No metals required.
Most of the magnetic field generation is thought to occur at the interface between the radiative interior of the Sun and an outer convective envelope. This region, called the tachocline, is subject to large shearing motions which are able to take small magnetic fields and amplify them. The stronger magnetic fields are then buoyant, because magnetic fields in a plasma exert a pressure. They therefore emerge at the solar surface in the form of loops of magnetic field.
These loops are strongly coupled to the plasma in the Sun. As the plasma moves around turbulently, driven by convective motions and differential rotation on the Sun's surface, the footpoints of the loops are sheared and twisted. There comes a point where the loop will snap back into a configuration with lower magnetic potential energy through a process called reconnection. The reconnection process has a side effect of accelerating particles within the magnetic loops. These relativistic particles smash into the photosphere (actually, they are mainly stopped in the chromosphere which sits above the photosphere), where they release their energy, heating plasma to millions of degrees, which evaporates into the corona. This is a solar flare.
The Sun has a very powerful magnetic field. But the rotation of the Sun on its axis is uneven. The velocity of rotation is higher at the equator and lower at the poles. Due to the large difference in the velocities, the magnetic field lines gets twisted and turned that causes some of them to come really close. The instability causes an outburst seen as solar flares.