Steps to create / add swap memory space in Linux

Posted: July 26, 2015 in System Administration
Tags:

1. Create swap file-additional file with dd command in / (root). You can select any other partition but it should be mounted (For e.g. /opt, /usr, /NewMountedPartition)

dd if=/dev/zero of=/swapfile-additional bs=1M count=4048

dd = It is a unix command used for convert and copy a fileif = read from FILE instead of stdin/dev/zero = /dev/zero is a special file in Unix-like operating systems that provides as many null characters (ASCII NUL, 0x00) as are read from itof = write to FILE instead of stdout/swapfile-additional = file named swapfile-additional



will be created in /bs = Read and write bytes at a time but if you do not mention MB or GB like only number it will read as bytes. for eg. bs=1024 means 1024 bytescount = Copy input blocks in our case it is 1024 (1M * 4048 = 4GB)
2. Run mkswap command to make swap area

mkswap /swapfile-additional

3. Change the permission of file swapfile-additional

chmod 600 /swapfile-additional

4. Permanent mounting the swap space by editing the /etc/fstab file.Use your file editor, I generally use vi editor.

vi /etc/fstab

Paste below given content in /etc/fstab file

/swapfile-additional swap swap    0   0

5. Now mount the swap area, run below given command.

mount -a

6. Enable the swap area

swapon -a

7. Check the number swap space mounted on your system
swapon -s
8. To check how much is swap space available on system. Run below given command
free -m

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s