  The Hawking--Page phase transitions of the Schwarzschild and charged black
holes are investigated in an extended phase space, in which the black holes are
enclosed in a spherical cavity of radius $r_B$ in asymptotically flat space. An
effective thermodynamic volume $V=4\pi r_B^3/3$ is introduced for the black
hole, and an effective pressure $p$ is defined as the conjugate variable of
$V$. The phase transition temperature $T_{\rm HP}$ and the Gibbs free energy
$G$ are systematically studied in a grand canonical ensemble with fixed
electric potential $\Phi$, and $T_{\rm HP}$ is found to increase with $p$ and
decrease with $\Phi$. If the phase transition occurs, $\Phi$ must have an upper
bound, such that the cavity radius is always larger than the black hole horizon
radius. These phase transition behaviors are further compared to those in the
anti-de Sitter space, and the remarkable similarities and notable differences
are also discussed in depth. Our work reveals the relationship of the
thermodynamic properties of black holes and their specific boundary conditions
in different extended phase spaces.
