In a large pot, saute chopped onions in butter until they're soft but not browned.
Stir flour, salt, and pepper into the onion mixture.
3. Whisk in the milk and half and half. Cook over medium to low heat until the mixture begins to thicken. Stir so that it doesn't stick to the bottom of the pan. (This will take 2 to 3 minutes. Don't rush it or it can scorch on the bottom)
After the creamy mixture begins to thicken you can turn off the heat. Next, add 1 and ½ cups cheese to the sauce and stir till melted and smooth.
Layer half of the sliced potatoes and bacon in a 12x7-inch casserole dish. Top with half of the cheese mixture. Repeat layers.
Cover with foil and bake at 350° for 35 minutes.
Remove foil, sprinkle reserved cheese over top, and bake another 30 minutes or until potatoes are soft, cheese is melted and edges begin to brown. (When you put the potatoes back in the oven, you will not cover them with foil.) You can test the potatoes with a fork. The fork should easily pierce the potatoes when they're done.
Allow the casserole to stand 5 to 10 minutes before serving to allow the sauce to thicken.