What's new

Swap file dedicated drive

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Ragpuss

Regular Contributor
hi all,
Sorry if this has been covered,
I have an RT-AC86U with 2 drives attached, media on the usb3 as sda and swap on usb2 as sdb.
I have created a swapfile on a dedicated drive on the. USB2 port (sdb1)
The relevant line was added to post-mount ( swapon /tmp/mnt/swapfile/myswap.swp )
Do I also need to edit the fstab file to get the swapfile to auto start on boot ?
The swapfiles location is tmp/mnt/swapfile/myswap.swp
Can anyone please let me know if I need to do anything more to get it to start ?
If I run the free command the swapfile shows but its use is 0
Although if I type swapon /tmp/mnt/swapfile/myswap.swp to manually start it then it sais device or resource busy , so does that mean that its running ?
This is the readout on running free :
/tmp/home/root# free
total used free shared buffers cached
Mem: 440436 396848 43588 0 18804 189012
-/+ buffers/cache: 189032 251404
Swap: 1048572 0 1048572

Thank you.
 
Last edited:
That’s normal. Your command to start it is correct. Unless you turn it off, you can’t turn it on again manually. It won’t be used unless it’s needed so the 0 is correct, probably.
 
That’s normal. Your command to start it is correct. Unless you turn it off, you can’t turn it on again manually. It won’t be used unless it’s needed so the 0 is correct, probably.
So will this now swap when needed for the whole device and not just the sdb drive ?
It’s just that I keep reading about people editing the fstab file for auto start of the swapfile across the devices drives.
Thank you.
 
I’m no expert by any stretch, but every tutorial I read over the years (as it pertains to asuswrt at least) never mentions editing fstab
 
The main reason you'd put an entry in fstab for swap is if you have made a swap partition. You have made a swap file so all you need to do is issue the swapon command after the USB device has been mounted (in your post-mount script).

EDIT: Just to add, apparently it is possible to put swap file entries in fstab but this seems like a bad decision when it resides on a USB device. You should already be using the post-mount and unmount scripts so it's better (IMHO) to put swapon and swapoff in those.

EDIT 2: As an experiment I just tried creating an entry in fstab (/jffs/configs/fstab) for my USB swap file and then rebooted my router. Unsurprisingly the swap file was not activated automatically on boot. So I still had to issue a "swapon -a" command after the USB device had mounted. So there really seems no point in going to the trouble of creating an entry in fstab for a swap file.
 
Last edited:
That will be where I’m getting confused, with the swap partition and swapfile, so it looks like I have done it right then :)
Yay I’m learning slowly, lol.
Having the swapfile in the same partition as Entware is ok I assume ? I was going to divide the drive into 2 and have Entware on one then the swapfile on the other, sdb1 and sdb2 , I guess that won’t make any difference ?
I only installed Entware on this device to make the swapfile so I won’t be running anything from Entware.
I also have Entware installed on my main router which I do use for AB-Solution, Pixel’, Skynet, etc’ so I wouldn’t want it to run anything other than the swapfile on my AP, I hope I’m correct in this ?
Thank you for the help :)
 
For the operating system's point of view it doesn't matter where the swap file is, or indeed how many you have. You can even have a mixture of swap files and partitions, they all end up being added to the "pool" of swap.

I don't think there'd be any performance difference between having your swap file on sdb1 vs. sdb2. All the I/O is going to the same USB device that's probably the bottleneck, not the partition layout.
 
That will be where I’m getting confused, with the swap partition and swapfile, so it looks like I have done it right then :)
Yay I’m learning slowly, lol.
Having the swapfile in the same partition as Entware is ok I assume ? I was going to divide the drive into 2 and have Entware on one then the swapfile on the other, sdb1 and sdb2 , I guess that won’t make any difference ?
I only installed Entware on this device to make the swapfile so I won’t be running anything from Entware.
I also have Entware installed on my main router which I do use for AB-Solution, Pixel’, Skynet, etc’ so I wouldn’t want it to run anything other than the swapfile on my AP, I hope I’m correct in this ?
Thank you for the help :)
A few things. 1) Dividing the usb drive among partitions only matters for personal preference or organization. 2) You don’t need entware installed to make a swap file, the system software provides that (at least on the fork). 3) The swap file on your AP if nothing is running on your AP is fine, but probably useless. It would be appropriate on the main router running all those scripts and apps (especially true if you have large amounts of blocking in Skynet as I understand it) - swap on another system wouldn’t help.
 
Keep in mind that a dedicated swap partition on a flash device will burn a hole in the flash - a swap file on a larger partition is a better idea...

32GB thumbdrives or MicroSD cards are cheap these days...
 
A few things. 1) Dividing the usb drive among partitions only matters for personal preference or organization. 2) You don’t need entware installed to make a swap file, the system software provides that (at least on the fork). 3) The swap file on your AP if nothing is running on your AP is fine, but probably useless. It would be appropriate on the main router running all those scripts and apps (especially true if you have large amounts of blocking in Skynet as I understand it) - swap on another system wouldn’t help.
Hi, so how would I create a swapfile without having Entware installed, as I understand it in my very limited knowledge there needs to be directories and files that Entware installs to be able to use a swapfile ?
The AP is running a media server, iTunes server and the samba shares all of which can get quite busy, then of coarse it is doing its normal job as an AP to my main router on a pretty crowded network, so I was hoping that the swapfile would ease the RAM pressure on that, usually running around the 96% even when the media server is on idle ?
Thank you.
EDIT : Solved thank you :)
 
Last edited:
Keep in mind that a dedicated swap partition on a flash device will burn a hole in the flash - a swap file on a larger partition is a better idea...

32GB thumbdrives or MicroSD cards are cheap these days...
I’m running the swapfile on an old but fast usb2 8gb Patriot pen drive, I have only set the swapfile to 1gb so there should be plenty of error space ?
 
The main reason you'd put an entry in fstab for swap is if you have made a swap partition. You have made a swap file so all you need to do is issue the swapon command after the USB device has been mounted (in your post-mount script).

EDIT: Just to add, apparently it is possible to put swap file entries in fstab but this seems like a bad decision when it resides on a USB device. You should already be using the post-mount and unmount scripts so it's better (IMHO) to put swapon and swapoff in those.

EDIT 2: As an experiment I just tried creating an entry in fstab (/jffs/configs/fstab) for my USB swap file and then rebooted my router. Unsurprisingly the swap file was not activated automatically on boot. So I still had to issue a "swapon -a" command after the USB device had mounted. So there really seems no point in going to the trouble of creating an entry in fstab for a swap file.
Hi, should I have the -a extension or any other included in the line in the post-mount for swapon to get my entire device to use it, or is that only needed for a manual start ?
All I have ATM is , “ swapon /tmp/mnt/swapfile/myswap.swp “
 
hi again,
After doing more research and reading all the advice here, I have managed to make a swap partition instead,
I used the whole drive of 8gb formatted as a Linux swap using mini partition in windows.
I then created a file in /jffs/scripts called post-mount added the bash and the line swapon /dev/sdb1
Then made the file executable using chmod +x /jffs/scripts/post-mount and finally changed the permissions to 700 , so they are showing as -rwx———
It all seems to load now on reboot, not using anything yet but I guess when the media server gets loaded it will.
I hope that I have done everything needed, if not then someone please let me know ?
Many thanks for all of the help and input :)
 

Latest threads

Sign Up For SNBForums Daily Digest

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