Try   HackMD

How to Clean Flash or Dirty Flash

A In-depth guide about clean flash and dirty flash on Android devices.
John YangMon, Jan 9, 2023

What Are the Differences?

What are the differences between "Clean Flash" and "Dirty Flash"?
Let’s start by explaining "Clean Flash" first. A clean flash requires you to format all of your data in the phone’s storage. That means that you’ll lose all of your data, including system data, cached files, Dalvik cache, and of course, internal storage.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Format Data will delete the phone's internal storage! Make sure you have made a backup of important data! THIS IS IRREVERSIBLE!

Dirty Flash a ROM is not recommended. It can cause all kinds of random problems.
The term "Dirty Flash" is commonly used to refer to an OTA (over the air) update or upgrading an old ROM to a newer version without having to factory reset or wipe your device.

The following steps will use TWRP to perform a Clean Flash and Dirty Flash.

How to Perform a Clean Flash and Install an ROM?

0) File Requirement

1) Boot into TWRP

  1. Boot your phone into bootloader mode. There are two diffent methed:
    • Using key combinations.
      • Every phone manufacturer has different key combinations to get into the bootloader mod. You'll have to look it up yourself.
    • Boot your phone into bootloader mode using adb commands
      • Enable developer options for your phone by pressing "Build number" in the Settings app multiple times.
      • Enable USB debugging option in developer options
      • Open a CMD terminal window. Press Windows Key + R then type in cmd then hit Enter
      • Navigate to the location where you store the Android platform tools using the command:
        cd C:\path\to\platform-tools\folder. If you did not store platform tools in C drive, just change the first letter.
      • Typing the flowing command into the terminal window:
        ​​​​​​​​​​​​adb reboot bootloader
        
      • After that, your phone should reboot into bootloader mode
  2. Connect your phone with the computer using a USB cable
  3. Extract the platform tools to whatever location that you like
  4. Put the previously downloaded TWRP image file in the platform tools folder for easy access
  5. Open a CMD terminal window. Press Windows Key + R then type in cmd then hit Enter
  6. Navigate to the location where you store the Android platform tools using the command:
    cd C:\path\to\platform-tools\folder. If you did not store platform tools in C drive, just change the first letter
  7. Typing the flowing command into the terminal window:
    ​​​​fastboot boot trwp-image-file.img
    
  8. Then your phone should be in the TWRP recovery

2) Formate Data

  1. In TWRP, click "Wipe"
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. Click "Format Data"
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. Type in "yes" to confirm formatting
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  4. After the prosses is done, click "Back" button
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  5. Now click on "Advanced Wipe"
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  6. Check Dalvic / ART Cache, System and Cache
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  7. Swipe to confirm wipe action
  8. After wiping is done, press back to go back to the main screen.
Credit ANDROID-ANDI https://andi34.github.io/faq/faq_twrp.html

3) Flash ROM

  1. In TWRP, click "Install"
  2. Click "Select Storage," then select "MicroSD"
  3. Select the ROM zip file
  4. Swipe to confirm flash
  5. After that's done, you can flash other files that you wanted to flash, like Magisk or GApps. If you want to flash Magisk, please see Magisk Preparations. If not, just continue.
  6. Press home button, to go back to the main screen
  7. Click "Reboot"
  8. Click "System"

How to Perform a Dirty Flash and Install an ROM?

How to Root The Device?

0) Preparations

  1. Download Magisk apk from https://github.com/topjohnwu/Magisk/releases
  2. Rename the file extension from apk to zip
  3. Put the renamed file into the phone's MicroSD storage

1) Boot into TWRP

2) Install Magisk

  1. Flash the renamed magisk.zip file the same way you flash ROM
  2. Reboot the device
  3. Start the Magisk app and follow the on screen instructions to complete the installation