  Solar eruptions are the most powerful drivers of space weather. To understand
their cause and nature, it is crucial to know how the coronal magnetic field
evolves before eruption. Here we study the formation process of a relatively
large-scale magnetic flux rope (MFR) in active region NOAA~12371 that erupts
with a major flare and coronal mass ejection on 2015 June 21. A data-driven
numerical magnetohydrodynamic model is employed to simulate three-dimensional
coronal magnetic field evolution of one-day duration before the eruption.
Comparison between the observed features and our modeled magnetic field
discloses how the pre-eruption MFR forms. Initially, the magnetic field lines
were weakly twisted as being simple sheared arcades. Then a long MFR was formed
along the polarity inversion line due to the complex photospheric motion, which
is mainly shearing rather than twisting. The presence of the MFR is evidenced
by a coherent set of magnetic field lines with twist number above unity. Below
the MFR a current sheet is shown in the model, suggesting that tether-cutting
reconnection plays a key role in the MFR formation. The MFR's flux grows as
more and more field lines are twisted due to continuous injection of magnetic
helicity by the photospheric motions. Meanwhile, the height of the MFR's axis
increases monotonely from its formation. By an analysis of the decay index of
its overlying field, we suggest that it is because the MFR runs into the torus
instability regime and becomes unstable that finally triggers the eruption.
