How to install OpenWrt on Xiaomi Mi Router 3

(last update: 11-May-2020)

OpenWrt is an embedded operating system based on Linux. You will get full power of Linux in your home router. OpenWrt has a lot of powerful features that default firmware doesn’t offer.

There are several OpenWrt based firmwares for Xiaomi Mi Router 3. Among of them, PandoraBox and X-Wrt work very well in Xiaomi Mi Router 3. However, PandoraBox is discontinued. Means Mi Router 3 might not get any latest update from PandoraBox. So right now, installing X-Wrt firmware for Mi Router 3 will be better choice. It also supports latest software packages from OpenWrt repository.

Before continuing the firmware installation, let’s see what OpenWrt offers beside the default Xiaomi’s Chinese firmware:

  1. Supports ALL kinds of popular VPN protocols. (OpenVPN, L2TP, PPTP…)
  2. Torrent client. You don’t need to always power up your PC for downloading/seeding the big torrent files anymore. Your router will work as a low powered Seedbox.
  3. Run various servers. You can run a web server, a proxy server, IRC server and more!
  4. Using QoS (quality of service) which handles the packets travelling through your router. You can prioritize certain types of traffic with QoS. This is my favorite use case as I can reduce the lag while gaming by properly configuring the QoS.
  5. Capture the network traffic. You can capture the network traffic by using various network tools and analyze that traffic later. Useful to the network admin
  6. Real time accurate bandwidth monitoring and throttling.
  7. Monitor internet connectivity
  8. Ad blocking
  9. DNSCrypt (only possible in X-Wrt firmware)

and much much more. OpenWrt’s software repositories contain other packages that extends more functionality.

NOTE: There is no mobile app to control OpenWrt firmware as Xiaomi firmware does. Also, it is not easy to configure OpenWrt firmware. You need to have absolute patience and troubleshooting capability in order to configure it like the way you want. Also, if you are not a techie person, I will not recommend you to proceed.

Disclaimer

I will not take any responsibility if you brick your router by incorrectly following this tutorial. Though I’ve tested every steps several times and successfully install OpenWrt on my Xiaomi Router. I’ve bricked my router many times in order to find the right steps :p

Some basic knowledge of Linux commands and SSH are necessary.

Note: if you brick your router, please follow Recovering from softbrick

If still not solved, please post your issue to the support forum. I will suggest you to take your time and read this support forum from the beginning. It holds lots of useful information regarding flashing and recovering.

Let’s begin (bricking or succeeding? :p )

What you need:

1. Xiaomi Mi WiFi Router 3 (2 100Mbps non gigabit LAN ports)
2. LAN Cable
3. USB Drive
4. Enough time
5. Brain/common sense

Step 1: Downgrading the official Xiaomi firmware to dev build

1.1. First, assuming that you are using official Xiaomi firmware. Backup your settings if you needed. Now, we need to downgrade to the dev build in order to enable SSH service. So download dev firmware from here:

1.2. Put downloaded “miwifi_r3_all_55ac7_2.11.20.bin” file on FAT/FAT32 formatted USB drive and rename it to “miwifi.bin” (without quote)

1.3. Power off the router and plug the USB into the router. Now hold the reset button and power it up until the yellow led starts flashing. A solid blue will appear after a few moments. We just flashed the dev firmware. Remove the USB.

Step 2:  Download firmware & preparing the flash file

For PandoraBox firmware:
2.1. Download the firmware file from here
2.2. Download Pandorabox boot file from here
2.3. Put “pb-boot-xiaomi3-20180726-0d8505f.img” file (boot file) to your FAT/FAT32 formatted USB drive

For X-Wrt firmware:
2.4. Download kernel1.bin & rootfs0.bin for “Xiaomi Mi Router R3” from here
2.5. Put both files to your FAT/FAT32 formatted USB drive

Step 3: Turning on SSH on Router

3.1. Connect your router through wifi with a default password.
3.2. Go to http://miwifi.com or http://192.168.31.1 and setup your router as usual.
3.3. Login to admin panel. Look at the url bar.
3.4. In url bar, after “stok=”, copy the code.


3.5 Replace the <STOCK> code in the below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=<STOK>/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3Bnvram%20set%20ssh%5Fen%3D1%3B%20nvram%20commit

3.6. If your wifi disconnect, then connect again. Follow 3.3 and 3.4 step again
3.7. Replace the <STOCK> code in below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=<STOK>/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3Bsed%20%2Di%20%22%3Ax%3AN%3As%2Fif%20%5C%5B%2E%2A%5C%3B%20then%5Cn%2E%2Areturn%200%5Cn%2E%2Afi%2F%23tb%2F%3Bb%20x%22%20%2Fetc%2Finit.d%2Fdropbear

3.8. You will probably disconnect again. Reconnect and follow 3.3 and 3.4 steps.
3.9. Replace the <STOCK> code in below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=<STOK>/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3B%2Fetc%2Finit.d%2Fdropbear%20start

3.10. Again (one last time) you will be disconnected. Connect again and follow 3.3 and 3.4 steps.
3.11. Replace the <STOCK> code in below url and visit that url. BUT replace OLD_PASSWORD with your admin panel password (that you provided in step 3.2) and NEW_PASSWORD with your desire password

http://miwifi.com/cgi-bin/luci/;stok=<STOK>/api/xqsystem/set_name_password?oldPwd=OLD_PASSWORD&newPwd=NEW_PASSWORD

Step 4: Entering into SSH and flash firmwares:

4.0. Connect USB drive to router
4.1. Download and open PUTTY client
4.2. In SSH field, put your router IP address (192.168.31.1) and connect
4.3. Username is ‘root’ and password is NEW_PASSWORD

For PandoraBox
4.4. Issue below commands one by one:

cd /extdisks/sda1
cp pb-boot-xiaomi3-20180726-0d8505f.img /tmp
cd /tmp
mtd write pb-boot-xiaomi3-20180726-0d8505f.img Bootloader
reboot

4.5. Wait until the led turns into blue
4.6. Power off the router (disconnect the power cable) and then hold the reset button then power up the router, release the reset button after 2/3 seconds after powering up. You will see breath style yellow led will glow
4.7. Connect your router through LAN cable. Cable will go from router’s LAN port (not internet/wan port) to your PC.
4.8. Now go to http://192.168.1.1 (while connected with LAN), you will see a PandoraBox firmware upgrade page. select your Pandorabox firmware (downloaded from step 2.1) and upload it. Router will be restarted when done.
4.9. Access the PandoraBox OpenWrt admin page by going http://192.168.1.1, default password is “admin”. Language is by default Chinese. Don’t panic if you don’t understand anything. Just go to the following link to change language.
4.10. Select language “Chinese” to “auto”
4.11. Save and apply (middle button at the very bottom)

For X-Wrt
(If you are already on PandoraBox firmware and want to upgrade to X-Wrt, jump to step 4.15)

4.12. Issue the below commands one by one (source: https://openwrt.org/toh/xiaomi/mir3)

nvram set flag_last_success=1
nvram set boot_wait=on
nvram set uart_en=1
nvram commit
cd /extdisks/sda1
mtd write x-wrt--ramips-mt7620-xiaomi_miwifi-r3-squashfs-kernel1.bin kernel1
mtd write x-wrt--ramips-mt7620-xiaomi_miwifi-r3-squashfs-rootfs0.bin rootfs0
reboot

4.13. After a few minutes, visit 192.168.15.1 and login with username: root, password: admin

4.14. To change firmware language to english, follow the instructions in the images:

Upgrade from PandoraBox to X-Wrt
If you are using PandoraBox and want to upgrade to X-Wrt, follow the below steps (source: https://openwrt.org/toh/xiaomi/mir3)
4.15. Download x-wrt——-ramips-mt7620-xiaomi_miwifi-r3-squashfs-breed-factory.bin file from here
4.16. Put the file in FAT/FAT32 formatted USB drive
4.17. Issue the below commands:

cd /extdisks/sda1 
mtd write x-wrt-------ramips-mt7620-xiaomi_miwifi-r3-squashfs-breed-factory.bin firmware 
reboot

Now follow 4.13 & 4.14

If it dosn’t work (blinking orange on boot):
4.18. Connect your router through LAN cable. Cable will go from router’s LAN port (not internet/wan port) to your PC.
4.19. Access 192.168.15.1 from browser
4.20. Upload “x-wrt——-ramips-mt7620-xiaomi_miwifi-r3-squashfs-breed-factory.bin” file and flash. Done

If you come this far, congratulation! You have successfully installed OpenWrt to your Xiaomi R3 router. Now configure internet connectivity.

50 thoughts on “How to install OpenWrt on Xiaomi Mi Router 3

  1. Ramom

    Hello, congratulations on the tutorial.

    Can I use the latest firmware and boot?

    1. Kamrul

      Hello, I tried other versions and I found the mentioned version is very stable for day to day work. You can definitely try the latest version.

      Thank you for the comment.

    2. makima

      what version you ended up with? cheers

  2. Miecz

    no matter what i do, i cant get to cd directory…

    1. Kamrul

      Did you connect your usb drive? Otherwise, you won’t be able to cd in external drive

    1. Kamrul

      Yes. USB 2.0, 2 ports 100mbps, non-gigabit.

      1. makima

        great, will install openwrt using your tutorial today. i do hope i won’t brick it)
        thanks again and have a great 2020!

        1. Kamrul

          Good luck. Please let me know whether you succeed or not. Happy new year.

          1. makima

            all went smooth! thank you for the how-to!

          2. Kamrul

            Glad you didn’t brick your router :p Congratulation!

    1. Kamrul

      I would definitely try if I had a spare router. I don’t want to install the new update in my home router as I don’t know if it will work as stable as 18.12. However, you can try upgrading if you want. Thank you

      1. makima

        can i upgrade to OpenWRT if we are now using PandoraBox?

        1. Kamrul

          PandoraBox is based on OpenWRT

    2. Tom

      Did you tried upgrade to 19.07.0?
      Did you bricked the router?
      Thanx.

  3. Ben

    Ive reinserted my usb but it still wont let me cd to the external drive

    1. Kamrul

      Please make sure that the usb drive is formatted with FAT/FAT32 and try again.

  4. Fabio

    Hi, thank you for the time you’ve spent for us. I followed your instruction untill “4.5. Wait until the led turns into blue”, but my led is stuck un purple and I can’t access the router anymore…. Can someone help me? Thanks in advance

  5. Adnan

    My Xiaomi Mi Router 3 got bricked and the LED is turned to orange.

    Tried the reset button – USB drive – power up combination but it didn’t work.

    Can anyone please help me fix this problem?

  6. zeti

    Thanks man, were you able to use airodump?

    1. Kamrul

      I didn’t try. I don’t think it supports monitor mode. Anyway thanks for reading

  7. Ajai

    Hey Kamrul, can you tell me which one is better Padavan or openwrt..

    I am currently using Padavan but this doesn’t have QOS built-in…. hence i am looking for a different firmware..

    Also in padavan project, i noticed that they have stopped maintaining the project.

    Please suggest..

    1. Kamrul

      In this tutorial, I used pandorabox which is also stopped making the OpenWRT based firmware for Xiaomi Mi Router 3. The last version is 19.01. There is no official OpenWRT firmware for Xiaomi Mi Router 3 router. So if you need OpenWRT based firmware, pandorabox is your best shot.

      If you need advance feature like QOS, per user bandwidth monitoring (the only reason why I switched from padavan to pandorabox), then you need pandorabox. Those features work smoothly in pandorabox

  8. Mehmet

    Hello Kamrul,
    how can i switch from Padavan to OpenWRT. I installed Padavan maybe 1 year ago and now i want to change it to OpenWRT. I dont have stock firmware as you described in your tutorial. Can you describe shortly which method i can use to install Openwrt on my Xiaomi Router 3 with Padavan Firmware.

    1. Hoang

      You can start from flashing PandoraBox (4.4), then move to x-wrt. There is no need to back to stock

  9. Fouad

    Thanks for that great tuto.
    I install Openwrt, use it as repeater but the Internet access is extremely slow even when use direct connection in LAN.
    How get back to original fw from Openwrt.
    Thanks

  10. M

    Hi
    How can I install the Xiaomi firmware?
    Thnx

      1. M

        but how can i transfer files to cd/ tmp

        1. Kamrul

          You can use MobaXterm

  11. Mohiuddin

    Can someone plz confirm that repeater mode is working well? I specifically need WISP mode to work.

    1. Kamrul

      Please upgrade/install X-Wrt firmware first. I didn’t try the repeater mode myself but it should work.

  12. Ajai

    Hey Kamrul,
    Have you used x-wrt in MI router 3 ?
    Recently i came across their website..
    They have been posting weekly builds of Mi router 3..

    1. Kamrul

      Hello Ajai, yes I tried. Currently I am on X-Wrt. It is better than PandoraBox in every aspect. I updated my post. Thank you for reading.

  13. Hesam Hanari

    Hi there
    I flashed x wrt with this guide. But I can’t go to 198.168.15.1
    How can i know my routers ip? I looked up in windows adaptor settings and it was 192.168.1.53 but it wasn’t work either
    Also what’s routers default password? My SSID is : X-WRT_CD27 I don’t know password

  14. Ajai

    Thanks for your reply kamrul..

    Also, please add to post on how to update the x-wrt version to latest release.. like a web upgrade or something.

  15. makima

    i see you know prefer X-WRT over PandoraBox? i’ve used your tutorial when there was no X-WRT part in here.

    is it better? stable?
    i thought our router does not have support for breed?

    1. Kamrul

      Hello, thanks for your input. I flashed X-Wrt several days ago and found a severe issue. For some reason the router couldn’t establish stable internet connection. It was disconnecting internet frequently. Maybe it just happened to me for some reason. After some troubleshooting, I found that it wasn’t my internet issue. Something wrong in X-Wrt. Then I switched back to PandoraBox and everything is running smooth as before. So I am sticking with PandoraBox again as it was stable enough for me for daily usage.

      1. makima

        got it, same here – PandoraBox is working flawlessly so why bother! one question though: can we install packages like in openwrt? say i want to install adblock package, can we do this?

  16. Arga

    X-wrt on mine working perfectly,
    I just dont know how to use DNS over TLS in this firmware.

  17. monusan

    Hi Kamrul,

    thank you for the great tutorial, I have successfully get into ssh, and can go to the usb…
    but when executing the mtd write command it is error with message :

    Could not open mtd device: kernel1.bin
    Can’t open device for writing!

    Could not open mtd device: rootfs0.bin
    Can’t open device for writing!

    Below are the complete capture of my shell :

    [email protected]:/extdisks/sda1# ls -lh
    drwxrwxrwx 1 root root 8.0K May 31 10:56 System Volume Information
    drwxrwxrwx 1 root root 8.0K Apr 16 2016 TDDOWNLOAD
    drwxrwxrwx 1 root root 8.0K Apr 16 2016 ThunderDB
    -rwxrwxrwx 1 root root 1.7M May 28 11:44 x-wrt-8.0-b202005230224-ramips-mt7620-xiaomi_miwifi-r3-squashfs-kernel1.bin
    -rwxrwxrwx 1 root root 10.4M May 28 11:44 x-wrt-8.0-b202005230224-ramips-mt7620-xiaomi_miwifi-r3-squashfs-rootfs0.bin
    drwxrwxrwx 1 root root 8.0K Apr 16 2016 xiaomi_config
    drwxrwxrwx 1 root root 8.0K Apr 16 2016 ??????
    drwxrwxrwx 1 root root 8.0K Apr 16 2016 ??????
    [email protected]:/extdisks/sda1#
    [email protected]:/extdisks/sda1# mtd write x-wrt-8.0-b202005230224-ramips-mt7620-xiaomi_miwifi-r3-squashfs-kernel1.bin kernel1.bin
    Could not open mtd device: kernel1.bin
    Can’t open device for writing!
    [email protected]:/extdisks/sda1#
    [email protected]:/extdisks/sda1# mtd write x-wrt-8.0-b202005230224-ramips-mt7620-xiaomi_miwifi-r3-squashfs-rootfs0.bin rootfs0.bin
    Could not open mtd device: rootfs0.bin
    Can’t open device for writing!
    [email protected]:/extdisks/sda1#

    Kindly advise…

    thank you,
    Regards,
    monusan

  18. Seladir

    Hello!
    I successfully installed X-WRT, but when I mount a USB hard drive and connect to it from PC, the writing speed is really low (~600KB/s) regardless of filesystem. Are there any tweeks / additional steps needed to get more adequate speed?
    Thanks in advance.

    1. Seladir

      Moreover, copying process affects network performance. For example, there is opened infinite ping process of google in the console, and stable 39ms turn into chaotic ~39-400ms during file copying on the mounted hard drive.

  19. Jerem

    Hello,

    I have a Mi 3G router with openWRT on it. But since the 19 update, it have very slow internet connection.

    So i wanted to try X-WRT ( https://downloads.x-wrt.com/rom/ ) .

    How can i switch to X-WRT ?

    If i connect in ssh (in OpenWRT) and do these steps, does it works?

    mtd write x-wrt-8.0-b202006050636-ramips-mt7621-xiaomi_mir3g-squashfs-kernel1.bin kernel1

    mtd write x-wrt-8.0-b202006050636-ramips-mt7621-xiaomi_mir3g-squashfs-rootfs0.bin rootfs0

    nvram set flag_try_sys1_failed=1

    nvram commit

    reboot

    Or do i need to go back to stock firmware?

    Thanks for help

Leave a Reply to Arga Cancel reply

Your email address will not be published. Required fields are marked *