OpenWRT – Rootfs & Swap on USB Storage

Introduction

The chances are that you have a router with a USB port, just like I have my TP-LINK TL-MR3420 router. It is likely that with more intense usage of your router, you will need more disk space. This can be achieved by connecting any USB storage device into the USB port of the router, such as pendrive, external HDD, memory card reader, cell phone, etc.. Unlike a Linux Desktop, OpenWRT is starved of disk space in the extreme. One way to overcome limitations and gain some “Mega” space is to remove installed kernel modules. This may not be at all very convenient, In general, for router with USB port, OpenWRT includes kmod-usb2, a pre-installed  basic module support for USB, which can be expanded to allow for external storage.

Basic Equipment Requirements

– TP-LINK TL-MR3420 Router* with OpenWRT Linux distribution for embedded devices and stable release of  Attitude Adjustment.

– USB Hub* with power supply

– Hard disk drive** with USB connection

* I have a 4-port USB hub  CN-050 v.1.002 from SITECOM with external power supply (cost 16,55€)

** In my case, I have an old 2,5″ 150GB SATA HD (bought long ago, I don´t remember how much probably 75,00€) that I decided to put into an external BlueRay USB box  (cost 13,99€).

Preparing the SATA HDD

Our SATA HDD needs to be partitioned and formatted to be recognised by OpenWRT.

We use MiniTool Partition Wizard Home Edition. Besides being free it is easy to use. Hook up your SATA HDD to your PC.

We partition our SATA HDD as follows:

Partition 1 with 1GB for LinuxSwap and Partition 2 for Ext4 with remainder space of our SATA HDD.

mr3420_1

Setup USB, Swap and ExtRoot

Make sure you have Internet connection. In my case I have my router with static IP address  192.168.1.1 with main gateway pointing to address 192.168.1.254 belonging to my ADSL router THOMSON TG585i V.7, with Internet and custom DNS server pointing to Google´s Open DNS address 8.8.4.4.

STEP 1: Next start LuCI in your favorite browser by pointing the URL to your router´s static IP, in my case 192.168.1.1

Update your router´s packages in System -> Software and click Update listsmr3420_1aActions will be shown of downloading process

mr3420_1b

STEP 2: We next install kmod-ub-storage packages. In Filter field write kmod-usb-storage  and click onto Find package. The result will be shown below as shown.

mr3420_3

Install kmod-usb-storage-extras by clicking onto Install link on the left side of found package. A popup window will ask you to confirm if you want to intall

mr3420_3aClick OK. The results will be shown above as you can see next

mr3420_3b

STEP 3: We will next install filesystem packages. First we find the packages by writing in Filter field kmod-fs

mr3420_4

We will install kmod-fs-ext4 package by clicking Install link on the left of found package.

Again a popup window will ask us if we want to install kmod-fs-ext4 package and we will click OK button. Results of installations of packages will be shown as previously.

STEP 4: We will finally install block packages. First we find the packages by writing in Filter field mount-

mr3420_5

We will install block-mount package by clicking Install link on the left of found package.

Again a popup window will ask us if we want to install block-mount package and we will click OK button. Results of installations of packages will be shown as previously.

mr3420_5a

It is interesting to note that all installations have reduced the available in my case to 38%.

STEP 5: We will plugin the Hub now where we have connected the SATA HDD. The following image shows my setup

mr3420_foto

We next reboot the router in System -> Reboot tab

mr3420_6

STEP 6: After reboot launch PuTTy and perform the shown commands

mr3420_67jpg

STEP 7: After reboot, launch WinSCP (I have vi that is included in OpenWT). Go to ” /etc/config ” folder and locate and edit the file fstab

mr3420_7

Edit fstab as shown below taking note specially that /dev/sda1 is partition 1 (LinuxSwap)  and /dev/sda2 is partition 2 (Ext4 for Data) and do slight modifications as shown below

mr3420_8

Back to LuCI perform reboot again

mr3420_6

After rebooting go to System -> Software tab and Voila!

mr3420_9

A while ago we saw we had 38% of memory now we have 100% and much more memory! Note that there are no package lists. We will do something about this  later.

STEP 8: Let us now check what is going checking mount points in System -> Mount Points tab and in my case at least, swap was not enabled which we will do by ticking Enabled as shown

mr3420_10

We also note that mount point /overlay is correctly mounted in /dev/sda2.

We will now enable fstab to mount the partitions. In LuCI System -> Startup tabmr3420_fstab_enabled

Do next reboot again

mr3420_6

STEP 9: As a final act of confirmation launch PuTTy and perform the commands as shown df -k and next free

mr3420_11

STEP 10: It seems all is fine. Now we will update the package lists like in STEP 1 and do something final about spin of HDD.

Back in LuCI in System -> Software tab perform Actions of searching with keyword luci in Filter field

mr3420_12

And choose to Install luci-app-hd-idle, a utility to spin down the hard drive. A popup window will ask you if you want to install luci-app-hd-idle and you will press OK button and you will see that the package will be installed

mr3420_13

A new tab will be added called Services. Choose Services

mr3420_14

Enable hd-idle as shown and Save & Apply

We have concluded our task of USB, HDD, Rootfs and Swap. By installing hd-idle we have proved that the HDD has substituted the internal limited memory of our router.

Acknowledgements

A special thank you is due to K. L. Seet for excellent tutorial found at that website. Most of this post is based on that tutorial.

About Tayeb

Electronics engineer, part-time webmaster and owner of "Aliatron", a tech-oriented company registered in Portugal and Mozambique. Owner of "EU Halal", a trading and consulting company in Halal & Tayyib, 100% stun-free compliant.
This entry was posted in Electronic Projects, Information Technolody and tagged , , , , , , , , . Bookmark the permalink.

45 Responses to OpenWRT – Rootfs & Swap on USB Storage

  1. رضوان says:

    this best explain master Tayeb, i understand this topic thank you

  2. Thanks for assistance 🙂

  3. Nebojsa says:

    I got error on Step 6,
    when type mount /dev/sda2 /mnt,
    I got error
    mount: mounting /dev/sda2 on /mnt failed: No such file or directory

    • Tayeb says:

      Welcome to my blog.

      You have to mount the partition, are you sure it is sda2? If you have only one partition it will be on sda1.

      On dmesg you should see that the partition is detected and what is its name.

  4. donynam says:

    After completely installed OpenWrt on TP-LINK TL-MR3420 router, then I installed all of the necessary USB storage package to the machine. But I still couldn’t mount any USB storage. Any idea ?

    Senario:

    1) The ‘dmesg’ as below after plugging in the USB storage:

    scsi3 : SCSI emulation for USB Mass Storage devices
    usb-storage: device found at 5
    usb-storage: waiting for device to settle before scanning
    scsi 3:0:0:0: Direct-Access SanDisk Cruzer Mini 0.1 PQ: 0 ANSI: 2
    sd 3:0:0:0: Attached scsi generic sg0 type 0
    sd 3:0:0:0: [sda] 501759 512-byte logical blocks: (256 MB/244 MiB)
    usb-storage: device scan complete
    sd 3:0:0:0: [sda] Write Protect is off
    sd 3:0:0:0: [sda] Mode Sense: 03 00 00 00
    sd 3:0:0:0: [sda] Assuming drive cache: write through
    sd 3:0:0:0: [sda] Assuming drive cache: write through
    sda: sda1
    sd 3:0:0:0: [sda] Assuming drive cache: write through
    sd 3:0:0:0: [sda] Attached SCSI removable disk

    2)both sda and sda1.was found inside /dev

    3)running command
    mount -t ext4 /dev/sda1 /mnt -o rw,sync
    It didn’t trigger any errors or warnings.

    4) /mnt still haven’t mounted.

  5. what speed you reached via wifi, when you copy data from external drive to computer?

    • Tayeb says:

      Welcome to my blog. I did not test. My objectives were to make the system work and have in fact concentrated in other projects and did not come back to this one. If you find out any feedback here will be appreciated.

      • I made it. I used Tp-Link Mr-3420 v2 (faster processor) & 1TB external drive. Copying data via FTP reach 2MB/s. Damn, I was hoping it would be faster.
        The same I had on LevelOne Wap-0008, but maybe Tp-Link will be more stable.

      • Tayeb says:

        Welcome back again Krzysiek. Excellent. Are you going to write an article? If yes, please share the link here.

        Have you investigated the reasons of the data rate you get? There are many constraints I guess: USB data transfer, External drive speed and perhaps even the processor in your modem. You can find the reasons from datasheets.

  6. Mario Samir says:

    sorry i posted in the wrong blog(multiple was open), was reading yours to expand the memory and make openvpn instal…. but if you had advice please don’t hesitate to suggest. thank you

    • Tayeb says:

      Hello Mario. Welcome to my blog. I am getting into VPN but not much yet. I am thinking in VPN mainly due to encrypting and privacy. If I learn something I will share. Also do the same and let us know here.

  7. Hello, is it possible to replace USB storage with NFS drive? I’ve set everything to mount it as /overlay, but I always end up with /tmp/overlay-disabled 😦

  8. kice says:

    there is no such a file “/etc/config/fstab”

  9. hamspiced says:

    Hi,

    Beautiful write up, thankyou for posting this. Im having issues primarily with the TL-MR3040 V2 with the side switches. Finding a stable version of openwrt is difficult, even after going through their forums. as a result i think that is the cause of many of my problems. I am running into issues installing the packages you listed as well as mounting the partitioned drive. i consistantly get this error: *
    satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-usb-core:
    * kernel (= 3.10.28-1-973615e2eb7786ede8048a627eb75438) *

    any insight would be helpful

  10. Peter says:

    Hi there,
    I have done everything, I can mount the NW share, I can log to the NW share, but Im not able to copy large file (even the HDD has about 580GB). Could you please advise?
    BR,
    Peter

  11. sipe says:

    Thank you, I’m using my 16GB USB as network disk on SX763 OpenWrt. Your guide is well written and easy to follow.

    • Tayeb says:

      Welcome to my blog. I hope the tutorial was useful. Do you want to share your project?

      • sipe says:

        Well, I have Siemens SX763 and some nice people from pcekspert.com started thread about OpenWrt. Then I started to play around and I really liked all the features and detailed configurations. Then just like you, I configured one bridge with TG782i which I’m using for VOIP (IMS protocol, can’t get it working on OpenWrt) and for PPPOE Pass-Through. Everything else is going through SX763 and OpenWrt. I set up for start samba inside LAN, SSH from outside and now I’m fooling around a bit 🙂

        Your tutorial is very detailed with pictures and explanations and thank you once more. I shared it on our OpenWrt thread. Keep up the good work! Cheers!

      • Tayeb says:

        Thank you for sharing information and your kind words on my tutorial. All the best for you!

  12. Mike says:

    root@OpenWrt:~# mount /dev/sda2 /mnt
    root@OpenWrt:~3 invalid argument

    Ideas?

  13. Amir Khan says:

    Hi, I following the instruction, but after reboot I don’t see the mount points that you have in the pics that you showed. It looks like my router is reseting everything on startup, i.e. recreating all the links and it is loosing links that we setup. Can you please help ?

    >>>>>=== Following is after reboot
    root@OpenWrt:/etc/init.d# df -h
    Filesystem Size Used Available Use% Mounted on
    rootfs 12.1M 4.3M 7.8M 36% /
    /dev/root 2.3M 2.3M 0 100% /rom
    tmpfs 61.7M 100.0K 61.6M 0% /tmp
    /dev/mtdblock7 12.1M 4.3M 7.8M 36% /overlay
    overlayfs:/overlay 12.1M 4.3M 7.8M 36% /
    tmpfs 512.0K 0 512.0K 0% /dev

    Disk /dev/sda: 1.9 GiB, 2031091712 bytes, 3966976 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x334a3349

    Device Boot Start End Blocks Id System
    /dev/sda1 2048 264191 131072 82 Linux swap / Solaris
    /dev/sda2 264192 3966975 1851392 83 Linux

  14. Fabio Marino says:

    Hello,
    excellent guide! I followed all your instructions (main difference was that I used a 32GB pen drive), but it seems I can’t get swap working at all, no matter what I try. Main partition is Linux ext3, /dev/sda1, correctly mounted; swap is on logical /dev/sda5, but swapon -a ends with: “block: failed to swapon /dev/sda5”. Every single time!
    Do you have any hint?
    Thank you, and keep up the good work! 🙂
    Fabio

  15. jj says:

    Really good article.
    Thanks a lot.

  16. Smax says:

    Work nice on DIR-825
    Thanks you

  17. Ciro says:

    Will this survive a firmware update?

  18. John says:

    Is it possible to use this method for tplink mr3420 v2?

  19. Pingback: OpenWRT extRoot & openVPN | rodez I/0

  20. bahha says:

    Great tutorial ! although I had to make my own firmware preloaded with necessary packages.
    you topic helped because I forgot to power the usb hub externally, thanks a lot 🙂

  21. Hi, I have a question? opkg update & opkg install kmod-rtl8187, is it enough to install alfa driver on the new storage that you made?

  22. do you use ext3 or ext4 for the disk?
    I

Leave a comment