[GUIDE] How to create a swap partition on external micro-sd

Search This thread

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
Alright folks, you asked for it and here's a simple how-to that will guide you to create and enable a swap partition on external micro-sd on our SGS.

First things first I assume you have already flashed the kernel Devil2_0.73_swap_i9000_CFS_BLN_CMC_20120420 or any other kernel which 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.
If you are on mac you can use iPartition to partition your sd-card, while linux users can use Gparted or any other partition tool they may like.

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/mmcblk1

it will look something like this

Code:
/dev/block/mmcblk1p2            1861        1924      514080  82 Linux swap

write down the exact number of the swap partition and let's activate it by typing

Code:
swapon /dev/block/mmcblk1pX

** 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 /system/etc/init.d/05userinit

now lets drop few lines in

Code:
#Activate swap at boot

#!/system/bin/sh

swapon -a

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

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

Code:
chmod 750 /system/etc/init.d/05userinit

Now lets create a fstab file so that the kernel can look at and activate the correct swap partition

Code:
vi /system/etc/fstab

Here it goes our swap partition. Remember where X is your actual swap partition according to your partition layout.

Code:
/dev/block/mmcblk1pX swap swap

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:
shell@android:/ # free
             total         used         free       shared      buffers
Mem:        385772       376352         9420            0        26420
-/+ buffers:             349932        35840
Swap:       514076            0       514076


** 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..

/** A special shout goes out to @DerTeufel1980 for listening to our request and enabling swap on his kernel. **/

So cheers you all and enjoy :)
 

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
is it possible to make swap on internal flash storage ?

Yes it is, but it wont worth to use ur nand as swap as the function of the swap is to read and write cpu data, and its usually very aggressive.
Yes it is faster, but it will most likely going to damage the nand, while using a sd-card is usually slower but the worst scenario is that u will have to trash your sd-card after a couple of years, not the phone..
 

gokussjx

Senior Member
Jul 7, 2011
2,061
4,910
/home/bidyut
Great Guide! Quite detailed :)

So, did you notice any heavy good change using SWAP?
Or is it just noticeable?

And what about Multitasking?
 

Segnale007

Senior Member
Feb 24, 2010
1,071
218
Mexico City
twitter.com
Great Guide! Quite detailed :)

So, did you notice any heavy good change using SWAP?
Or is it just noticeable?

And what about Multitasking?

Thank your for the feedback. However I can say I have suddenly noticed a speed bost in the way the phone response, especially whit multiple applications open and services running in background. Till yesterday without swap I had to close like some apps each 4/5 opened and left in background. Right now I am playing GTA and I have like 8 apps opened in background.
 
  • Like
Reactions: gokussjx

dark_knight35

Senior Member
Jan 15, 2012
1,936
989
Thank your for the feedback. However I can say I have suddenly noticed a speed bost in the way the phone response, especially whit multiple applications open and services running in background. Till yesterday without swap I had to close like some apps each 4/5 opened and left in background. Right now I am playing GTA and I have like 8 apps opened in background.

How big is your swap partition?
Looking forward to getting a new micro sd to also feel the speed.
 

lerkin

Senior Member
Jan 4, 2011
1,125
375
msk
Now I use 512 mb swap on 10 class sd-card partitioned and set up by this guide. Works well. Feels like much better than with swapper2. Thanks
 
  • Like
Reactions: Segnale007

Top Liked Posts

  • There are no posts matching your filters.
  • 33
    Alright folks, you asked for it and here's a simple how-to that will guide you to create and enable a swap partition on external micro-sd on our SGS.

    First things first I assume you have already flashed the kernel Devil2_0.73_swap_i9000_CFS_BLN_CMC_20120420 or any other kernel which 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.
    If you are on mac you can use iPartition to partition your sd-card, while linux users can use Gparted or any other partition tool they may like.

    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/mmcblk1

    it will look something like this

    Code:
    /dev/block/mmcblk1p2            1861        1924      514080  82 Linux swap

    write down the exact number of the swap partition and let's activate it by typing

    Code:
    swapon /dev/block/mmcblk1pX

    ** 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 /system/etc/init.d/05userinit

    now lets drop few lines in

    Code:
    #Activate swap at boot
    
    #!/system/bin/sh
    
    swapon -a

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

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

    Code:
    chmod 750 /system/etc/init.d/05userinit

    Now lets create a fstab file so that the kernel can look at and activate the correct swap partition

    Code:
    vi /system/etc/fstab

    Here it goes our swap partition. Remember where X is your actual swap partition according to your partition layout.

    Code:
    /dev/block/mmcblk1pX swap swap

    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:
    shell@android:/ # free
                 total         used         free       shared      buffers
    Mem:        385772       376352         9420            0        26420
    -/+ buffers:             349932        35840
    Swap:       514076            0       514076


    ** 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..

    /** A special shout goes out to @DerTeufel1980 for listening to our request and enabling swap on his kernel. **/

    So cheers you all and enjoy :)
    20
    Hi guys, great thread.
    I tried the zip from sunra and works great, but it has 2 issues i wanted to address:
    1. It doesn't automatically detect the swap partition
    2. It is embedded with a specific version of Devil kernel

    I updated swap.sh to automatically detect the kernel support for swapping and the swap partition name (in the external sd only, as it's dangerous to enable such a partition in the internal sd).
    Also the updater-script gives some output on the operation (success, swap not supported by kernel, swap partition not found).

    Just install it from recovery AFTER installing a kernel that supports swap (for example Devil 0.79)

    Thanks to Segnale007 and sunra0815 for the idea.

    Please try it and let me know if works correctly!
    4
    ok guys, I made a package with devil kernel and swap settings.

    1. Read the op carefully!
    2. Make a swap partition on your /emmc (512mb should be more than enough)
    3. It will only work if you have the following swap partition number!!!
    Code:
    /dev/block/mmcblk[COLOR="Red"]1p2[/COLOR]

    4. Flash the package via cwm.

    5. After a reboot check out if it works with the "free" command.

    6. enjoy

    If your swap partition has an other number you can change it in the scripts in the .zip package with notepad++ or any linux editor.

    1. /systm/etc/fstab
    2. /swap.sh

    If you do not know what I´m talking about do NOT flash!!!

    I´m not a pro. I made this for myself, but maybe it is usefull for you too ...

    Please make a Nandroidbackup before and let me know if it works for you.
    2
    You never know...
    2
    @Segnale007:

    Here is a command to readaout the swap partition (don´t know if that only works while the swap partition is active??):

    Code:
    awk -F" " '{if (NR!=1) {print "\r",$1}}' /proc/swaps

    Uhm it needs to be tested.. Anyways like I said I have really no time atm to work on a flashable cwm zip to automate few steps..

    I understand this can be very useful for some users, mainly nightly flashers, however the main purpose of this guide is to illustrate the users a option to not have to relay on a third party app with limitations and additional ram consumption.

    Thank you all for your understanding.