# How to Clean Flash or Dirty Flash
> A In-depth guide about clean flash and dirty flash on Android devices.
> [name=John Yang] [time=Mon, 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.
:::danger
:warning: 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
* Download the ROM that you wanted to install to the phone's MicroSD card, since you won't be able to access encrypted internal storage in recovery mode.
* Download the TWRP recovery image from the official website https://twrp.me/Devices/
* Download Android Debug Bridge (adb) from android developer website https://developer.android.com/studio/releases/platform-tools
### 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:
```cmd
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
8. Typing the flowing command into the terminal window:
```cmd
fastboot boot trwp-image-file.img
```
9. Then your phone should be in the TWRP recovery
### 2) Formate Data
1. In TWRP, click "Wipe"

2. Click "Format Data"

3. Type in "yes" to confirm formatting

4. After the prosses is done, click "Back" button

5. Now click on "Advanced Wipe"

6. Check Dalvic / ART Cache, System and Cache

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](#0-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?
* It's the same as [Flash ROM](#3-Flash-ROM) above
## 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
* See [Boot into TWRP](#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