Expanding OpenWRT Storage With an 8GB USB Drive on TP-Link TL-WR902AC: a Step-by-Step Guide

by noobtutes in Teachers > 12

236 Views, 1 Favorites, 0 Comments

Expanding OpenWRT Storage With an 8GB USB Drive on TP-Link TL-WR902AC: a Step-by-Step Guide

Red Bold Modern YouTube Video Thumbnail(1).png

If you've ever tried to install additional software on a router like the TP-Link TL-WR902AC, you’ve probably run into storage issues due to its limited 8MB of internal flash memory. In this blog post, I'll walk you through how I expanded the storage of my TL-WR902AC using an 8GB USB drive and set up an FTP server with anonymous access, all while keeping things simple and efficient.

youtube link:


Why Expand Storage on OpenWRT?

By default, the TL-WR902AC router comes with only 8MB of flash memory, and after installing OpenWRT, you’re left with roughly 2MB of usable space. This makes it impossible to install additional packages like Samba, adblock, or even an FTP server, as the storage fills up too quickly. To solve this, I decided to use an external USB drive to expand the available space and store larger files.

Supplies

s-l1600-removebg-preview(1).png
WhatsApp_Image_2024-09-11_at_21.14.52_556e7cf9-removebg-preview.png

Tp-link Tl-WR902AC

SanDisk USB [compact]

USB [INR]

1. TPlink_tl-wr902ac v4 custom build: https://pastebin.com/rF3MFZqK

2. Expand storage OpenWrt using USB: https://pastebin.com/nFvrrpdS

3. FTP using vsFTPd in OpenWrt: https://pastebin.com/h6vX8pXr

Preparing the USB Drive for Expansion

I started by using an 8GB USB drive. To prepare it:

  1. Plug the USB into your Windows PC, right-click the Windows icon, and open Disk Management.
  2. Find your USB drive, delete all existing partitions, and eject it without creating any new partitions.
  3. Plug the USB drive into the router, and run the following script to partition and format the drive:

opkg update

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


DISK="/dev/sda"
# Create a GPT partition table
parted -s ${DISK} -- mklabel gpt
# Create a 2GB partition for extroot
parted -s ${DISK} -- mkpart primary ext4 1MiB 2050MiB
# Create a 5GB partition for file share
parted -s ${DISK} -- mkpart primary ext4 2050MiB 7500MiB
# Format the first partition as ext4 for extroot
mkfs.ext4 -L extroot ${DISK}1
# Format the second partition as ext4 for FTP storage
mkfs.ext4 -L ftp_share ${DISK}2

This setup allows us to use 2GB for expanded router storage (extroot) and 5GB for an FTP server.

Expanding OpenWRT Storage

Once the drive was partitioned, I moved the root filesystem to the 2GB partition. This provided extra space for installing packages and ensured the system wouldn’t run into storage issues again.

Without this custom setup, any attempt to expand storage or install large packages would fail due to the lack of disk space.

Setting Up an FTP Server

With the extra storage in place, I installed vsftpd, a lightweight FTP server. I configured it for anonymous access so that anyone could upload and download files without the hassle of creating users or setting complex permissions.

However, I had to adjust the folder permissions:

  1. The root FTP directory (ftp_share) is secured with no access for anonymous users.
  2. The storage subdirectory is given full 777 permissions, allowing users to read, write, and execute files within it.

This setup ensures that the root folder remains secure while giving users the freedom to interact with the storage folder as needed.

DONT COPY AND PASTE DIRECTLY!

#edit passwd file
root:x:0:0:root:/root:/bin/ash
daemon:*:1:1:daemon:/var:/bin/false
#By Default as shown below a ftp user is made but has wrong file path "home/ftp" change to your file path.
#For me its /mnt/ftp_share
ftp:*:55:55:ftp:/mnt/ftp_share:/bin/false
network:*:101:101:network:/var:/bin/false
nobody:*:65534:65534:nobody:/var:/bin/false
ntp:x:123:123:ntp:/var/run/ntp:/bin/false
dnsmasq:x:453:453:dnsmasq:/var/run/dnsmasq:/bin/false
logd:x:514:514:logd:/var/run/logd:/bin/false
ubus:x:81:81:ubus:/var/run/ubus:/bin/false
 
opkg update
opkg install vsftpd
 
#Ensure that the ownership of the directories is set correctly.
#Sometimes ownership issues can affect permissions:
mkdir -p /mnt/ftp_share
mount /dev/sda2 /mnt/ftp_share
df -h
#You should see /dev/sda2 mounted on /mnt/ftp_share
 
#make a folder with full permissions!
mkdir -p /mnt/ftp_share/storage
 
vi /etc/vsftpd.conf
# Default Options
background=YES
listen=YES
write_enable=YES
local_umask=000
check_shell=NO
session_support=NO
 
# Anonymous FTP server specific settings
anonymous_enable=YES
no_anon_password=YES
anon_root=/mnt/ftp_share
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_umask=000
 
#extra timeout settings
idle_session_timeout=600
data_connection_timeout=120
accept_timeout=60
connect_timeout=60
 
#Root directory should not be writable
chmod 755 /mnt/ftp_share
 
#Writable subdirectory should be set to allow uploads
chmod -R 777 /mnt/ftp_share/storage
 
# see owners, groups and file permissions d -directory r -read w -write x -execute
ls -l /mnt/ftp_share
ls -l /mnt/ftp_share/storage
 
#restart service
/etc/init.d/vsftpd start
/etc/init.d/vsftpd reload
/etc/init.d/vsftpd restart
#Or
service vsftpd reload
service vsftpd restart
 
#Enable vsftpd to Start on Boot
/etc/init.d/vsftpd enable
 
#some useful commands
 
#force delete even if there are files inside
rm -rf /mnt/ftp_share/storage/*
#normal deletion of files
rm <filename.extension>

Resolving FTP Server Partition Auto-Mount Issues

Screenshot 2024-09-12 123738.png

Initially, after rebooting the router, the 5GB FTP partition wasn't auto-mounting. To fix this, I went into Mount Points in the LuCI web interface and enabled auto-mount for the ftp_share partition. After another reboot, everything mounted correctly, and the FTP server functioned as expected.

Final Thoughts

With this setup, I’ve transformed my TP-Link TL-WR902AC from a basic router with limited storage into a robust device with 2GB of usable space for packages and a 5GB FTP server. While this method works well, keep in mind that the TL-WR902AC is a low-powered device with a single-core CPU. Pushing it too hard may affect performance or even cause issues, so always keep your setup lightweight.

Future Plans

In future videos, I’ll dive into more advanced FTP server setups, such as user authentication and firewall configurations that restrict access to specific devices. But for now, this simple, anonymous FTP setup works perfectly!

Additional Resources

Screenshot 2024-09-12 130826.png

Check out my other videos for tutorials on setting up ad blockers, 5GHz Wi-Fi, and more on OpenWRT. All the links, commands, and resources mentioned in this post are available in the video description!

youtube links:

TP-Link TL-WR902AC v4 Usb tethering OpenWrt: A friendly guide.

https://www.youtube.com/watch?v=oitYRDxWo5A

OpenWrt adblocking in router Tp-Link TLWR902AC: A friendly guide.

https://www.youtube.com/watch?v=hDm8THMLGYA




Thanks for reading, and until next time!