Last Tweet

    KuJoe's Tweets

Categories

Latest Article

Latest Comment

Tag Cloud

Powered By...

Creating a Linux swap file.

Comments (0)
 
When I recently acquired my new cloud VM I found that the swap partition was only 256MB and so I wanted to expand that. I did some research and found that a swap file was equally as good as a swap partition and easier to grow, shrink, and remove.

I found a great site on how to do just that! (Copying the instructions in case the site disappears.)

Quote:

Procedure to add a swap file

You need to use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.

a) Login as the root user

b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
Code:
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288


c) Set up a Linux swap area:
Code:
# mkswap /swapfile1


d) Activate /swapfile1 swap space immediately:
Code:
# swapon /swapfile1


e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
Code:
# vi /etc/fstab


Append following line:
Code:
/swapfile1 swap swap defaults 0 0


So next time Linux comes up after reboot, it enables the new swap file for you automatically.

g) How do I verify swap is activated or not?
Simply use free command:
Code:
$ free -m

linux, tutorials

Comments

This article hasn't been commented yet.

Write a comment

* = required field

:

:

: