To enable linux SWAP on your Asus RT-AC68U router you need the following:
- Custom firmware with jffs partition enabled (I recommend Asuswrt-Merlin build);
- an USB HDD or USB flash drive to mount on one of your router’s USB ports.
Using a swap file
To enable swapping using a swap file you need to first create the file, prepare it for swapping and then enable the swapping on it. First of, make sure the file system the disk you wish to swap on is properly mounted. If you chose labels for the partitions, use them instead of sda1, sda2, sdb1, etc.
#check how the disk was mounted ls -l /tmp/mnt
For the purposes of this tutorial we will assume the disk is mounted as /tmp/mnt/sda1/ and we want to use the file /tmp/mnt/sda1/myswap.swp for swapping.
#create a 256MB swap file ("count" is in Kilobytes) dd if=/dev/zero of=/tmp/mnt/sda1/myswap.swp bs=1k count=262144 #set up the swap file mkswap /tmp/mnt/sda1/myswap.swp #enable swap swapon /tmp/mnt/sda1/myswap.swp #check if swap is on free
If you reboot your router, the swap will be inactive until you swapon again. To do this automatically you have to create the file /jffs/scripts/post-mount, or edit it if exists and add the line:
#!/bin/sh swapon /tmp/mnt/sda1/myswap.swp
Now every time the router reboots, it will turn on swap.
Using a swap partition
This method is not recommended if using USB storage with multiple partitions.
- Using your computer, create a linux-swap partition on your disk that will be mounted on the router. You can use GParted for linux, MiniTool Partition Wizard Home Edition for Windows or Disk Utility for MacOS;
- Connect the formatted drive to router and in PuTTY terminal use command fdisk -l to see how it was mounted. Let’s asume it is mounted as sda1;
- Again in PuTTY terminal use command swapon /dev/sda1 and then free to see if swap is correctly activated;
- If swap is correctly activated, use the script /jffs/scripts/post-mount with the command swapon /dev/sda1 as mentioned above.
#!/bin/sh swapon /dev/sda1
Warning!
Do not use SWAP (partition or file) on a device which goes to hibernation or does spin-down. You might make the router more unstable than without using SWAP.
Be sure you deactivate spin-down on the device which you want to use for SWAP.

Spin-down settings on ASUS router powered by Asuswrt-Merlin
There are some devices, like the Western Digital USB HDDs WD Elements, My Book or My Passport which have their own power management and will not be affected by the settings on the router and they will spin-down if data is not read or written for some time. I recommend to avoid this kind of devices for SWAP.
Info source:
http://www.dd-wrt.com/wiki/index.php/Linux_SWAP
Pingback: How to install transmission for Optware on Asus RT-AC68U | Software development tutorials
Pingback: How to install Optware on ASUS RT-AC68U | Software development tutorials
This is just what I am looking for. My router is crashing!
I’m glad it helped you!
Good timing – I had looked for this before and couldn’t get it working. This worked first time. The first command line takes time to complete …
I just want to point out that I had to set “Enable JFFS custom scripts and configs” to “Yes” for the post-mount script to run. This option can be found: Administration -> System.
Excelent Guide! Thanks for your help!
Thanks for the guide, I wasn’t able to make my script work on reboot until I made it executable with this command.
chmod a+rx /jffs/scripts/*