To caramelize the onions: Melt the butter in a large deep frying pan over high heat until it bubbles, then add the onions and a pinch of salt, and cook until the onions are translucent, about 12 minutes. Add the sugar and cook over medium-low heat, stirring often, until the onions are turning brown and look all around caramelized, about 2 hours. Place the onions in a fine-meshed sieve to drain off the excess butter. Cool completely.