I've figured it out by myself. Here is the easiest step-by-step solution:
1. Make a copy of the keyboard layout/variant that you want to customize
I wanted to customize the Portuguese (Brazil, Dvorak) layout. Therefore I made a copy of the Brazilian Portuguese XKB layout file:
$ cp /usr/share/X11/xkb/symbols/br br-custom
2. Edit the layout file as you wish
Edit the copy of the layout file. You may follow the instructions in this question's answers to create your custom layout: What are the steps needed to create a new keyboard layout?
3. Install the customized layout file
First, backup the original layout file:
$ sudo mv /usr/share/X11/xkb/symbols/{br,br.bak}
Then install the file that you have just edited:
$ sudo cp br-curstom /usr/share/X11/xkb/symbols/br
Note: in the commands above, substitute the br
part by the name of the layout you are customizing.
4. Verify that the modified layout is working
Open the Settings application and go to Keyboard
> Input Sources
.
If the layout variant you want to use is not in the list of keyboard layouts, search and add it:

Then, click the three dots button at the right of the customized layout's name and select View Keyboard Layout
:

If the layout file is OK, a graphical representation of it should show up. If it doesn't, you may have introduced a syntax error when editing it or maybe included a layout component with the wrong name. You'll need to fix it before continuing.
5. Test the customized layout
After selecting the new layout in Settings, it will be set up for your user's desktop session. Open a text editor and check that your customizations are working accordingly. If it doesn't work as expected, edit the layout file again and reinstall it until it's right for you. Be careful to not overwrite the backed up version.
6. Apply the keyboard layout to the login screen and Linux console
When you are 100% sure that the customized layout is working, you may apply it to the login screen and the Linux console (the pseudo-terminals that are accessed by pressing Ctrl + Alt + F2 through Ctrl + Alt + F6).
Run this command and select the keyboard layout/variant you've just modified:
$ sudo dpkg-reconfigure keyboard-configuration

Finally, restart the PC and check if the customized layout was applied to the login screen as well.
/etc/default/keyboard
.