How To Create / Remove Swap Partition In Linux

February 25, 2011 | By in FILE SYSTEM,LINUX HOWTO
| 3 Replies More

Swap Linux

Swap memory is required when system requires more memory than it is physically available, the kernel swaps out less used pages and gives memory to the current process that needs the memory immediately. So a page of memory is copied to the pre-configured space on the hard disk. Disk speed is much slower compared to memory speed. Swapping pages give more space for current application in the memory (RAM) and make application run faster.

In some scenarios, system admin need to increase swap space. Below commands help you to expand the existing swap space.

Step 1

Check if you have enough space on disk to create new partition for swap.

Step 2

Create new partition using tool like fdisk:

#fdisk /dev/cciss/c0d0

Make the new partition as swap. Change toggle id to 82 (for swap).

Step 3

Run mkswap command on the newly created swap partition:

#mkswap /dev/cciss/c0d0p9
Setting up swapspace version 1, size = 6004416 kB

Step 4

Run swapon commad to enable swap space:

#swapon /dev/cciss/c0d0p9

Step 5

Verify the newly added swap space using below commands:

#cat /proc/swaps


#swapon -s

Step 6

Add newly created swap partition to fstab file. It should look as below:

/dev/cciss/c0d0p9 swap swap defaults 0 0

Somebody was asking me how to create/remove swap partiton for lvm. Below command helps for that. Assuming swap partiton was created on lvm partition.

Follow the below steps to increase the Swap for LVM

# swapoff -v /dev/rootvg/swapvol
# lvm lvresize /dev/rootvg/swapvol -L +8G (increase from 8 GB to 16 GB)
# mkswap /dev/rootvg/swapvol
# swapon -va

Follow the below steps to delete/ remove the Swap partition for LVM

Step 1

swapoff -v /dev/VolGroup00/LogVol01

Step 2

Then you need to delete the swap partition entirely.

#lvremove /dev/VolGroup00/LogVol01

Step 3

Remove the following entry from your /etc/fstab file.

/dev/VolGroup00/LogVol01 swap swap defaults 0 0


Tagged With :

Free Linux Ebook to Download

Comments (3)

Trackback URL | Comments RSS Feed

  1. Tom says:

    Zach ,

    Thanks for the info. I was looking swap partition on LVM and info you have provided was useful to me. Keep posting.

  2. Monal Sharma says:

    correction in step 5:

    cat /proc/swaps


    cat /proc/swap

Leave a Reply

All comments are subject to moderation.