Add swap to USB drive on Asus Router


Part of the Furniture
I feel that Asus routers are great and the firmware keeps getting better! Yes, there are some teething problems with Aimesh and it would be great to have SMB2 capability in the “Official” release. Merlin’s firmware for Asus has many good features, but lacks Aimesh.

One feature I’ve wanted on the official Asus is the ability to add a swap file to a USB drive. Sometimes Samba writes run teh RAM usage up. Impossible, can’t be done, no way to mount the swap file after router reboot…. Well, there is a way…

An undocumented feature I’ve discovered is the ability to specify a custom script when a USB drive is inserted. This also works when the router is started or rebooted.

I’ve tested this on a RT-N66R and a RT-AC66U_B1. For my test I used a 1 GIG USB with FAT and a 32 GIG with EXT2. I recommend you have a volume label on the drive.

On your router enable Telnet or SSH and connect to the router with a terminal or Putty.

Note: for Windows users WinSCP can be used to connect to the router with SCP, create and edit files in the /jffs directory and set permissions.

Run the command df to see where your USB drive is mounted. Should be something like /tmp/mnt/volume-label Of course use your volume label in the following commands.

Create a swap file

dd if=/dev/zero of=/tmp/mnt/ volume-label /myswap.swp bs=1k count=262144

mkswap /tmp/mnt/ volume-label /myswap.swp

Start the swap

swapon /tmp/mnt/ volume-label /myswap.swp

Run the free command to see the swap is started.

Create the script file in /jffs (The following is using telnet. There are other ways to create the file, WinSCP is recommended.)

cat > /jffs/post-mount (press Enter)


swapon /tmp/mnt/ volume-label /myswap.swp (press Enter)

Press Ctrl + Enter keys

chmod 755 /jffs/post-mount

The contents of the script should look like this:
swapon /tmp/mnt/ volume-label /myswap.swp

Modify nvram

nvram set script_usbmount="/jffs/post-mount"

nvram commit

Reboot the router, log in with telnet or SSH and run the free command. You should see the swap size of 256 MB.

One other thing… One wonders what else you can get to run from a USB drive with this?

Edited 07JAN21
Last edited:


Part of the Furniture
Thanks for the info @bbunge (although "Ctrl + Enter keys" don't do anything in my terminal).

But I was wondering what use swap would be in stock firmware given that you can't run lots of additional software like in Merlin? You mention Samba but swap is of no use there. Samba just uses unused RAM to buffer disk I/O releasing it when another process needs it. The media server perhaps?
Last edited:


Part of the Furniture
Writes and reads to a USB drive run up RAM use. Especially with NTSF format drives. I have had the router crash because of this. Adding a swap sure helps from my experiences with Merlin firmware. As for running other software like Addblock or Freshjr QOS add on, if you can get a script to run at start up, why not start the swap and something else?

Sent from my P01M using Tapatalk

Nathan Groves

Occasional Visitor
This is amazing and something that I've actually started a thread about .

A couple of hopefully simple questions....

Can this be done safely with download master running on the second usb port? RT ac86u

Is it worth having a bigger swap and if so, how?

Does this automatically start the swap when the router reboots?

Amazing and thanks all .


Last edited:

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!