Melt 2 tablespoons of butter in a large skillet over medium heat. Add the sliced onions and cook, stirring often, until they turn golden brown and soft, about 20 minutes. Remove half the onions and set them aside for the gravy.
Stir the flour into the remaining onions in the skillet. Cook for 1 minute, then slowly whisk in the beef broth. Simmer until the gravy thickens, about 3 minutes. Season with salt and pepper to taste and set the gravy aside.
Preheat the oven to 375 degrees. In a mixing bowl, combine the ground beef, egg, breadcrumbs, thyme, salt, and black pepper. Mix in the reserved caramelized onions until evenly distributed.
Grease a 9x13 baking dish. Arrange the sliced potatoes in an even layer across the bottom. Spread the meatloaf mixture over the potatoes and press it flat.
Pour the caramelized onion gravy over the meat layer. Sprinkle the grated Gruyere cheese on top.
Cover the dish with foil and bake for 45 minutes. Remove the foil and bake 10 minutes more until the cheese melts and the potatoes feel tender when pierced with a knife.