The onset of unsteadiness in a boundary-layer flow past a cylindrical roughness element is investigated for three flow configurations at subcritical Reynolds numbers, both experimentally and numerically. On the one hand, a quasi-periodic shedding of hairpin vortices is observed for all configurations in the experiment. On the other hand, global stability analyses have revealed the existence of a varicose isolated mode, as well as of a sinuous one, both being linearly stable. Nonetheless, the isolated stable varicose modes are highly sensitive, as ascertained by pseudospectrum analysis. To investigate how these modes might influence the dynamics of the flow, an optimal forcing analysis is performed. The optimal response consists of a varicose perturbation closely related to the least stable varicose isolated eigenmode and induces dynamics similar to that observed experimentally. The quasi-resonance of such a global mode to external forcing might thus be responsible for the onset of unsteadiness at subcritical Reynolds numbers, hence providing a simple explanation for the experimental observations.