Bring a large pot of salted water to a boil. Add the spaghetti and cook for 3 to 4 minutes less than the package recommends, so that it is very al dente. Drain and reserve.
Preheat oven to 180 degrees C.
Grease a 22-by-33-cm cake pan with butter.
In a large skillet over medium-high heat, add the olive oil and sauté the onions for 4 to 5 minutes until translucent. Add the beef and leave to brown for 5 to 8 minutes; season with salt and pepper. Set aside.
In a large bowl, whisk together the marinara, ricotta, parsley, eggs, 1/2 cup of the Parmesan, 1 teaspoon salt and ¼ teaspoon pepper. Add the cooked spaghetti, beef and onions and toss to evenly coat.
Transfer to the prepared pan, top with the mozzarella and sprinkle with the remaining 2 tablespoons Parmesan.