Saute the onion and garlic in the butter until lightly browned and caramelized. Season with salt and pepper.
Add the flour to the caramelized onions and stir together to make a roux.
Then, add the heavy cream and stock. Season with salt and pepper as well. Stir until the sauce start to thicken then set aside.
In a greased pan, stack the potatoes slightly overlapping one another. Season with salt and pepper.
Add half of the cream sauce on top of that and spread it out evenly. Add about 1 cup of the shredded cheese on top.
Then, stack the rest of the potatoes and repeat the same steps. Add the cream sauce then the cheese, salt and pepper, and parmesan cheese.
Bake covered in a 400 F oven for 30 minutes then uncovered for another 30 minutes until the potatoes are fork tender. They may need lonher depending on the thickness of the cut of the potato.