Sharing Knowledge | System Admin Articles

Quick HOWTO: Reduce SWAP Partition Online without reboot in Linux

Recently I had a request to reduce the swap space and allocate that space to some other LV in one of our server.  Below is what I followed and it perfectly worked for me.  :)

Make sure you have enough physical memory to hold the swap contents. 

Now, turn the swap off:
# sync
Now check the status
# swapon -s 

Then, Use fdisk command:
# fdisk <YOUR_HARDDISK_Where_SWAP_Resides>
List partitions with "p" commandFind Delete your partition with "d" commandCreate a smaller Linux-Swap partition with "n" commandMake sure it is a Linux-Swap partition (type 82) (Change with "t" command)Write partition table with "w" command

Run "partprobe" to update Filesystem table to kernel. (It is very important before proceeding further)

check to make sure swap is turned on
swapon -s 
Now you can use your free space to increase space for other Logical volumes (LV). 

Use fdisk command to create new partition, then 

# partprobe
# lvextend -L  +SIZE_TO_INCREASE <LV_NAME> 

Note: It is extreme importance of syncing and turning the swap off before you change any partitions. If you FORGET TO DO THIS, YOU WILL LOST_DATA!!

Labels: Linux, Quick HOWTO, Swap

My Profile PhotoAbout the Author

I'm Parthiban, An UNIX System Admin by Profession. I'm Experienced in Linux/Unix System Administration and Scripting. I have done lot of work on the infrastructure Mgmt side in Linux, UNIX and Windows system administration, Hardware, Storage and Data center. I'm blogging since 2008.
Follow Me On Twitter or On Facebook

0 Comments for "Quick HOWTO: Reduce SWAP Partition Online without reboot in Linux"

What do you think about this Article? Add your Opinion..!

Back To Top