Swap Tutorial

Recomended way to allocate swap space is as following:

Lets suppose n is the size of Physical memory (RAM)

if n is less than or equal to 2 then,   swap=n x 2

for eg, if n=2    then swap will be n x 2 = 2 x 2 = 4GB swap

if n is greater than 2 then, swap = 1+n

for eg, if n=5  then swap will be n+1=5+1=6GB swap

swap in lvm

  1. lvs
  2. vgs
  3. swapon -s
  4. lvcreate -L 1G -n swaplv sysvg
  5. mkswap /dev/sysvg/swaplv
  6. swapon /dev/sysvg/swaplv
  7. swapon -s
  8. vi /etc/fstab

/dev/sysvg/swaplv         swap     swap     defaults 0 0

 

 

to remove

  1. swapoff                                  /dev/sysvg/swaplv
  2. swapon    -s
  3. remove entry from fstab

12. lvremove                                /dev/sysvg/swaplv

swap from file

  1. swapon -s
  2. dd if=/dev/zero of=/swapfile bs=1024 count=1048576 (1024*MB)
  3. mkswap /swapfile
  4. chown root:root /swapfile
  5. chmod 0600 /swapfile
  6. swapon /swapfile
  7. swapon -s
  8. vi /etc/fstab

/swapfile swap swap defaults 0 0

swap from partition

1. mkswap /dev/sdc1
2. swapon /dev/sdc1
3. cat /etc/fstab
/dev/sdc1 swap swap defaults 0 0
4. swapon -s

Leave a Reply