Announcement

Collapse
No announcement yet.

Swap in Linux

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Swap in Linux

    Swap space is used when the amount of physical memory (RAM) is full. If the system needs more memory and no more RAM is available, inactive pages in memory are moved to the swap space. Swap should not be considered as a replacement of RAM memory because swap space is on hard drives and I/O access to hard drives is slower than I/O access memory.

    The swap must be located on a dedicated swap partition and it is designed to help RAM memory not to replace it.
    Swap partition

    * Using parted a swap partition can be created in order to be added to the existing swap (or just to create it for the first time) :

    Code:
    $ parted /dev/sdb
    GNU Parted 2.1
    Using /dev/sdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) mkpart
    Partition type? primary/extended? p
    File system type? [ext2]? linux-swap
    Start? 1
    End? 512M
    (parted) quit
    Now /dev/sdb1 is a 512M swap partition
    * Next step is create the swap filesystem on the swap partition :
    Code:
    $ mkswap /dev/sdb1
    Setting up swapspace version 1, size = 498684 KiB
    no label, UUID=81631aa8-8064-47fc-92ef-5eb3fa6e8b87
    * Once the swap filesystem has been created the final step is activate the new swap space :
    Code:
    $ free | grep Swap
    Swap: 1736696 0 1736696
    The initial swap size is 1736696 Kb
    Code:
    $ swapon /dev/sdb1
    It activates the new swap
    Code:
    $ free | grep Swap
    Swap: 2235376 0 2235376
    After the new swap (512 M) has been added the new swap size is 2.2G

    * Adding the corresponding line to /etc/fstab the system will activate automatically the swap on boot :
    Code:
    $ echo "/dev/sdb1 swap swap defaults 0 0" >> /etc/fstab
    Last edited by kuldeep; 02-22-2015, 12:07 AM.
Working...
X