Preheat your oven to 350 degrees Fahrenheit. Spray a 2-quart casserole dish with cooking spray.
In a small saucepan over medium heat, melt the butter. Add in the onions, garlic, salt, and pepper. Sauté until the onions start to soften, about three minutes.
3 tablespoons unsalted butter, 1 small yellow onion, 1 teaspoon kosher salt, 1/8 teaspoon black pepper, 3 garlic cloves
Whisk in the flour until you no longer see any streaks of white. Then slowly whisk in the half and half, a few tablespoons at a time, adding more only once what you have just added has been absorbed. While you want to go slowly, this should only take about 1 minute. Bring to a simmer.
3 tablespoons all purpose flour, 2 cups half and half
Add 1 1/2 cups of the cheddar cheese, a few handfuls at a time, whisking to combine. Add more cheese once what you have just added is melted.
2 cups cheddar cheese
Layer half the potatoes in the bottom of the prepared pan. Top with half of the prepared cream sauce. Layer the second half of the potatoes. Top with the remaining cream sauce, then add the remaining 1/2 cup cheddar cheese and the Parmesan cheese.
2 cups cheddar cheese, 3 medium russet potatoes, 1/4 cup Parmesan cheese
Cover the casserole dish with foil and bake for 70 minutes. Remove the foil and continue baking for 20 minutes.