Saturday, December 19, 2009

File System - Swap Space

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the physical memory is full, inactive pages in memory are moved to the swap space.

Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files

Steps to create swap
  • fdisk device_name - to create a partition
  • mkswap partition – initialize swap partition
  • swapon partition – enable the swap partition
  • swapon –s - to list the swap partition
  • Add a entry in /etc/fstab file to mount after reboot
To create new swap partition
# lvcreate vg0 –n lv2 –L 512M
Initialize new swap
# mkswap /dev/vg0/lv2
Enable swap partition
# swapon –va
Add an entry to fstab
# vi /etc/fstab
/dev/vg0/lv2 swap swap defaults 0 0
To check the swap partition information
# cat /proc/swaps
or 
# swapon -s

To remove swap partition
# swapoff -v /dev/vg0/lv2
# lvremove /dev/vg0/lv2
Remove the fstab entry
# vi /etc/fstab
#/dev/vg0/lv2 swap swap defaults 0 0
To check the swap partition information
# cat /proc/swaps

To create a swap file
# dd if=/dev/zero of=/swapfile bs=1024 count=65536
# mkswap /swapfile
Add an entry to fstab
# vi /etc/fstab
/swapfile swap swap defaults 0 0
# swapon /swapfile
# cat /proc/swaps

To remove a swap file
# swapoff -v /swapfile
# rm /swapfile
# cat /proc/swaps

No comments:

Post a Comment