Wednesday, July 17, 2013

Create a Swap Partition in Linux

Swap Partition in RHEL6

Swap partition is used to increase system speed by enabling virtual memory concept space taken from HDD.
When you install Linus operating system you have option to create swap partition otherwise you can also create swap ofter installation.

There are two different types of swaps that you can have:
file swap and partition swap.

Commands that is used to manage swap patition in linux
mkswap             Creates a swap device
swapon              Enables a swap space
swapoff             Disables a swap space
dd                      Wipes or zeroes out an area of the disk

Syntax: swapon [options] DEVICE
 Options that you can use for different purpose.
-a Enables all swap devices
-e Silently skips devices that don’t exist
-s Verifies that the swap is running

1-Partition swap:
Example: Create the swap space on /dev/hdd2:
A-# mkswap /dev/hdc2
where /dev/hdd2 is you partition name .

To enable the swap on /dev/hdd2 partition:
# swapon /dev/hdd2

To verify that the swap is running correctly:
# swapon -s

To disable the swap on /dev/hdd2 partition:
# swapoff /dev/hdd2

You can also set up a file swap.
You can use the dd command to reserve space for another swap on.

# dd if=/dev/zero of=/mnt/file_swap bs=1024 count=1000000

To make swap file
# mkswap /mnt/kamal_swap
where kamal_swap is your file name.

To enable the swap:
# swapon /mnt/file_swap

Again, you can verify that the swap is enabled:
# swapon -s

No comments:

Post a Comment