Preheat oven to 350°F. Grease a 9×13-inch baking pan with butter.
Layer the potatoes and onions in the baking dish. Set aside.
In a medium saucepan, melt the butter over medium heat. Add in the garlic and cook until fragrant.
Sprinkle over the flour and whisk until smooth and the flour is golden, about 1 minute.
Slowly pour in the milk while whisking, making sure to quickly whisk out any lumps. Bring to a simmer.
Remove from the heat and whisk in the salt, pepper, cheddar, and ¾ cup gruyere until melted. Pour over the potatoes.
Cover with foil and bake for 45-60 minutes, or until the potatoes are tender when pierced with a knife in the center of the baking dish.
Remove the foil and sprinkle on the remaining gruyere and parmesan cheese. Bake for 15-20 minutes until the cheese is melted and bubbly.
Optional: To brown the cheese, broil for 1-2 minutes.
Garnish with herbs and serve.