Temperature and pressure being equal at equilibrium (from first law of thermodynamics) I have a question in which an insulated container of gas with volume $V$ is divided into two parts $V_1$ and $V_2$ by a movable barrier through which energy can pass, and need to show that, using the first law of thermodynamics $$dE = T dS - p dV$$ that in equilibrium, the temperatures and pressures in the two parts are equal.
What actually is meant by "equilibrium" in this situation? If this is the usual interpretation in which no energy is exchanged, then we would have $dE=0$ on both sides of the permeable barrier, but the volume isn't changing on either side since surely the barrier only allows the exchange of energy between the sides, rather than allowing the gas particles to mix. How would you actually show that the temperatures and pressures are equal on both sides when in (presumably no energy change) equilibrium?
 A: It is not enough to assume energy conservation in the form of the Gibbs equation $d=TdS-pdV$ to hold. You must also take into account that upon removing the constraint, in this case to allow to move the partition to a new location and equalizing temperatures between parts, in the new equilibrium the total entropy is at a maximum.
The way to do this is to write for the two parts before the partition is allowed to move and conduct heat as
$$dE_1=T_1dS_1-p_1dV_1\\dE_2=T_2dS_2-p_2dV_2 \tag{1}\label{1}$$
or $$dS_1=\frac{1}{T_1}dE_1-\frac{p_1}{T_1}dV_1\\dS_2=\frac{1}{T_2}dE_2-\frac{p_2}{T_2}dV_2 \tag{2}\label{2}$$
The constraints are $$V_1+V_2=V_0\\E_1+E_2=E_0$$
and from $dE_0=0$ and $dV_0=0$ (isolated rigid container)
$$dV_1=-dV_2\\dE_1=-dE_2$$ that we substitute into $\eqref{2}$ and add them up:
$$dS=dS_1+dS_2=\frac{1}{T_1}dE_1-\frac{p_1}{T_1}dV_1+\frac{1}{T_2}dE_2-\frac{p_2}{T_2}dV_2\\
=\left(\frac{1}{T_1}-\frac{1}{T_2}\right)dE_1-\left(\frac{p_1}{T_1}-\frac{p_2}{T_2}\right)dV_1 \tag{3}\label{3}$$
For infinitesimal variations of $dE_1$ and $dV_1$ the total entropy $dS=0$ because of those are reversible changes, thus we must have in equilibrium
$$T_1=T_2 \\p_1=p_2\tag{4}\label{4}$$
