FORUMS
Remove All Ads from XDA

[GUIDE] How to create a swap partition at my way (the easiest)

1,028 posts
Thanks Meter: 216
 
By Segnale007, Senior Member on 21st January 2012, 09:07 PM
Post Reply Email Thread
I know this topic has been covered many times already, but since I couldn't find a easy and straight forward how-to to create a swap partition on my X8, I am going to walk you through few easy steps that will let you create a swap partition in 5 mins or so.

First things first I assume you have already the latest version of miniCM7 and nAa kernel, although this mini howto should apply for any phone and any rom out there, as long as the kernel supports swap partition.

First thing you want to partition your SD card in order to create our swap partition, I recommend you to follow this accurately.

Now that we have successfully created our swap partition, we want to boot up the phone and enable our swap partition in order to be accessible to the kernel.

To detect the swap partition that we have just created open up a ADB terminal and type

Code:
fdisk -l dev/block/mmcblk0
it will look something like this

Code:
/dev/block/mmcblk0p3             862         966      843412+ 82 Linux swap
write down the exact number of the swap partition and let's activate it by typing

Code:
swapon /dev/block/mmcblk0pX
** where X is the number of the swap partition **

We can now check if our swap partition has been activated by executing the command free

Now we want to make our swap partition to be activated at boot time, without having to activate it manually everytime we reboot the phone.

Assuming you know how to at least write and save a text file in VI, let's go back to our fido ADB shell and type

Code:
vi /data/local/userinit.sh
now lets drop few lines in

Code:
#!/system/bin/sh

#Swap
swapon /dev/block/mmcblk0pX
** where X is the number of the swap partition **

If you are not really comfortable with VI you can also use Nano or even RootExploer or any other root file manager if you are more comfortable with UI.

save it and once again in ADB shell lets make it executable

Code:
chmod a+x /data/local/userinit.sh
As last step you may want to change the swappiness value, note that most of the roms have it set to 60 by default, which is good enough in my opinion, although setting it to higher (max is 100) may help to improve overall performance, while setting it to lower may increase interactivity and overall stability.

Temporary change (until next reboot)

Code:
echo 60 > /proc/sys/vm/swappiness
Permanent change

Code:
echo vm.swappiness=60 >> /system/etc/sysctl.conf
As result

Code:
~ # free
             total         used         free       shared      buffers
Mem:        186704       177248         9456            0          116
-/+ buffers:             177132         9572
Swap:       843404        53760       789644

** few notes **

I don't intend to take credit for this how-to as it takes few pieces of commands and hints from any guides out there which covers this topic, and anyways its basic linux knowledge really..

So cheers you all and enjoy
The Following 16 Users Say Thank You to Segnale007 For This Useful Post: [ View ] Gift Segnale007 Ad-Free
 
 
22nd January 2012, 01:10 AM |#2  
Senior Member
Flag Wojcieszyce
Thanks Meter: 119
 
Donate to Me
More
mmcblk0p3 is used when we have 3 partitions on SD and last one is swap.
If we have only 2 (fat+swap like me) it need to be mmcblk0p2

Also mkswap /dev/block/mmcblk0pX need to be done b4 you call swapon.
The Following 3 Users Say Thank You to rav3n_pl For This Useful Post: [ View ] Gift rav3n_pl Ad-Free
22nd January 2012, 01:58 AM |#3  
Segnale007's Avatar
OP Senior Member
Flag Mexico City
Thanks Meter: 216
 
More
Quote:
Originally Posted by rav3n_pl

mmcblk0p3 is used when we have 3 partitions on SD and last one is swap.
If we have only 2 (fat+swap like me) it need to be mmcblk0p2

Also mkswap /dev/block/mmcblk0pX need to be done b4 you call swapon.

Yea I forgot to mention that mmcblk0p3 is in my case the swap partition and the number vary depends on how many partitions you have on your SD card.

Btw mkswap isn't needed if you follow my how-to, because Linux Swap file system is already selected when partitioning the SD card, you don't really need to format the swap partition again by using mkswap .
22nd January 2012, 10:40 PM |#4  
Sir_gpm's Avatar
Senior Member
Flag Managua
Thanks Meter: 244
 
More
I tought that a partition is need it, to run the swap file, but now I am running it in my sd card without partition it. Is any difference, between partition my sd?
23rd January 2012, 01:19 AM |#5  
Senior Member
Flag Wojcieszyce
Thanks Meter: 119
 
Donate to Me
More
You are using swap file, it can be created by swapper. Swap partition is easier - it will persist when you connect to pc.
The Following User Says Thank You to rav3n_pl For This Useful Post: [ View ] Gift rav3n_pl Ad-Free
23rd January 2012, 01:22 AM |#6  
Segnale007's Avatar
OP Senior Member
Flag Mexico City
Thanks Meter: 216
 
More
Quote:
Originally Posted by Sir_gpm

I tought that a partition is need it, to run the swap file, but now I am running it in my sd card without partition it. Is any difference, between partition my sd?

If you meant what's the difference between using swapper2 and partitioning the SD card is that basically you can assign as much space as you want to your swap partition, while with swapper2 you can't really have more than 250mb of swap.

Also like @rav3n_pl said, when you mount the sdcard on your computer the swap will stay available since it uses its own partition.

Personally I found 250mb of swap too little, my suggestion is to give at least 600mb to the swap partition.

My setup is 800mb of swap and swappiness value set to 70.
The Following 2 Users Say Thank You to Segnale007 For This Useful Post: [ View ] Gift Segnale007 Ad-Free
23rd January 2012, 02:12 AM |#7  
Senior Member
Thanks Meter: 531
 
Donate to Me
More
I would like to ask you why & in what situation was 256mb swap insufficient?
Did you actually run 'free' in terminal to see how much swap was being used?

I just can't imagine anything running on our phone that will actually use up the whole 256mb swap, unless you are running a linux distro over the top...(less than 1% of users & those users know what they are doing)...the only thing a greater than 256mb swap space partition is doing is decreasing your over-all sd-card capacity for music/files/apps2sd/whatever2sd...

Swap doesn't 'add' ram. We don't magically have 1gb of ram with 800mb swap...
I'm not bashing, I just think new users could easily take this idea the wrong way.
Same as other people advising newer users to set up 1gig+ of swap...it is just unused space on your sd-card.

The best thing about setting up a partition and not using swapper2 is you don't have an app on your phone that is notorious for auto-running, has root access, as well as internet permission. Root access means they can send any info about your phone straight through. Even with Droidwall+similar apps, they don't mean anything to root.
The Following 2 Users Say Thank You to lrakkarl For This Useful Post: [ View ] Gift lrakkarl Ad-Free
23rd January 2012, 07:10 AM |#8  
Senior Member
Flag Ostrava
Thanks Meter: 8
 
Donate to Me
More
i have fat32 ext3 and swap,ext3 and swap works,but i cant use storage(fat32) phone say its wrong sd card..but in another rom with same kernel works..
23rd January 2012, 08:34 AM |#9  
TimeWasterNL's Avatar
Senior Member
Flag Zwolle
Thanks Meter: 111
 
Donate to Me
More
Quote:
Originally Posted by hajiborojobo

i have fat32 ext3 and swap,ext3 and swap works,but i cant use storage(fat32) phone say its wrong sd card..but in another rom with same kernel works..

In the linked article is adviced to put a SD card of 2GB or smaller on FAT, maybe that's your solution?
23rd January 2012, 10:53 AM |#10  
Segnale007's Avatar
OP Senior Member
Flag Mexico City
Thanks Meter: 216
 
More
Quote:
Originally Posted by lrakkarl

I would like to ask you why & in what situation was 256mb swap insufficient?
Did you actually run 'free' in terminal to see how much swap was being used?

I just can't imagine anything running on our phone that will actually use up the whole 256mb swap, unless you are running a linux distro over the top...(less than 1% of users & those users know what they are doing)...the only thing a greater than 256mb swap space partition is doing is decreasing your over-all sd-card capacity for music/files/apps2sd/whatever2sd...

Swap doesn't 'add' ram. We don't magically have 1gb of ram with 800mb swap...
I'm not bashing, I just think new users could easily take this idea the wrong way.
Same as other people advising newer users to set up 1gig+ of swap...it is just unused space on your sd-card.

The best thing about setting up a partition and not using swapper2 is you don't have an app on your phone that is notorious for auto-running, has root access, as well as internet permission. Root access means they can send any info about your phone straight through. Even with Droidwall+similar apps, they don't mean anything to root.

I have never said that swap adds ram, not that I want new users to believe that, but in my case 256mb of swap was way too little, especially when it comes to play games and at the same times running apps in background while the phone still remains snappy. Maybe 800mb of swap is a little bit exaggerated, but in my opinion 500mb of swap is a must to have..
The Following User Says Thank You to Segnale007 For This Useful Post: [ View ] Gift Segnale007 Ad-Free
26th May 2012, 11:55 AM |#11  
revan17's Avatar
Senior Member
Flag Zagreb
Thanks Meter: 273
 
More
Quote:
Originally Posted by rav3n_pl

mmcblk0p3 is used when we have 3 partitions on SD and last one is swap.
If we have only 2 (fat+swap like me) it need to be mmcblk0p2

Also mkswap /dev/block/mmcblk0pX need to be done b4 you call swapon.

Wow, if only I read the second post and not gaze at the OP for 2h, it would have saved me two hours of googling. The OP needs to be modified.
Post Reply Subscribe to Thread

Tags
swap

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes