pitSTOP

how to: add swap partition in linux

Posted by: aneeska on: June 25, 2009

Swap space in linux is analogous to page space(Virtual memory) in windows.

Three steps to make and use it in linux.

- create a partition and mark it as swap

- create a swap file system

- add the swap partition info /etc/fstab

create a partition and mark it as swap

Use “fdisk” to create a partition to be used as swap. One thing to remember is that the size of the partition need to be equal to or more than system RAM size for better performance.

More Info:

The swap partion’s system id should be set as hex code 82 so that when you list the partitions using fdisk the output sould look something like this:

$ fdisk -l /dev/sda

Device Boot      Start         End      Blocks   Id  System
/dev/sda4         4989        5100      899577   82  Linux swap / Solaris

create a swap file system

Now that the partition is ready, its time to create swap file system in it. Use the “mkswap” command

$ mkswap /dev/sda4

add the swap partition info /etc/fstab

Add the swap partition info to /etc/fstab so that in the next boot swap is mounted and used.

Add this line:

/dev/sda4                    swap    defaults        0 0

Verify whether swap is active

After a reboot, check the contents of this file

$ cat /proc/swaps

If swap is active, output will resemble something like this:

Filename                                Type            Size    Used    Priority
/dev/sda4                               partition       2031608 0       -1

A Short Reference

Read this REDHAT Documentation

Leave a Reply

tweeting is a way of life!