Thursday, 28 February 2013

How to create SWAP space in Linux Servers

You need to use the dd command to create swap file. The mkswap command is used to set up a Linux swap area on a device or in a file.

Login as root user, and use the following command to create a swap file.

The following dd command example creates a swap file with the name “tmpDSK” under /backup directory with a size of 2000MB (2GB)

# dd if=/dev/zero of=/backup/tmpDSK bs=1M count=2000

Setup correct file permission for security reasons, enter:

# chown root:root  /backup/tmpDSK
# chmod 600 /backup/tmpDSK

Make this file as a swap file using mkswap command.

# mkswap /backup/tmpDSK
Setting up swapspace version 1, size = 2097147 kB

To make this swap file available as a swap area even after the reboot, add the following line to the /etc/fstab file.

/backup/tmpDSK       swap                     swap     defaults        0 0

Enable the newly created swapfile.

# swapon /backup/tmpDSK

# free -m
             total       used       free     shared    buffers     cached
Mem:          4050       3222        828          0        210       2589
-/+ buffers/cache:        422       3628
Swap:         1999          0       1999

No comments:

Post a Comment

Note: only a member of this blog may post a comment.