Pages

Wednesday, February 19, 2020

Activate SWAP on Asus RT-AC68U router

From: https://mydevtutorials.wordpress.com/2014/01/10/how-to-activate-swap-on-asus-rt-ac68u-router/

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.
1
2
#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.
1
2
3
4
5
6
7
8
9
10
11
#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 (nano works):
1
2
#!/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.
  1. 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;
  2. 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;
  3. Again in PuTTY terminal use command swapon /dev/sda1 and then free to see if swap is correctly activated;
  4. If swap is correctly activated, use the script /jffs/scripts/post-mount with the command swapon /dev/sda1 as mentioned above.
1
2
#!/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
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