linux poison RSS
linux poison Email

How To create and use swap file (Adding Swap Space)

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 256 MB to 1 GB, but there is only 256 MB of swap space. It might be advantageous to increase the amount of swap space to 1 GB if you perform memory-intense operations or run applications that require a large amount of memory.

Linux also provides tools to manage your swap space. You can add and remove spaces as you need to, as well as turn them on and off, even while they are being used.

To create a file to be used a swap, you need to first create the file. This is most easily done with the dd command. To create a 65 Mb file, you might have this command (from the the mkswap man-page):

# dd if=/dev/zero of=/swapfile bs=1024 count=65536

which displays:

65536+0 records in
65536+0 records out

Next you have to prepare the file for usage as swap space using the mkswap. The simplest form would be:

# mkswap /swapfile

Now add this file to your swap pool

# swapon /swpafile

Now you can check if swap is added to your system by using following command

# free


4 comments:

Anonymous said...

# swpaon /swpafile.1

should

# swapon /swpafile.1

DevOps said...

Thank you, typo mistake, corrected now.

Anonymous said...

this shd also work quite well
#dd if=/dev/zero of=/swapfile bs=1024 count=65765

#mkswap /swapfile "size_here:eg 32435"

#sync

#swapon /swapfile

notice typo with the "swpafle.1"

Anonymous said...

Great info. I have a multi boot drive and need to delete my swap file, which i created as primary and replace it with a swapfile.

After creating the swapfile, as per instruction above, how can i get rid of the swap partition? just delete it or is there a proper way?

Post a Comment

Related Posts with Thumbnails