Thursday 20 December 2012

Linux Tips:Setting SWAP Memory under Linux

Setting SWAP Memory under Linux

 These are the steps to add swap space to your Linux system through the use of swap files.

  • Determine the amount of existing swap space
    more /proc/swaps
    

    This will list any swap partitions and swap files currently in use. Your swap space should be at least twice the amount of physical RAM installed for best results. For example, a system with 512MB of physical RAM should have at least 1GB of swap space.
    To configure 2GB of swap, we can make one 2GB swap file or two 1GB swap files. We'll do two 1GB swap files because one 2GB swap file might not work depending on Linux kernel support for large files (file over 2GB).
  •  
  • Make swap files named swapfile1 and swapfile2 in /var/tmp
    cd /var/tmp
    dd if=/dev/zero of=swapfile1 bs=1024 count=1048576
    dd if=/dev/zero of=swapfile2 bs=1024 count=1048576
    

    This creates the files /var/tmp/swapfile1 and /var/tmp/swapfile2, each 1GB in size. Using the "dd" command ensures that the files have no holes.
  •  
  • Turn each swap file into a swap area
    /sbin/mkswap -c -v1 /var/tmp/swapfile1
    /sbin/mkswap -c -v1 /var/tmp/swapfile2
    

    This checks each file for bad blocks, then turns it into swap space.
  • Enable the swap files for swapping
    /sbin/swapon /var/tmp/swapfile1
    /sbin/swapon /var/tmp/swapfile2
     
  • Verify that the system is using the swap file
    more /proc/swaps
    

    You should see entries for /var/tmp/swapfile1 and swapfile2.
  •  
  • Set up your system to load the swap space at startup
    In /etc/rc.d/rc.sysinit, look for a line that contains:
    
    swapon -a
    
    Append this command to enable your swap files at startup:
    
    swapon /var/tmp/swapfile1
    swapon /var/tmp/swapfile2
    
    The line should now look something like this:
    
    action "Activating swap partitions" swapon -a
     swapon /var/tmp/swapfile1
     swapon /var/tmp/swapfile2
    
    
  •  

    1 comment: