In real life, medieval farming communities in area where the ground was stable enough quickly developed into miniature Underdarks. Since brigands and soldiers would come periodically to rape, kill, and pillage; the peasants needed some form of protection. They'd make tunnels and caves, with concealed entrances, and simple but nasty traps (or things such as arrowslits on both sides of the entrance corridor).
When troops were spotted, everybody would gather the cattle and other beasts, and everyone -- including livestock -- would enter the underground complex. It was also where most food stock and their meager wealth was kept.
The marauders would arrive, and find nothing. They could always torch the houses, but they were quickly rebuilt. And if they did find an entrance, it would be a slaughter for them: in the dark, in cramped corridors where they can't benefit from their military asset (no horse of course, and no space to swing a weapon), falling in simple traps (such as a mud pit, try to swim in the mud when you wear an armor), and getting attacked from the side by invisible attackers stabbing you with forks and such from another corridor through slits.
I see the dwarven commoners as using the same kind of methods, except in more dwarven. They do farm on the surface; but they live underground, and at the slightiest sign of a threat, everything and everyone disappear in hidden tunnels. But, since they're dwarves, a messenger will hurry through long-distance tunnels to the nearest dwarven garrison.
However, despite these farming communities, dwarven nations still need to import food. Which is where dwarven smiths and mercenaries get in the picture. The dwarves export tools, weapons, armors; and rent the services of engineers and soldiers. The money raised this way lets them buy the food supplies they need.