First-principles calculations were performed to understand the relationship between grain boundary energy and free volume in magnesium. A linear relationship between grain boundary energy and free volume was found not only in pure Mg grain boundaries, but also in segregated grain boundaries. This indicates that the free volume is determined by both the mechanical effect (e.g. misfit strain) and the chemical effect (e.g charge transfer), and even strong covalent-like bonding cannot break down the linear relationship. However, only Ca and Y segregated grain boundaries deviated from the linear relationship. The origins of deviation for the Ca and Y segregated grain boundaries are discussed.