Tag Archive : openwrt

/ openwrt

FlashSystem supported by OpenWRT

December 9, 2015 | Article | No Comments

Storage system in embedded system is differs with PC or server’s machine. There is no large-capacity storage like hard disk. Storage in embedded system is limited into some MB. Typical embedded system use flash memory rather than magnetic disk. The memory in general can be categorized as two types: NOR flash and NAND flash.

As described, filesystem in embedded system is usually so small in capacity. Therefore, a different approach used to maximize this capacity potential. In this article we will discuss about what filesystem supported by OpenWRT.

Note that, this article won’t discuss the filesystem too much. In future, there might be some link / reference / further reading for each filesystem.

Introduction: NOR vs NAND

Flash memory is an electronic non-volatile computer storage device that can be electrically erased and reprogrammed.

Flash memory technology is developed from EEPROM (Electrically Erasable Programmable Read-Only Memory). There are two types of Flash Memory: NOR flash and NAND flash, which describe the basic logic gates used.

NOR flash

NOR-type flash memory allows a single machine word / byte to be written or read independently.

NAND flash

NAND-type flash may be written and read in blocks (or pages). This operation is similar to disk process. In fact, NAND type is primaly used in main memory (RAM). Other than main memory, it also used to develop memory cards, USB flash drives and Solid State Drives.

mini_fo

The (mini fanout overlay file system) – Redirects modifying operations to a writable location called “storage directory”, and leaving the original data in the “base directory” untouched. When reading, the file system merges the modified and original data so that only the newest versions will appear.

On newer OpenWRT, the filesystem is obsoletes and replaced with overlayfs.

overlayfs

Squashfs

Read only compressed filesystem. The compression is useing LZMA. Data is not aligned, allowing SquashFS to pack the files tighter thus taking up significantly less space than JFFS2. The compression can save up 20-30% compared to JFFS2.

pro

  • Taking as little space as possible
  • Allow the implementation of FailSafe for recovery.

contra

  • Read only, means no way to alteration. If alteration should be done, one should extract the data, make alteration and compress it to new SquashFS filesystem.
  • Waste space, since each time a file contained on it is modified, actually a copy of it is being copied to the second partition (JFFS2).

JFFS2

Writable compressed filesystem with journaling and wear levelling using LZMA compression.

pro

  • writable, has journaling and wear leveling
  • cool

contra

  • compressed, so program (opkg, for example) can’t know in advance how much space a package will occupy.

UBIFS

YAFFS2

ext2

Old filesystem particularly used by Linux.

pro

  • Program can knows how much space is left
  • Popular

contra

  • no journaling
  • no wear leveling
  • no transparent compression

tmpfs

/tmp resides on a tmpfs and /var is a symlink to it. /dev resides on a little tmpfs partition of its own

pro

  • no wear leveling

contra

  • volatile

OpenWRT Boot Process

December 9, 2015 | Article | No Comments

Booting is the primary aspect for utilizing / using a device. Booting is the first process on every machine. The booting process is handled by several application in several layer. Booting will initialize device to work before the device can be operated.

In OpenWRT, when the Machine gets powered, the boot process immediately take place. The machine can be connected over the JTAG Port port and some commands can be issued.

In this article we will discuss about Booting Process on OpenWRT environment.

The Three Stages

The booting process in OpenWRT box is similar to PC’s, especially to Linux and UNIX. It can be divided into three stages or Process Trinity, according to OpenWRT definition.

Bootloader

Boot loader is a special program for booting the device for first time. Mostly, OpenWRT use grub to initialize and parses any options that are presented at the boot menu. After initialization done, it would terminate and give control to kernel.

In OpenWRT, the process happened as following:

  1. The bootloader on the flash gets executed
  2. The bootloader performs the POST, which is a low-level hardware initialization
  3. The bootloader decompresses the Kernel image from it’s (known!) location on the flash storage into main memory (=RAM)
  4. The bootloader executes the Kernel with init=… option

Kernel

When bootloader has done its tasks, the control is passed to kernel. Kernel then do following operations:

  1. the Kernel further bootstraps itself
  2. issues the command/ops-code start_kernel
  3. /etc/preinit does pre-initialization setups (create directories, mount fs, /proc, /sys, … )
  4. the Kernel mounts the rootfs (root file system),
  5. if “INITRAMFS” is not defined, calls /sbin/init (the mother of all processes)
  6. finally some kernel thread becomes the userspace init process

Init

Init is a startup script invoked by kernel to starts some service / system non-related to kernel.

The user space starts when kernel mounts rootfs and the very first program to run is (by default) /sbin/init. The interface between user space application and kernel is clib and the syscalls kernel offers.

Init script is considered as the “Mother of All Processes” since its controls things like starting daemon, changing runlevels, setting up the console/pseudo consoles/tty access daemons, housekeeping chores, etc.

In OpenWRT, following are the processes happen on Init process:

  1. init reads /etc/inittab for the “sysinit” entry (default is “::sysinit:/etc/init.d/rcS S boot”)
  2. init calls /etc/init.d/rcS S boot
  3. rcS executes the symlinks to the actual startup scripts located in /etc/rc.d/S##xxxxxx with option "start":
  4. after rcS finishes, system should be up and running

OpenWRT Time Synchronization

December 9, 2015 | Article | No Comments

OpenWRT router isn’t shipped with hardware clock like PC does. Therefore, the clock is reset each time the WRT is reboot to a hardcoded time setting.

Applying OpenWRT to some time-critical device would result in unexpected result. A valid clock system need to be implemented. As there are no local source could be used as reference, the only option is using external clock as resource. The cheapest afford will be connecting to a NTP (Network Time Protocol) Server and synchronizing the time with it. The synchronization is done automatically every reboot and the time will be periodically synchronized when OpenWRT is running.

To periodically synchronizing the device, make sure cron is running and able to create a scheduled task to perform the time synchronization.

In this article we will discuss about time synchronization between OpenWRT and NTP Server. Here, I assume we have build and NTP server or at least have a NTP to be used as reference.

Preparation

Prior to performing time synchronization, make sure the time zone is set correctly on OpenWRT device. Check the value of /etc/TZ to know it.

Since I’m located in Indonesia (West Indonesia Time / WIT), my timezone would be GMT+7. Therefore I will set my Timezone by:

echo GMT-7 > /etc/TZ

Well, the offset in the TZ valu specifies the time value added to local time to get a UTC value. Therefore, if the local timezone is West of the Prime Meridian, the value is positive and it would be negative if it is East. As a result, TZ Must be set to GMT-7 for a timezone that is GMT+7.

Obtain Materials

To communicate with NTP Server, we need a capable client. The client in this scope is ntpclient which can be installed using opkg.

opkg install ntpclient

Configuration

In addition, this package may also create an init script, /etc/init.d/S55ntpclient, with following content:

#!/bin/sh
/usr/sbin/ntpclient -c 1 -S -h pool.ntp.org &

This will cause ntpclient to attempt a once-off time synchronization to pool.ntp.org at boot time. Additional parameters can also be passed to ntpclient to tell it to periodically perform a time synchronization with a specified host.

Here is the content of /etc/init.d/S55ntpclient I use.

#!/bin/sh

# Kill any existing ntpclient process (they can get stuck if no route to target host)
/usb/bin/killall ntpclient

# do time synchronization
/usr/sbin/ntpclient -l -h 10.10.135.1 -c 1 -s &

Here I have a local NTP Server so I use it. Replace the address to ntp address you want.

A fellow user said that when initial time synchronization fails (ie, no route to the specified time server or similar), ntpclient will hang and will never attempt another synchronization. This can typically occur if the time synchronization is being done over a wireless link or a VPN which may not yet be up then the init script is run.

For periodic time synchronization, we will utilize cron.

Create /etc/crontabs/root with the following content:

# timesync every 15 minutes
*/15 * * * * /etc/init.d/555ntpclient

Restart crond to make change take effect:

killall crond; /etc/init.d/S60cron

At this point, our device should be synchronized for every 15 minutes

OpenWRT Package Manager Tutorial

December 9, 2015 | Article | 1 Comment

In PC’s Linux Distribution, managing package such as installing, updating, and removing package is so easy. Many distribution offers simplified package management using their way such as: apt for debian based, rpm for red-hat based, etc. Although diversity occurs, the purpose is same: managing package / software on Linux.

Being embedded system, OpenWRT offers similar feature. It has its own package manager, named OPKG Package Manager.

In this article we will discuss about opkg, how to use it for our needs.

Overview and History

Opkg is a fork from ipkg package manager. It is lightweight and used to download and install OpenWRT packages form local package repositories or one located in the internet. This function is similar to other package managers. As package manager for small and embedded system, of course Opkg should be as fast as possible.

Opkg attempts to resolve dependencies with packages in the repositories – if this fails, it will report an error, and abort the installation of that package.

Missing dependencies with third-party packages are probably available from the source of the package.
To ignore dependency errors, pass the –force-depends flag.

Syntax

Invoking opkg is simple.

opkg [options...] sub-command [arguments...]

Where options are option for manipulating packages. The manipulation / options available are:

update
Update list of available packages. This operation will download file(s) with list of available packages.
upgrade <pkgs>
Upgrade packages. It can also be used for upgrading group of package:
List of upgradeable packages can be obtained with the opkg list-upgradable.
install <pkgs|FQDN>
Install package(s). Usage sample:
opkg install hiawatha
opkg install http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/hiawatha_7.7-2_ar7ixx.ipk
opkg install /tmp/hiawatha_7.7-2_ar71xx.ipk
configure <pkgs>
Configure packages.
remove <pkgs|regexp>
Removes package(s)

Configuring Repositories

Repository is a server / machine which packages stored. When an OpenWRT device need / want to install a packages, it will retrieves the needed package from repository.

When configuring a packages, make sure the repository used is correct with the target OpenWRT device. What you need to look is the correct architecture (processor and other chips compatibility).

Adjust Repositories

OPKG configuration is stored as /etc/opkg.conf. The content could be like this:

src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages
dest root /
dest ram /tmp
lists_dir ext /var/opkg.lists
option overlay_root /overlay

In above example, we use chip from atheros therefore we install package from atheros ar71xx branches. Root folder is on / and ram is on /tmp. The list or package list is stored as /var/opkg.lists and overlay directory is on /overlay.

For fetching packages locally, adjust to this line:

src/gz local file:////path/to/packagesDirectory

Adjust Architectures

By default opkg only allows packages with the architecture all (= architecture independant) and the architecture of the installed target. In order to source packages from a foreign but compatible target, the list of allowed architectures can be overrided in opkg.conf, something like this:

arch all 100
arch brcm4716 200
arch brcm47xx 300

The architectures are written in specific order. All of the packages architecture defines there has priority and ease opkg for determining which package to prefer in case multiple architectures available.

Proxy Support

If  OpenWRT box is behind proxy, add following to /etc/opkg.conf:

option http_proxy http://proxy.example.org:8080/
option ftp_proxy ftp://proxy.example.org:2121/

Adjust the address and port yourself. If the proxy need authentication, add following:

option proxy_username xxx
option proxy_password xxx

Another way is combining authentication with proxy address, which gives us:

option http_proxy http://username:[email protected]:8080/
option ftp_proxy http://username:[email protected]:2121/

OpenWRT Development with Eclipse

December 9, 2015 | Uncategorized | No Comments

It is interesting deploying a small router using OpenWRT, turn a $20 into a multipurpose box. But, can we extend it’s awesomeness to something more? Yes, we can. We can write and develop an application for running inside of OpenWRT. Creating our own OpenWRT application in fact is not so difficult to do.

OpenWRT utilize machine with different architecture and system compared to our machine. Therefore, we can’t use our gcc on our machine to build an OpenWRT application. To do so, we will build the suitable compilers and other utils. In other words, we will create a cross-toolchain.

In this article, we will discuss about preparing environment for developing OpenWRT’s application. The language used for development is C\C++ and the IDE used will be Eclipse.

For this article I use:

  1. Slackware64 14.0
  2. OpenWRT Buildroot
  3. Eclipse Juno

For simplicity, we will break down the set up into smaller categories.

OpenWRT Buildroot Installation

OpenWRT Buildroot is a set of Makefiles and patches that allows us to easily generate both a cross-compilation toolchain and a root filesystem for embedded systems, especially OpenWRT. The OpenWRT buildroot is a heavy modification of Buildroot. The cross-compilation toolchain uses uClibc, a tiny C standard library.

Prerequisites

  1. 350MB of hard disk space for source files to download.
  2. 3-4GB of available hard disk space for building process (OpenWRT).

Another things to prepared are packages for building the Buildroot. Make sure we have these all:

  1. asciidoc
  2. bash
  3. binutils
  4. bzip2
  5. fastjar
  6. flex
  7. git
  8. g++
  9. gcc
  10. getopt
  11. GNU awk (gawk)
  12. gtk2.0-dev
  13. intltool-update
  14. jikes
  15. libz
  16. make
  17. ncurses
  18. openssl/ssl.h
  19. patch
  20. perl-ExtUtils-MakeMaker
  21. python2.6
  22. rsync
  23. ruby
  24. sdcc
  25. unzip
  26. wget
  27. working sdcc
  28. xgettext
  29. xsltproc
  30. zlib

Assume our build directory will be on ~/openwrt and when it is done, the cross-toolchain will be installed on /opt/OpenWRT.

Installation

Before proceeding, make sure you have svn installed!

First we need to create the working directory ~/openwrt and download the required source code form svn repository. It should be around 14.382 files with overall size of 150MB.

Now, do these commands as non-root user.

mkdir ~/openwrt
cd ~/openwrt
svn co svn://svn.openwrt.org/openwrt/trunk/
cd trunk

Check the missing packages on system used for building OpenWRT on. Use one of the following ommands:

make defconfig
make prereq
make menuconfig

Eclipse

Eclipse will act as our development environment. If you don’t install it yet, you should install it. You can follow this article for Eclipse installation on Linux.

Once Eclipse installed, all we have to do is install additional eclipse packages.

Start eclipse. Now navigate to:

Help -> Install New Software -> Add

enter the following information:

Name: Juno Download

Location: http://download.eclipse.org/releases/juno/

Click on OK. Now expand the Mobile and Device Development  section and check the C/C++ GCC Cross Compiler Support and Remo System Explorer End-User Runtime. Click Next to begin installation. After installation you will be prompted to restart the eclipse, do so.

OpenWRT: Experience the First Login

December 7, 2015 | Article | No Comments

In two previous articles (OpenWRT installation and OpenWRT failsave) so far we have build our box. In this article we will try to experience what we have built 🙂

Login to the box is as simple as another router does. You can do it by telnet, ssh, or even web UI. By default, there is no password for administration user (root) so you must set it later (next article).

In any fresh installed system, it has following defaults:

  1. Internal interface lan and the wireless interface/interfaces wlan0/wlan1 are bridged together to br-lan
  2. wifi is disabled
  3. IP address for internal interface is 192.168.1.1/24
  4. dnsmasq is running; it allocates IP address in the range of 192.168.1.100 to 192.168.1.250 on the internal interface to connected hosts
  5. dropbear does not accept connections
  6. telnet daemon is running on standard port (23)

This default configuration will be kept until we set a password. And also the system will be reset to this state when we use failsafe mode.

In this article we will discuss two way to enter the machine:

  1. Login with Command Line Interface
  2. Login with WebUI

Login with Command Line Interface

Login with telnet is so easy. Just use you CLI or terminal and give following command:

telnet 192.168.1.1

You should be prompted by this screen (or similar to):

BusyBox v1.17.3 (2011-02-22 23:42:42 CET) built-in shell (ash)
Enter 'help' for a list of built-in commands.
  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 ATTITUDE ADJUSTMENT (bleeding edge, r26290) ----------
  * 1/4 oz Vodka      Pour all ingredents into mixing
  * 1/4 oz Gin        tin with ice, strain into glass.
  * 1/4 oz Amaretto
  * 1/4 oz Triple sec
  * 1/4 oz Peach schnapps
  * 1/4 oz Sour mix
  * 1 splash Cranberry juice
 -----------------------------------------------------
[email protected]:~$

Telnet connection is considered unsecure, so we only use telnet connection for this time only.

By default, root account doesn’t have password assigned. Go assign a password for it.

passwd

We will be prompted to set a new password for the user root. Use a secure password for better security. After the password set, telnet daemon will be disabled. Type exit into the prompt. The telnet daemon is disabled but SSH is available automatically. Now use ssh to go back to router.

ssh [email protected]

Login with WebUI

Mostly, WebUI is installed by default. To connect to router using WebUI, we can use any browser and go to 192.168.1.1 (default router address). Login using username root and empty password (if you have not change anything, using telnet).

LuCI

LuCI is one of interface used for WebUI. Login to username root with an empty password. Then click on the left in the top bar on Administration and go to System in the bar underneath. You should see a page asking for new password. Write password you like on that page.

X-Wrt

Another User Interface available. The WebUI will now ask you to set a password. Write your password into the New Password field and again into the Confirm Password field then click set

Gargoyle

Similar to other WebUI method, we should connect to router using web browser. The username is admin OR root and the password is password. You can ssh to the router at the default address (192.168.1.1) the username is root the password is password. Unlike OpenWrt the telnet port is not open.

Login Problem

Can’t login? This might be a problem on firewall settings in Linux or Windows. Please check them or disable them (not recommended).

OpenWRT: Extending the Filesystem

December 3, 2015 | Article | No Comments

For every wireless router, the usable resource such as storage and RAM is very limited. Well, that’s obviously. For instance, take a look to our sample device, TP-Link MR3020. It has following specification:

Processor Atheros [email protected]
RAM 32MiB
Flash Storage 4MiB
Ethernet 10/100 Mbps
USB2 port
micro USB port
Wifi 802.11b/g/n MIMO

See the flash storage? Only 4MiB! Therefore we can’t install many packages here. Well, I have expect this? So we will use a way to extend the storage. This method is called extroot for extending the filesystem so we will have more space to utilized.

Now, what we need?

  1. A linux box. Any linux distribution will do, even windows can.
  2. An OpenWRT-powered wireless router. In this case our beloved TP-Link MR3020.
  3. A USB Flash Disk. I recommend flash disk with storage capacity 1GB or more. This flash disk will be our root filesystem.

Setup the environment

The vital point for our operation is: our box must be able to read and write (at least) recognize our flash disk. To do so we must install following packages:

  1. block-mount
  2. komd-usb-storage
  3. kmod-fs-ext4

To do so, issue this command:

opkg install block-mount kmod-usb-storage kmod-fs-ext4

Disk Partitioning

After the box has been set up, the next stage is to prepare the usb flash disk. In your Linux PC, use tools such as fdisk to partition the flash disk. I won’t cover how to partition it. Please search another source. What partition you need are:

  1. Partition 1 has format Linux Swap. Adjust the size with the RAM.
  2. Partition 2 has format either EXT2, EXT3, EXT4. In this case i choose EXT4.

Edit fstab file

In this stage we make the system recognize our flash disk. Edit /etc/config/fstab file like this:

config global automount
option from_fstab 1
option anon_mount 1

config global autoswap
option from_fstab 1
option anon_swap 0

#config mount
#       option target   /home
#       option device   /dev/sda1
#       option fstype   ext4
#       option options  rw,sync
#       option enabled  0
#       option enabled_fsck 0

config mount
option fstype ext4
option target /mnt/sda2
option device /dev/sda2
option options rw,sync
option enabled 1
option enabled_fsck 1

config swap
option device   /dev/sda1
option enabled  1

Activate fstab

We enable fstab so it would setup the filesystem at reboot. We also activate fstab for current session:

/etc/init.d/fstab enable
/etc/init.d/fstab start

Issu following command to check current filesystem condition:

df -h

You should see your flash disk device denoted by /dev/sda2 is successfully mounted to /mnt/sda2.

Copy the files

Issue these command to copy or mirror the system condition to our flash disk:

tar -C /overlay -cvf - . | tar -C /mnt/sda2 -xf -
mkdir -p /tmp/cproot
mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda2 -xf -
umount /tmp/cproot

Finalizing

Yes, it’s the final stage. After we have done copying, reedit the /etc/config/fstab file and modify so that the file would be like this:

config global automount
option from_fstab 1
option anon_mount 1

config global autoswap
option from_fstab 1
option anon_swap 0

#config mount
#       option target   /home
#       option device   /dev/sda1
#       option fstype   ext4
#       option options  rw,sync
#       option enabled  0
#       option enabled_fsck 0

config mount
option fstype ext4
option target /mnt/sda2
option device /dev/sda2
option options rw,sync
option is_rootfs 1
option enabled 1
option enabled_fsck 1

config swap
option device   /dev/sda1
option enabled  1

Reboot the system and enjoy 🙂

OpenWRT: Set the Environment

December 3, 2015 | Article | No Comments

So we have install and build the box, know some method for resetting, what next?

Be patient, we have to do something before he step to advance session. In this article we will set some environment for the router and give a little configuration for it.

What would we do?

  1. Set up hostname
  2. Set up password
  3. Set IP address

So let’s start

Set Up Hostname

Hostname is a string identify a node in a network. To set a hostname we have to edit file /etc/config/system. Search string and modify it like this:

config system
option hostname 'XGF135-SkyGear'

Replace XGF135-SkyGear with you desired hostname. In my case, my router would be renamed to XGF135-SkyGear.

Set Up Password

An OpenWRT box come with default blank password for root account. This is dangerous for production machine as anyone can login without password. To set up a password, we can use this command:

passwd

Just fill password for root account, twice.

Set IP Address

We can use IP address other than 192.168.1.1. To do so, modify /etc/config/network by using following command:

sed -i -e 's/192.168.1.1/<your IP here>/' /etc/config/network

Again, replace <your IP here> with your desired IP address.

OpenWRT: Install and start the OpenWRT

December 3, 2015 | Article | 2 Comments

This is first point and must see article before we advance to other articles.

Why are we building machine with OpenWRT inside? There are plenty reason, but most of them are:

  1. It’s interesting! As hardware hacker, creating a new machine with all you’ve got will gives you extra excitement.
  2. Cheap! A $20 machine equivalent to $70 machine. Why not?
  3. Small box! Imagine you have small linux box capable for doing (almost) anything

In this article we will discuss about installation of OpenWRT into wireless router. The devices I used for this article (and later if I have not describe it explicitly) would be:

  1. Linux Box. Any linux PC or notebook with Linux installed (although you can do it with Windows box)
  2. 3G Wireless Router – TP-Link MR3020. We will install OpenWRT on this box. I bought this device for Rp 190.000 or about $20.
  3. Optionally you need internet connection for downloading the image.

Before we start, I warn you for last time:

Any change we made to our device would void the warranty. I won’t take any responsibility for any damage you may cause. It’s your own risk!!

I have warn you. So if you still want to follow me, let’s start hacking.

To install an OpenWRT, of course we need image. In general what we want to accomplish is to flash the firmware and replace it with OpenWRT. Before we start, see the table of supported device for your device. Please make sure the device is supported by OpenWRT. You can visit this link (http://wiki.openwrt.org/toh/start)

Read the information and download the correct firmware. In our case we use this image

OpenWRT is a linux-based firmware and the one we download is version 12.09-rc1 which compatible with our device (TP-Link MR3020). Again, search the correct file if you have different device.
Please note: while upgrading / flashing firmware the device must supplied by stable electricity. If in the process the power is out, you may say goodbye to your device.

Then, follow these steps:

  1. Connect the device with laptop. Use ethernet cable and connect one end of cable to device and another one to our laptop. The ethernet cable should be included int the package. If not, any cross cable should be enough.
  2. Open administrator page. For TP-Link MR3020 device, you can point to http://192.168.0.254. It may differ if you have change it before.
  3. Login to admin user. The device will prompt you and ask for username and password. Fill it with username: admin and password: admin. It also may differ if you have changed it before
  4. Locate the upgrade firmware menu. This is platform dependent so it may differ for your device. For TP-Link MR3020 device, go to System Tools -> Firmware.
  5. Choose the image file. In this case we choose our downloaded file.
  6. Upgrade. Choose upgrade or any button with similiar mean.

If you follow those steps above, then you should have OpenWRT router now. The address of the router now would be 192.168.1.1. Now change your IP address to 192.168.1.2 and try to telnet the device. If you success, you might have similar to this.

Cheers! You have installed the OpenWRT. Take look for next article for configuring OpenWRT.

OpenWRT: OpenWRT Failsafe

December 3, 2015 | Article | No Comments

What if you have configure OpenWRT device and turn you device to useless? Or maybe some of configuration make you box inaccessible. But fortunately, OpenWRT has a built in feature for “resetting” your box. It’s called failsafe mode and this feature will attempt to bypass almost all configuration in favor of a few hard coded defaults. The device would boots up in 192.168.1.1/24 with only essential service running. From this state we can telnet and fix certain problems.

But how we can do it? This article will cover the basic.

In this article I will use TP-Link MR3020

Triggering via Hardware Button (Standard method)

  1. Set our IP address to 192.168.1.2 with subnet mask 255.255.255.0
  2. Turn off the device and turn it on again.
  3. Immediately after the device boot, press hardware reset
  4. Try to ping 192.168.1.1 to check whether the device has entered failsafe mode.

Here is a video on to do it (for MR3020 device):

Triggering via Keyboard key Combination

  1. Unplug the router’s power cord.
  2. Connect the router’s WAN port directly to your PC.
  3. Configure your PC with a static IP address between 192.168.1.2 and 192.168.1.254. E. g. 192.168.1.2 (gateway and DNS is not required).
  4. Plugin the power.
  5. Connect via serial
  6. Wait until the following messages is passing: Press the [f] key and hit [enter] to enter failsafe mode
  7. Press “f” and the “enter” key
  8. You should be able to telnet to the router at 192.168.1.1 now (no username and password)

Now we have entered failsafe mode. You will get message similar to this:

Note: the root filesystem in failsafe mode is the only SquashFS partition. The JFFS2 is not present. To mount JFFS2 in read-write mode run this command:

mount_root

Now, suppose you forgot your password you just need to set a new one. A command to do so:

passwd

Another common problem is you forgot router. To get it just give command:

uci get network.lan.ipaddr

When you fill the entire JFFS2 or install too big/ too many packages, you can clean the entire JFFS2 partition by executing one of these command:

firstboot

or

mtd -r erase rootfs_data

or

rm -r /overlay/*

After you have done, you can reboot by using:

reboot -f

That’s all. Happy hacking 🙂

Social media & sharing icons powered by UltimatelySocial