[Sony Cross-Device Development Themes and Apps] mxperial:
I've thought on providing a user friendly clean install tutorial here (assuming that you coming from stock):

1. Get the last CarbonROM, the last Gapps (OpenGapps ARM or MindTheGapps ARM), the last stable or beta Magisk (Installer, Uninstaller and Manager) and the last TWRP.

2. If your device is D5833 get .575 and .291 roms (however you just need the kernels), if it is D5803 skip this step.

3. Follow this tutorial to root your phone.

4. Backup your DRM keys if you want (I personally like to backup them)

5. Now unlock your Bootloader using Flashtool (get the unlock code from here if you don't have it)

6. After get your bootloader unlocked flash again .291 rom

7. Get Minimal ADB and Fastboot

8. Copy the TWRP that you download to the Minimal ADB and Fastboot folder (C:\Program Files (x86)\Minimal ADB and Fastboot)

9. Run Minimal ADB and Fastboot as admin

10. Connect your phone in fastboot mode (press volume up and connect the usb cable)

11. In Minimal ADB and Fastboot type fastboot flash FOTAKernel <"twrp_name">.img and hit enter

12. If everything were OK type exit and hit enter

13. Now press volume down and the power button at the same time to boot in the recovery, when the phone vibrates release the power button, when the light came out release the volume down button. thanks [MENTION=346743]casouzaj[/MENTION] for this post.

14. Click on Wipe, Advanced and select and clear Everything (Dalvik/ART Cache, system, cache, Data, Internal Storage)

15. Go back and click on Install, find and install CarbonROM

16. Go back and click on Install, find and install Gapps

17. Go back and click on Install, find and install Magisk

18. Go back and click on Install, find and install Image Enchament and Smart Technologies (Optional - I installed but not sure if it is doing anything)

19. Go back and click on Install, find and install Oreo-XZ2-DisplayMod-for-XZ-XZs-XP (Optional - I installed but not sure if it is doing anything)

20. Reboot to system

21. Upgrade Magisk Manager (Swipe up on the main screen, find and open Files app, click on the on top left, select SD card, find Magisk Manager apk)

22. Open Magisk Manager and install SONY XPERIA XZ2 SOUND SYSTEM™ by [MENTION=7541648]sirdoha[/MENTION] (v1.35 Magisk recommended) (not necessarily anymore)

(Quick guide: Open Magisk Manager, click on the on top left, click on Modules, click on the "+" button on the center of the screen, give its permissions, search for the file and click on it).

23. Remember, after install any Magisk module, reboot your system, otherwise it will not get installed properly. (At least I've tried to flash many modules at once and it didn't work)

24. Install the right Sony Stock Camera Magisk Module on your device (Camera button acts just like in Sony Stock ROMs).

25. Install the right Xperia System Pack Magisk Module.

26. Install Xperia Camera Add-on Package Magisk Module.

27. If you want to boost your torch get the Magisk Module from here

28. Reboot. Done!

*If you reboot your system and didn't see the modules, just reboot your phone one more time. All done!

Congrats, welcome to the CustomROMs world. Now you need to set somethings up: 3rd Post

Press the ":good: Thanks!" button if you found this tutorial helpful!