  We propose $D$ mesons as probes to investigate finite-volume effects for
chiral symmetry breaking at zero and finite temperature. By using the
$2+1$-flavor linear-sigma model with constituent light quarks, we analyze the
Casimir effects for the $\sigma$ mean fields: The chiral symmetry is rapidly
restored by the antiperiodic boundary for light quarks, and the chiral symmetry
breaking is catalyzed by the periodic boundary. We also show the phase diagram
of the $\sigma$ mean fields on the volume and temperature plane. For $D$
mesons, we employ an effective model based on the chiral-partner structure,
where the volume dependence of $D$ mesons is induced by the $\sigma$ mean
fields. We find that $D_s$ mesons are less sensitive to finite volume than $D$
mesons, which is caused by the insensitivity of $\sigma_s$ mean fields. An
anomalous mass shift of $D$ mesons at high temperature with the periodic
boundary will be useful in examinations with lattice QCD simulations. The
dependence on the number of compactified spatial dimensions is also studied.
