OpenWRT: Extending the Filesystem

Home / OpenWRT: Extending the Filesystem

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 🙂

,

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

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

Social media & sharing icons powered by UltimatelySocial