Archive for December, 2008

Sometimes it is necessary to add more swap space after a server installation.
For example, you may need to do this when you feel it is time to upgrade the amount of RAM in your server, doing this will take you to upgrade you Swap Space as well since the Swap space need to be 2x times the amount of RAM installed on your server.

It might be advantageous to increase the amount of swap space to x2 of your RAM if you perform memory-intense operations or run applications that require a large amount of memory.
In this case a customer has upgraded his server RAM, hence we proceeded to upgrade his Swap Space as well.

In this example we are going to create a 8GB Swap file.

1) Make sure you have 8 GB laying around somewhere:

  1. [root@box home]# df -h
  2. Filesystem            Size  Used Avail Use% Mounted on
  3. /dev/sda1             3.0G  2.5G  398M  87% /
  4. /dev/sda2             226G   97G  119G  45% /home
  5. /dev/shm              4.0G     0     4.0G   0% /dev/shm

2) /home since to be the best one to do this (Keep in mind that partition table schemes will differ from Server Companies to Server Companies, this is NOT the best partition table scheme we recommend for our customers.) so We’re going to make a swap file in /home by using dd to create a file 8GB file in size.

  1. [root@box home]# dd if=/dev/zero of=swapfile bs=1024 count=8290304
  2. 8290304+0 records in
  3. 8290304+0 records out
  4. 8489271296 bytes (8.5 GB) copied, 259.485 seconds, 32.7 MB/s

3) We setup some Permission restrictions for security reasons

  1. [root@box home]# chmod 600 swapfile

4) Now we set up the swap area and enable it.

  1. [root@box home]# mkswap swapfile
  2. Setting up swapspace version 1, size = 8489267 kB
  3. [root@box home]# swapon swapfile

5) We should be set to go, Now we double check that our swap memory has increased,

  1. [root@meyer home]# free -m
  2. total       used       free     shared    buffers     cached
  3. Mem: 4104     3804      300        0       15     3012
  4. -/+ buffers/cache: 793     7311
  5. Swap:  8605     34     8591

6) You can edit /etc/fstab to enable your swap file automatically at boot time.
By adding an entry like this:

  1. /home/swapfile       swap                swap    defaults        0 0