5,598,171 Members 44,130 Now Online
XDA Developers Android and Mobile Development Forum

[Script] swapconf - swap config

Tip us?
 
mrvek
Old
(Last edited by mrvek; 29th October 2012 at 01:17 AM.)
#1  
mrvek's Avatar
Senior Member - OP
Thanks Meter 367
Posts: 508
Join Date: Feb 2011
Location: /home
Default [Script] swapconf - swap config

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:	2268
Size:	33.8 KB
ID:	1438263   Click image for larger version

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

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

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

Name:	5.jpg
Views:	821
Size:	15.3 KB
ID:	1438268  

Click image for larger version

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

Name:	7.jpg
Views:	740
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, 2409 views)
The Following 24 Users Say Thank You to mrvek For This Useful Post: [ Click to Expand ]
 
Erovia
Old
#2  
Erovia's Avatar
Senior Member
Thanks Meter 213
Posts: 709
Join Date: Sep 2012
Thanks a lot for the info.
Phone: Nexus 4
ROM: ParanoidAndroid 4+
Kernel: hells-Core
Recovery: MultiROM
--------------------------------------------------------------------------------------------------------------------------
Tablet: Nexus 7
ROM: SlimKat 4+
Kernel: LeanKernel
Recovery: MultiROM
--------------------------------------------------------------------------------------------------------------------------
Phone: Motorola Milestone A853 ROM: CyanogenMod 9.1.0d Recovery: Open Recovery MiniMod by -FuFu-
The Following User Says Thank You to Erovia For This Useful Post: [ Click to Expand ]
 
walker666
Old
#3  
walker666's Avatar
Member
Thanks Meter 6
Posts: 42
Join Date: Oct 2009
Location: Zagreb
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: [ Click to Expand ]
 
arttree
Old
#4  
Member
Thanks Meter 7
Posts: 64
Join Date: 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: [ Click to Expand ]
 
mrvek
Old
#5  
mrvek's Avatar
Senior Member - OP
Thanks Meter 367
Posts: 508
Join Date: Feb 2011
Location: /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.
The Following User Says Thank You to mrvek For This Useful Post: [ Click to Expand ]
 
arttree
Old
#6  
Member
Thanks Meter 7
Posts: 64
Join Date: 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: [ Click to Expand ]
 
walker666
Old
#7  
walker666's Avatar
Member
Thanks Meter 6
Posts: 42
Join Date: Oct 2009
Location: 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
The Following 2 Users Say Thank You to walker666 For This Useful Post: [ Click to Expand ]
 
arttree
Old
#8  
Member
Thanks Meter 7
Posts: 64
Join Date: Jul 2010
great tips! It work! Thanks.
 
Eiertschik
Old
(Last edited by Eiertschik; 25th October 2012 at 02:13 PM.)
#9  
Eiertschik's Avatar
Senior Member
Thanks Meter 67
Posts: 389
Join Date: Mar 2011
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
The Following User Says Thank You to Eiertschik For This Useful Post: [ Click to Expand ]
 
mrvek
Old
#10  
mrvek's Avatar
Senior Member - OP
Thanks Meter 367
Posts: 508
Join Date: Feb 2011
Location: /home
Quote:
Originally Posted by Eiertschik View Post
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.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes