22 Jul 2025HTML

How to unlock almost any Xiaomi/MI devices bootloader from Linux

Hi friends, if you want to unlock any of your Xiaomi/MI devices via a Linux-based OS, you’ll often find that… oh! you need Windows.

But it’s really a bad thing for those who don’t use Windows OS. I use Linux OS, and I don’t wanna use Windows.

So I researched deeply and, after many findings and trial and error, I found a tool that worked for me:

So we’ll see step-by-step how to unlock it.

One more thing — when I was doing the unlocking, I wasn’t aware of the prerequisites exactly, so what I was doing was: switch off device, go to fastboot, then see error, then boot normally, then again follow the step, then again go to fastboot, then again get error… and repeat the same process back and forth many times.

If you’re here, I think you’ll unlock it in 1–2 shots. (If you get an error I didn’t get, you might still need to repeat many times, but I’ll show you a way that will minimize it.)


Pre-requisites

  1. You must have a SIM attached in your phone.
  2. Your SIM should have an active data plan (in some steps we need to connect via mobile internet only; Wi-Fi is not allowed).
  3. You must have a Xiaomi/MI Account.
  4. Your account must be linked with a phone number.
  5. Your account must be added in Mi Unlock Status.
  6. Your mobile must have USB debugging enabled.
  7. You must enable fastboot.
  8. Python 3.
  9. You must back up your data if not already done.

How to fulfill pre-requisites

  1. It’s simple.
  2. It’s simple.
  3. If not, create a new one (ensure mapping mobile number as well): https://account.xiaomi.com/pass/serviceLogin?checkSafePhone=true
  4. If you followed the previous step, then no worries. Else go to the same URL above.
  5. Go to Developer options » Mi Unlock status » Agree » Add account and device (here use your mobile data & turn off Wi-Fi).
  6. It’s simple (if you don’t know, search on the web or use generative AI).
  7. Go to Developer Options > Enable fastboot (or search on the web or generative AI).
  8. It’s simple (in almost all Linux distros, we can find it by default).
  9. Backup WhatsApp, files, folders, movies, pictures, notes, contacts, or others.

Now, whatever we need, we already have. One more thing — read this or reference it for any issues:

https://offici5l.github.io/articles/mi-error-codes.html

Error Code: 20041

 “sorry, your mi id is not associated with a phone number”

 The Xiaomi account is not linked to a phone number.

 Add a phone number to the Xiaomi account. (If the option to add a phone number is not available, it can be added via: )

Error Code: 10013

 “This device is not activated, please activate it and try to unlock it again”

 The issue is often due to a part (most likely the motherboard) being replaced in the device.

 Contact the Xiaomi support team.

Error Code: 20030

 “Sorry, couldn’t unlock more devices by this account this month”

 You are trying to retrieve new encryptData (token) in the same month.

 You must wait for the beginning of the next month, meaning the 1st of next month.

Error Code: 10000

 “Request parameter error”

 Invalid device token or product.

 Restart the tool. Always make sure you are using the latest version of the tool.

Error Code: 20035

 “Please upgrade your unlock tool”

 The tool uses an old version of clientVersion.

 If you are using Miunlocktool or official tool, download the latest version of the tool. If using MiUnlockTool, update the clientVersion to a higher version.

Error Code: 20031

 “Please add your account in Settings > Developer options > Mi Unlock status”

 You did not bind the account in ‘Mi Unlock Status’.

 Go to Developer options » Mi Unlock status » Agree » Add account and device.

Error Code: 20033

 “Your account is not authorized to unlock. Please change to another account”

 The account has been restricted from accessing the bootloader unlock service because Xiaomi’s servers detected suspicious activity.

 Sometimes, enabling ‘Find Device’ in settings can resolve the issue. If the problem persists, create a new account.

Error Code: 20045

 “Please use the common user tool on the official website”

 Invalid server region.

 Change server. In Termux, use ‘miunlock global’. In Windows, Linux, or MacOS, use ‘python3 Miunlocktool.py global’. Available servers: global, india, russia, china, europe.

 “The place where the account is registered does not match the place where the phone is sold.”

 The device is from China, and you are using a global Xiaomi account.

 Use a China account.

Error Code: 20038

 “该手机已被账号  通过查找手机锁定,无法解锁”

 device locked by account 

 Log in to account  in the following link: i.mi.com/mobile/find, select device, Disable Locate Device.

Let’s start!

1st, Connect your mobile to your Linux computer (you can also do it on another computer, but I’ve tested it on Linux, so I’ll always refer to Linux).

2nd, Ensure your USB debugging is enabled.

3rd, Then use the command below to clone the project:

git clone [email protected]:offici5l/MiUnlockTool.git

For safety purposes, I’ve forked it, so you can also clone my fork: https://github.com/kheersagarpatel/MiUnlockTool

Or you can download it from: https://github.com/offici5l/MiUnlockTool

4th, Go to that folder via terminal:

cd MiUnlockTool

5th, Run the ls command. You’ll get a result like this:

code.yml  LICENSE  MiUnlockTool.py  pyproject.toml  README.md

6th, After that, run the command:

python3 MiUnlockTool.py

Follow the steps provided by MiUnlockTool.py.

At one stage, it will show something like:

< waiting for any device >

Here, turn off your connected device and hold the Power + Volume Down buttons.

Your device will enter fastboot mode.

If everything is fine, at the end it will show you something like:

code 20036

Please unlock 168 hours later. And do not add your account in MIUI again, otherwise you will wait from scratch.

You can unlock (repeat this process) on: 2025-08-08 08:00
________________________________________________________

It means everything worked. Now wait for 7 days (or 168 hours). And do not add your account in MIUI again, otherwise you’ll have to wait from scratch.

If you don’t get this message, follow from step one.

After 168 hours, run the script again. (I’ll update here what happens, since I’m also waiting for it.)

 

You may also like

How to Open File Manager from Terminal in Linux?

Discover how to use the xdg-open command to open the file manager an...

Continue reading

Can't connect to a wired connection in Linux

Troubleshoot wired connection issues in Linux: check cables, network...

Continue reading

Web scraping with Python: How to use Python to extract data from websites

This article explores the process of web scraping with Python, inclu...

Continue reading