Sharing Knowledge | System Admin Articles

Quick HOWTO : Steps to create swap file in Linux

Step 1:

Create the file.

This file will be 1024*524288 bytes. Generally it is a good
idea to create the swap file twice as big as the amount of
RAM that you have installed if you are under a 1 GB.

However, if you have larger amounts of RAM, it's best to run
your own tests with free to see how you're using the swap

$ dd if=/dev/zero of=/swapfile0 bs=1024 count=524288

Step 2:

Setup the swap area on the file you created.

$ mkswap /swapfile0

Step 3:

Enable the file for swapping

$ swapon /swapfile0

Step 4:

Permanently enable the swap file on boot.
Add the following lines to /etc/fstab.

/swapfile0 swap swap defaults 0 0

Step 5:

Check that the swap file is working the the free command. Also,
reboot too to make sure the swap file works on restart and that
/etc/fstab was correctly configured.

Labels: Linux, Quick HOWTO

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 : Steps to create swap file in Linux"

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

Back To Top