I think what you want is a derivation of the canonical ensemble from the microcanonical.
The microcanonical ensemble refers to a closed system, where we know that the conserved total energy is between ##U## and ##U+\delta U##. Given all the constraints, e.g., that a gas is confined in a given container of volume ##V## and that ##U## is in the above mentioned interval, the fundamental assumption of thermodynamics is that in equilbrium all the available microstates are found with equal probability.
Now let ##W(U)## be the number of microstates with an energy ##H(x,p)<U##, which is given by
$$W(U)=\int_{\mathbb{R}^{6N}} \mathrm{d}^{3N} x \mathrm{d}^{3N} p \frac{1}{h^{3N}} \Theta[U-H(x,p)].$$
Then the number of microstates in the energy shell considered above is
$$\Omega(U)=\delta U \frac{\partial W}{\partial U} = \delta U \int_{\mathbb{R}^{6N}} \mathrm{d}^{3N} x \mathrm{d}^{3N} p \frac{1}{h^{3N}} \delta[U-H(x,p)].$$
Now consider a small partial volume separated from the gas by a heat-conducting wall but inpenetrable for the gas particles and consider that still everything is in thermal equilibrium. Let's denote this subsystem with the label 1 and the rest system ("the heat bath") with label 2.
According to the fundamental principle the probability that part 1 has precise energy ##E_1## is proportional to the number of available microstates the heat bath can be in, i.e.,
$$P(E_1)=\frac{\Omega_2(U-E_1)}{\Omega(U)}. \qquad (1)$$
##\Omega(U)## is the total number of available states of the total system in equilibrium. Now the number of states for the total system, given that system 1 has energy ##E_1## is
$$\Omega(U|H_1=E_1)=\Omega_1(E_1) \Omega_2(U-E_1),$$
and both ##\Omega_1## and ##\Omega_2## are steeply raising functions of their argument. Thus the function above has a very sharp maximum, and thus the equilibrium state is charactrized by ##E_1=U_1##, where ##U_1## is the value, where the above function takes a maximum. For simplicity we define the entropy as
$$S(U|H_1=E_1)=\ln \Omega(U|H_1=E_1)=S_1(E_1) + S_2(U-E_1).$$
The condition for a maximum at ##E_1=U_1## is
$$\partial_{E_1} S(U|H_1=E_1)=\partial_{U'} S_1(U')|_{U'=U_1}-\partial_{U'} S_1(U')|_{U'=U-U_1}=0.$$
From phenomenological thermodynamics the condition for equilibrium for two systems in heat contact is the equality of temperature, and thus one defines
$$\partial_{U'} S_1(U')|_{U'=U_1}=\beta_1=\frac{1}{T_1}$$
and anlogously for system 2 (the heatbath). The equilibrium condition then is indeed
$$T_1=T_2$$
So we have with very good accuracy
$$\Omega(U)=\Omega_1(U_1) \Omega_2(U-U_1).$$
Taking the logarithm of (1) then gives
$$\ln P(E_1)=S_2(U-E_1) -S_2(U-U_1) -S_1(U_1)=S_2(U-U_1+U_1-E_1)-S_2(U-U_1) -S_1(U_1) = S_2(U-U_1) + \beta_2 (U_1-E_1)- S_2(U-U_1) -S_1(U_1) =(\beta_1 U_1-S_1) - \beta_1 E_1.$$
Now we have
$$(\beta_1 U_1 - S_1)=\beta_1(U_1-T_1 S_1)=\beta_1 F_1,$$
where ##F_1## is the free energy of part 1 of the gas. So finally we have
$$P(E_1)=\exp(\beta_1 F_1) \exp(-\beta_1 E_1).$$
Since
$$\int \mathrm{d}^{3N_1} x \mathrm{d}^{3N_1} p \frac{1}{h^{3N}} P(E_1)=1$$
we finally get
$$Z_1=\int \mathrm{d}^{3N_1} x \mathrm{d}^{3N_1} p \frac{1}{h^{3N_1}} \exp(-\beta_1 E_1)=\exp(-\beta_1 F_1)$$
or
$$F_1=-T_1 \ln Z_1.$$
From
$$\mathrm{d} F_1=\mathrm{d} (U_1-T_1 S_1)=T_1 \mathrm{d} S_1 - P_1 \mathrm{d} V_1 -T_1 \mathrm{d} S_1-S_1 \mathrm{d} T_1=-S_1 \mathrm{d} T_1 -P_1 \mathrm{d} V_1$$
we get
$$S_1=-\left (\frac{\partial F_1}{\partial T_1} \right )_{V_1,N_1}, \quad P_1=-\left (\frac{\partial F_1}{\partial T_1} \right )_{T_1,N_1}.$$
This we have used above in the derivation of ##S_1##.
Again we note that the correction due to indistinguishability of the particles in the sense of QT, one should put the ##1/N_1!## correction in front of ##Z_1## to get rid of the Gibbs paradox for the entropy, as discussed in my previous posting.