Spray an 8 x 11 inch casserole dish with non-stick cooking spray.
In a medium-size saucepan, melt butter over medium heat.
Mix in the flour, salt, and garlic powder and stir constantly with a whisk for one minute.
Stir in milk.
Cook until mixture has thickened.
Stir in cheese all at once, and continue stirring until melted, about 30 to 60 seconds.
Layer 1/2 of the potatoes into the bottom of the prepared casserole dish and season with salt and pepper.
Top with the diced onions, then pour half of the cheese mixture on top of the onions.
Layer the rest of the potatoes, season with salt and pepper, and top with the remaining cheese sauce.
Cover the dish with aluminum foil and bake for 80-90 minutes (I usually remove the foil for the last 15 minutes so that the top can brown just a little bit).
Notes
Make sure to uncover that last few minutes of baking to get that golden brown goodness.