Cut the guanciale in half first along its length and then widthwise, taking care to create cubes of the same thickness. Set aside.
Heat plenty of salted water in a saucepan.
When the water is boiling, pour in the spaghetti.
While the spaghetti cooks, pour a little olive oil into a pan and heat it over very low heat. Add the onion and cook until it turns golden. To prevent the onion from burning, it is best to keep the heat low and mix with a wooden spoon.
When the onion is golden brown, add the guanciale as well.
Lower the heat to low and stir with a wooden spoon until the guanciale is golden and has lost fat.
In the meantime, drain the pasta, remembering to set aside a little cooking water in case the final pasta mixture appears too dry.
Add the spaghetti to the sauce in the pan and, over medium heat, mix with a wooden spoon, adding the pasta cooking water if necessary.
Turn off the heat and complete the preparation of pasta alla gricia by sprinkling with plenty of grated pecorino and black pepper.