Archive for the tag 'swap'

Quick way to add more SWAP space on your server

To check the swap space used you can use “free -m“.

If for some reason you have a server with too little SWAP then there is a quick way to create a swap file and then use it for additional swap space on the server.

dd if=/dev/zero of=/opt/swapfile bs=1024 count=2048000
mkswap /opt/swapfile
swapon /opt/swapfile
swapon -s

And then we need to add the following to the /etc/fstab.

/opt/swapfile swap swap defaults 0 0

Instructions for deleting the swap file after import in Ensim

Eg. partition - /dev/hda3 mounted on /, swap file - /var/swapfile.

Turn off swapping for file “/var/swapfile” with the following command:

swapon, swapoff - enable/disable devices and files for paging and swapping

Swapoff disables swapping on the specified devices and files. When the -a flag is given, swapping is disabled on all known swap devices and files (as found in /proc/swaps or /etc/fstab)

#swapoff /var/swapfile

Delete the file “/var/swapfile” with the following command:

#rm -f /var/swapfile
SBDavid

Instructions to setup swap file

Instructions to setup swap file

Select the partition where you want to create the swap file. This partition must have free disk space to create the swap file.

Create a file for swap with the following command (# is shell prompt):

#dd if=/dev/zero of=/var/swapfile bs=1024 count=[count]

where [count]= number of 1024 blocks required. If count=1024000 size of /var/swapfile will be 1024* 1024000 = 1 GB .

You can decide the size of “/var/swapfile” depending on the size of the backup tar file.

Setup an extra swap with the following command:

#mkswap /var/swapfile

Enable “/var/swapfile” for swapping with the following command:

#swapon /var/swapfile

Verification: The file “/proc/swaps” must contain the entry for the swap file “/var/swapfile”. If this entry is not present, then swapping has not been enabled for the swap area.

SBDavid

Size of swap partition

Size of swap partition

Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then 1x physical RAM for any amount above 2 GB, but never less than 32 MB.

Using this formula, a system with 2 GB of physical RAM would have 4 GB of swap, while one with 3 GB of physical RAM would have 5 GB of swap.

Creating a large swap space partition can be especially helpful if you plan to upgrade your RAM at a later time.

If your partitioning scheme requires a swap partition that is larger than 2 GB, you should create an additional swap partition. For example, if you need 4 GB of swap, you should create two 2 GB swap partitions. If you have 4 GB of RAM, you should create three 2 GB swap partitions. Red Hat Enterprise Linux supports up to 32 swap files.

SBDavid

Change priority of swap files

Change priority of swap files

You can check the current priority of the swap file from /proc/swaps.

$ cat /proc/swaps

Inorder to change the priority of the swap partitions, you need to edit the “fstab” and append the new priority. If you have the fstab entry for your swap file /swap1 as:

/swap1 swap swap defaults 0 0

then append the following:

/swap1 swap swap pri=x,defaults 0 0

where x is the new priority you have set.

You can re-mount it by using ‘mount -a’ command.