[Script] swapconf - swap config

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
Description:
A small command line tool to create, delete, enable or disable swap file on sdcard and autostart swap file or partition on boot (zRam (compcache) is configured through system Settings))


Features:
- Automatic detection of partitions and files: if you do not have a dedicated swap partition, script uses swapping to file - first on sd-ext and if that one does not exist then it swaps to sdcard. Swap partition takes precedence over files. This should work no matter if you have or do not have ext partition (for app2ext) on sd card.

- create and delete swap file - you can test different sizes without rebooting

- ability to start and stop swapping where ever it may be configured: biggest advantage of this is that you can stop swap if you have it on your /sdcard so you can use mass storage mode. Also, you can test various sizes for swap files or how your system works when swap is disabled, without need for a reboot

- misc. activities: view status of swap partition/files and status of memory

Usage:
Code:
Disable startup:    swapconf 0 -> disables startup script
Enable startup:     swapconf 1 -> enables startup script
Create swap file:   swapconf mkf size_in_MB -> creates swap file of specified size (e.g. swapconf mkf 30  for 30MB swap file)
Remove swap file:   swapconf rmf -> removes previously created swap file
Start swap:         swapconf start p|f -> starts swapping to partition (p) or file (f)
Stop swap:          swapconf stop -> stops swapping whereever it may be started
View swap status:   swapconf status -> view status of swaps and memory
		
NOTE: Enabling both swapping to partition and to file is not supported.
If you have a dedicated swap partition on sdcard it will be used if enabled. Otherwise you need to configure swap file.
The attachment is OpenRecovery flashable update zip. Simply apply update.
Startup script should persist across new ROM updates until you do a factory reset (wipe data)

Feedback is welcome ;)

Changes for version 0.2:
- relocated script from /data/local/bin to /system/bin: if your terminal app does not export /data/local/bin to PATH that should not be an issue anymore. Script should still persist across ROM updates [thanks to kabaldan for the tips :)], startup script should persist until you do a factory reset (or you delete/disable it ;)).
- reworked script commands: previously you were not able to create swap file without enabling startup script
- improved partitions detection
- fixed a bug where you could not stop swapping to file if zRam was active
- mics. fixes and cleanups

Changes for version 0.2b:
- fixed backup of swapconf script during ROM upgrade on CM10

Notes:
- script will not persist when changing different ROM versions, e.g. from CM7 to CM10
- kabaldan and Skrilax_CZ have informed me that it is a bad idea to have active swap on sdcard's FAT32 partition unless there is an app that will disable swapping when the sd card is going to be mounted to PC. So far, the only issue I have noticed is that you can not mount USB mass storage mode until you turn off swap so I left that possibility enabled. The choice is yours (btw., it uses fat32 partition only if you have no dedicated swap partition or ext partition).
 

Attachments

Last edited:

arttree

Senior Member
Jul 22, 2010
65
7
0
Great piece of swap tool! Great jobs mrVek!

in my case i can't directly cmd 'swapconf status' as shown in your screenshot, but have to cmd 'sh swapconf status' than the script run...

Thank you anyway, save me lots of time.
 
  • Like
Reactions: mrvek

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
@arttree: that's odd. I haven't had such issues. Do other commands have the same issue? What rom are you using?
That seems like a permissions problem, execute perm. maybe missing. I'll look into it. You can try to chmod 755 /data/local/bin/swapconf to see if it'll help.
 
  • Like
Reactions: arttree

arttree

Senior Member
Jul 22, 2010
65
7
0
/data/local/bin/swapconf permision is 755. i installed/flashed it using update-OR-swapconf.zip you posted in 1st post.

anyway other than execute using "sh", everything work fine, even after reboot my MS, swap partition detected automatically.
 
  • Like
Reactions: mrvek

walker666

Member
Oct 20, 2009
43
6
0
Zagreb
Do you have /data/local/bin in your PATH? Or you always navigate to /data/local/bin?

Try this:
echo $PATH

To see if /data/local/bin exists in your path, if not then:

export PATH= $PATH:/data/local/bin

after that you wont need "sh" or "./" before swapconf (and you will be able to execute swapconf cmd from everywhere)...

Remember that this is not permanent PATH export, you need to do that everytime, as mrvek guided me, in terminal's settings there is an option to execute some commands on console startup (similar to .bash_profile) and you should put there "export PATH= $PATH:/data/local/bin" so you don't have to do that every time on console startup.

Sent from my Milestone using xda app-developers app
 
  • Like
Reactions: mrvek and arttree

Eiertschik

Senior Member
Mar 28, 2011
399
67
0
Little problem:

$ su
# swapconf 1
[[: /dev/block/mmcblk0p1: unknown operand
Created configuration.
Enabled startup script.
#


Seems like the script thinks that mmcblk0p1 is swap - but that's my ext-partition...
My swap is mmcblk0p2 :(

But it seems like I'm misinterpreting this error, am I not?

Sent from my Milestone using xda app-developers app
 
Last edited:
  • Like
Reactions: mrvek

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
Little problem:

$ su
# swapconf 1
[[: /dev/block/mmcblk0p1: unknown operand
Created configuration.
Enabled startup script.
#


Seems like the script thinks that mmcblk0p1 is swap - but that's my ext-partition...
My swap is mmcblk0p2 :(

But it seems like I'm misinterpreting this error, am I not?

Sent from my Milestone using xda app-developers app

mmcblk0 is sd card, if present. mmcblk0p1 is first partition and should be FAT32, mmcblk0p2 is second partition (ext, and it must be p2 because some things in system assume that ext is 2nd partition if it exists, otherwise it won't mount it) and mmcblk0p3 is 3rd (usualy swap).
Neverthelss, these are issues, especially on CM7, with the script that need to be fixed asap.
 

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
Updated OP with new version (0.2).
I have tested it with different configurations and it seems to be working. Let me know if I missed anything.

Thank you all for your feedback.
 
  • Like
Reactions: walker666

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
bug fix

Updated OP (again).
Only change was a fix for CM10 so it should persist between rom upgrades (ie., swapconf script is properly backed up during CM10 install).
I'm sorry for the trouble, haven't noticed it before.
 

arttree

Senior Member
Jul 22, 2010
65
7
0
thank you for improving your scripts. Great piece of script that our life a lots lots easier.

btw, if i used swap file option, do i need to manually stop it before i enable the mass storage(connect to PC)?
 

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
thank you for improving your scripts. Great piece of script that our life a lots lots easier.

btw, if i used swap file option, do i need to manually stop it before i enable the mass storage(connect to PC)?
Yes but only if swap file is on sd card fat32 partition. If you do not have an ext partition then it was created in sdcard's fat32 (/sdcard/.swapfile)
If it is on your fat32 partition and is active you need to stop it before connecting to mass storage mode.

Please note that intended purpose of startup script is to enable swap on boot. To do that it uses certain priority - first it tries swap partition, if that did not exist then it tries ext partition (if you created file) and the last resort is sd card fat partition (also needs pre-created file). The same applies to manual creation of file - ext has precedence over fat32.
I guess that is not a design flaw.
 

mrvek

Senior Member
Feb 10, 2011
579
460
93
/home
is it fullly compatible with Compcache of zRam?
Hm... not sure if I understand.
zRam/compcache is controlled in ROMs settings.
On the other hand you can have zram enabled and still use this scrip to configure swap to partition or file but you can't manipulate zram with this script.