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
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.
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.