I've been struggling for a while now in understanding the concept of entropy as a function of the internal energy. Textbooks typically call $g(E)$ the number of microstates compatible with an energy $E$ of the system. Then they say that the entropy is given by the Boltzmann formula as $S(E)=k \ln g(E)$. Here the energy is precisely fixed to be $E$.
Consider now two systems, isolated from the outside. They are brought into contact, allowing for an exchange of energy. Equilibrium is then said to be established when $g_1(E_1)g_2(E_2)$ has a maximum, or, equivalently, $S_1(E_1) + S_2(E_2)$ has a maximum. From this condition then the temperature is introduced as $1/T = \partial S_1(E_1) / \partial E_1 = \partial S_2(E_2) / \partial E_2$. Now, however, $E_1$ and $E_2$ can fluctuate because of the interchange of energy between the two system, thus we have no precise knowledge of either of them. One could argue that, if the system is big enough, then $g(E)$ is so narrow that fluctuations in the energies are negligible and $E_1$ and $E_2$ can simply be replaced by their mean values.
My question is, what happens in the case of small systems? There are examples of single particle systems put in contact with a heat bath and equilibrium properties of those systems are calculated as if they were infinitely large. In particular, how would one define temperature for such a single particle system? Is its temperature $\partial S(E) / \partial E$ or $\partial S(\langle E \rangle ) / \partial \langle E \rangle$? If the former, how can we say the system is at constant temperature if $E$ fluctuates? If the latter, how would you go from the Boltzmann formula $S = k \ln g(E)$ to $S = k \ln g(\langle E \rangle)$?