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

Search This thread

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
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 :)
 
Last edited:

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
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 .
 
Last edited:

Sir_gpm

Senior Member
May 27, 2011
2,364
312
Managua
POCO X4 Pro
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?
 

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
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.
 
Last edited:
  • Like
Reactions: Sir_gpm and CrItIcX

lrakkarl

Senior Member
Dec 13, 2011
105
527
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.
 
Last edited:

hajiborojobo

Senior Member
Apr 28, 2011
108
8
Ostrava
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..
 

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
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..
 
  • Like
Reactions: WhatWhatInTheButt

revan17

Senior Member
Dec 23, 2010
995
273
38
Zagreb
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.
 

ankitxperia

Senior Member
Feb 19, 2011
283
90
mumbai
I Create Partion Using ClockwordRecovery MOD its that simple
even swapper works great can any body tell me i am doing something wrong
 

cenovita

Senior Member
Aug 29, 2011
141
7
Hi all, why I always get this?

mkswap /dev/block/mmcblk0p2
Setting up swapspace version 1, size = 255593472 bytes
swapon /dev/block/mmcblk0p2
swapon: /dev/block/mmcblk0p2: Invalid argument

Also swapper2 is not working either...

I am using last nAa kernel and ROM.

Thanks.
 

NIMBAH

Senior Member
Dec 20, 2011
724
176
London
Hi all, why I always get this?

mkswap /dev/block/mmcblk0p2
Setting up swapspace version 1, size = 255593472 bytes
swapon /dev/block/mmcblk0p2
swapon: /dev/block/mmcblk0p2: Invalid argument

Also swapper2 is not working either...

I am using last nAa kernel and ROM.

Thanks.

If you have an ext partition then its mmcblk0p3.

Sent from my X8 using xda premium
 

cenovita

Senior Member
Aug 29, 2011
141
7
If you have an ext partition then its mmcblk0p3.

Sent from my X8 using xda premium

I have just 2, one FAT32 (7gb) and the rest is for the SWAP part, I have tried formatting it with swap and ext3, no case...

look at this:

Disk dev/block/mmcblk0: 8064 MB, 8064598016 bytes
255 heads, 63 sectors/track, 980 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
dev/block/mmcblk0p1 1 922 7405933+ b Win95 FAT
dev/block/mmcblk0p2 923 980 465885 83 Linux
root@android:/ # mkswap /dev/block/mmcblk0p2
mkswap /dev/block/mmcblk0p2
Setting up swapspace version 1, size = 255593472 bytes
root@android:/ # swapon /dev/block/mmcblk0p2
swapon /dev/block/mmcblk0p2
swapon: /dev/block/mmcblk0p2: Invalid argument
1|root@android:/ # free
free
total used free shared buffers
Mem: 189448 162852 26596 0 24
-/+ buffers: 162828 26620
Swap: 0 0 0
root@android:/ # swapon /dev/block/mmcblk0p3
swapon /dev/block/mmcblk0p3
swapon: can't stat '/dev/block/mmcblk0p3': No such file or directory
1|root@android:/ # swapon /dev/block/mmcblk0p3

BTW, if i partition with minitool, the card is not mountable by the phone... I have to partition with recovery...

---------- Post added at 04:24 PM ---------- Previous post was at 04:14 PM ----------

OK, I have partitioned with Recovery and created 1 ext partition of 256Mb and 1 swap partition of 256Mb.

After that, i was able to mount swap in p3 (the swap one).

Minitool, useless for me...
 
Last edited:

bobgeneric

Senior Member
Feb 24, 2012
639
84
hI DEVS!
I have 2 partitions: Fat32-1,6GB (my files) and ext4-200MB (linked files)
Can i use swap?
If yes... the command will be: swapon /dev/block/mmcblk0p2 ?
 

NIMBAH

Senior Member
Dec 20, 2011
724
176
London
hI DEVS!<br />
I have 2 partitions: Fat32-<b>1,6GB </b>(my files) and ext4-<b>200MB</b> (linked files)<br />
Can i use swap?<br />
If yes... the command will be: <b>swapon /dev/block/mmcblk0p2</b> ?

No you will need to create another partition for swap. The best way is through recovery but that will require reformatting your SD Card.

Sent from my X8 using xda premium
 
  • Like
Reactions: bobgeneric

webuser71

Member
Oct 4, 2010
37
4
Android ICS 4.0.3

Hello,
i have Script und working fine with gscript. But i wont do it in autostart. I copy userinit.sh in data\local\ reboot but i have no swap. I mus the script with gscript.
can anyone help me please.
i have HRC HD2 with CLK-NexusHD2.1HWA ICS-Android 4.0.3
thanks
 

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    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 :)
    3
    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.
    2
    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.
    2
    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.
    1
    You are using swap file, it can be created by swapper. Swap partition is easier - it will persist when you connect to pc.