Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Script] swapconf - swap config

OP mrvek

23rd October 2012, 09:43 PM   |  #1  
mrvek's Avatar
OP Senior Member
/home
Thanks Meter: 382
 
538 posts
Join Date:Joined: Feb 2011
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).
Attached Thumbnails
Click image for larger version

Name:	1.jpg
Views:	2662
Size:	33.8 KB
ID:	1438263   Click image for larger version

Name:	2.jpg
Views:	1725
Size:	26.2 KB
ID:	1438264   Click image for larger version

Name:	3.jpg
Views:	1384
Size:	26.2 KB
ID:	1438265   Click image for larger version

Name:	4.jpg
Views:	1091
Size:	25.3 KB
ID:	1438266   Click image for larger version

Name:	5.jpg
Views:	937
Size:	15.3 KB
ID:	1438268   Click image for larger version

Name:	6.jpg
Views:	860
Size:	20.0 KB
ID:	1438269   Click image for larger version

Name:	7.jpg
Views:	833
Size:	17.6 KB
ID:	1438270  
Attached Files
File Type: zip update-OR-swapconf-v.0.2b.zip - [Click for QR Code] (127.8 KB, 2867 views)
Last edited by mrvek; 29th October 2012 at 02:17 AM.
The Following 26 Users Say Thank You to mrvek For This Useful Post: [ View ]
23rd October 2012, 09:45 PM   |  #2  
Erovia's Avatar
Senior Member
Thanks Meter: 257
 
805 posts
Join Date:Joined: Sep 2012
More
Thanks a lot for the info.
The Following User Says Thank You to Erovia For This Useful Post: [ View ]
23rd October 2012, 09:56 PM   |  #3  
walker666's Avatar
Member
Flag Zagreb
Thanks Meter: 6
 
42 posts
Join Date:Joined: Oct 2009
More
Bravo mrvek!
"Svaka cast!"



Sent from my Milestone using xda app-developers app
The Following User Says Thank You to walker666 For This Useful Post: [ View ]
25th October 2012, 03:14 AM   |  #4  
Member
Thanks Meter: 7
 
64 posts
Join Date:Joined: Jul 2010
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.
The Following User Says Thank You to arttree For This Useful Post: [ View ]
25th October 2012, 05:36 AM   |  #5  
mrvek's Avatar
OP Senior Member
/home
Thanks Meter: 382
 
538 posts
Join Date:Joined: Feb 2011
@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.
The Following User Says Thank You to mrvek For This Useful Post: [ View ]
25th October 2012, 07:25 AM   |  #6  
Member
Thanks Meter: 7
 
64 posts
Join Date:Joined: Jul 2010
/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.
The Following User Says Thank You to arttree For This Useful Post: [ View ]
25th October 2012, 07:38 AM   |  #7  
walker666's Avatar
Member
Flag Zagreb
Thanks Meter: 6
 
42 posts
Join Date:Joined: Oct 2009
More
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
The Following 2 Users Say Thank You to walker666 For This Useful Post: [ View ]
25th October 2012, 07:51 AM   |  #8  
Member
Thanks Meter: 7
 
64 posts
Join Date:Joined: Jul 2010
great tips! It work! Thanks.
25th October 2012, 02:43 PM   |  #9  
Eiertschik's Avatar
Senior Member
Thanks Meter: 67
 
394 posts
Join Date:Joined: Mar 2011
More
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 by Eiertschik; 25th October 2012 at 03:13 PM.
The Following User Says Thank You to Eiertschik For This Useful Post: [ View ]
25th October 2012, 03:39 PM   |  #10  
mrvek's Avatar
OP Senior Member
/home
Thanks Meter: 382
 
538 posts
Join Date:Joined: Feb 2011
Quote:
Originally Posted by Eiertschik

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.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes