cofin Posted November 3, 2012 Share Posted November 3, 2012 Here is a quick and dirty plugin that I wrap to enable/disable the swap file I have on my cache drive. Perhaps some of you guys will find it usually, but most importantly, perhaps we can improve upon it. It's pretty static right now... It creates (if the file doesn't already exists) a 16GB swap file on /mnt/cache, sets permissions, then mounts it. On shutdown, it automatically disables it. Comments and criticisms certainly appreciated. swapfile.plg.zip Quote Link to comment
dcoens Posted November 4, 2012 Share Posted November 4, 2012 This is great! I had posted this link some time ago into a lime-technology forum. http://lime-technology.com/forum/index.php?topic=1595.msg190521#msg190521 How can I incorporate a swap disk (like my swap USB stick) into your plg file? Quote Link to comment
cofin Posted November 4, 2012 Author Share Posted November 4, 2012 If you know what device his the swap partition, you would just swap the commands out to point to the correct device. If you'd like to make it dynamic, you would just grep your device out of the 'cat /proc/partitions' command you listed. You could use something like this in the swap_start piece (note that this hasn't been tested) if [ -d /dev/sdg ]; then # USB Swap drive is ready mkswap -f /dev/sdg swapon /dev/sdg fi in swap_stop, try something like this if [ -d /dev/sdg ]; then # USB drive exists swapoff /dev/sdg fi This assumes that your sdg drive is always that USB stick. It doesn't check to make sure that it is, so it could be dangerous. I am about to go on the road for a few hours, but when i get some back, I'll take a few minutes to see if we can make the script a bit more dynamic. Quote Link to comment
dcoens Posted November 4, 2012 Share Posted November 4, 2012 I made the changes, but without the code: mkswap -f /dev/sdg Note: My USB drive has changed since my last post to /dev/sde. You are right about this command being a dangerous/unforgiving command if you are not correct about the drive, you will have destroyed the drive on witch it is assigned. The swapon and swapoff will just error out if the drive is not swap drive. now the dynamic part: if the script could check for where a swap drive/partition or file is and then assign the swapon/swapoff, that would be great. Quote Link to comment
trurl Posted November 19, 2012 Share Posted November 19, 2012 Here is a quick and dirty plugin that I wrap to enable/disable the swap file I have on my cache drive. Perhaps some of you guys will find it usually, but most importantly, perhaps we can improve upon it. It's pretty static right now... It creates (if the file doesn't already exists) a 16GB swap file on /mnt/cache, sets permissions, then mounts it. On shutdown, it automatically disables it. Comments and criticisms certainly appreciated. Pardon my somewhat linux noobness. If I understand the code correctly swap_stop() removes the swap file /mnt/cache/.swap Since swap_start() creates the swap file only if it doesn't already exist, would it be OK to not remove it and so save the time it takes to create it during boot? Quote Link to comment
trurl Posted November 19, 2012 Share Posted November 19, 2012 Pardon my somewhat linux noobness. If I understand the code correctly swap_stop() removes the swap file /mnt/cache/.swap Since swap_start() creates the swap file only if it doesn't already exist, would it be OK to not remove it and so save the time it takes to create it during boot? Following up my own question with more questions: Does the swap file need to be zero-filled just prior to swapon and so it does need to be recreated during boot? If using a swap partition instead of a file does the OS zero the partition on boot? Am I needlessly trying to save a few seconds here? I seem to remember the swap I used under 4.7 from unMenu as takiing a lot of time to create during boot but maybe not. Quote Link to comment
theone Posted November 22, 2012 Share Posted November 22, 2012 I did some modifications to the original plugin by "cofin" because it didn't work "out of the box". Used Joe L's unmenu swafile plugin as reference - Thank you Joe. Main changes - added: mkswap command chmod command logger commands to log in syslog Note that I changed the size to 2G instead of 16G - that is what I need and don't want to waste time each reboot to create the larger file. I would also like to echo trurl's question: Does the swap file need to be recreated (zeros) each time it is turned on "swapon"? swapfile.zip Quote Link to comment
klunde Posted November 23, 2012 Share Posted November 23, 2012 Please forgive my ignorance, but what is the benefit of this plugin? What is swap file used for? Quote Link to comment
MyKroFt Posted December 2, 2012 Share Posted December 2, 2012 it adds memory to your system thru the use of a temp memory storage file - windows does the same... Myk Quote Link to comment
MyKroFt Posted December 2, 2012 Share Posted December 2, 2012 according to the how-to i just found, they created the file, assign ownership/permissions and then added a line to the fstab file for automount the swap file upon bootup - and this was not creating the file at every bootup I edited the rc.swap to not delete the swap file as is it written, if the swap file exists it will use it, otherwise it will created it and then use it Myk Quote Link to comment
theone Posted December 2, 2012 Share Posted December 2, 2012 according to the how-to i just found, they created the file, assign ownership/permissions and then added a line to the fstab file for automount the swap file upon bootup - and this was not creating the file at every bootup I edited the rc.swap to not delete the swap file as is it written, if the swap file exists it will use it, otherwise it will created it and then use it Myk Can you post this link to the how-to? That is one of the question posted above by trurl and myself... Do we need to recreate the swap file each boot? Quote Link to comment
MyKroFt Posted December 2, 2012 Share Posted December 2, 2012 no you dont, been been playing with this for the last hour and I commented out the rm command on the stop, have been stopping/starting/rebooting and everything is working just fine here is the link I based my reasoning off of and my testing.... http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/ Myk Quote Link to comment
aptalca Posted January 29, 2013 Share Posted January 29, 2013 Hi guys, It's been a couple of months since MyKroFt posted his proposed changes. So what's the verdict? Does it work totally fine for everyone so far? Thanks Quote Link to comment
theone Posted February 8, 2013 Share Posted February 8, 2013 New swap file plugin with WEBUI posted: http://lime-technology.com/forum/index.php?topic=25816.0 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.