
The acceleration of the entire system is given by:
In order that small mass 2 not move vertically the tension in the string must equal the force of gravity:
The tension in the string is what is responsible for accelerating the small mass 1 (note that there is no friction so tension is the only force acting on this small mass).
Using the two equations for T we have a relation between a and g. Finally:
By the way, the force causing the acceleration of the small mass 2 is f, the force the large mass M exerts on the smaller mass.