• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to add Swap Space on Linux Servers (CentOS/RHEL) On the Fly

by admin

In Most of the UNIX-like operating systems, the swap partition is created during the installation time, However, with kernel 2.6 swap files can be used as a swap partition.

The administrative flexibility of swap files outweighs that of partitions; since modern high-capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous. We can add a swap file as a dedicated partition.

Why Linux require Swap Memory?

Linux divides its physical RAM (random access memory) into chunks of memory called pages. Swapping is the process whereby a page of memory is copied to the pre-configured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

Steps To Add Swap File

Step 1: Create a file(1GB) using dd Command.

Login into the terminal as a root, Type below command:

# dd if=/dev/zero of=/root/swapfile bs=1M count=1024

Step 2: Swap Area on swapfile using mkswap.

# mkswap  /root/swapfile

Step 3: Enable Swap space on the file.

# swapon /root/swapfile

Step 4: check the status of Swap space using below commands:

# swapon -s

add swap file on the fly in linux

OR

check swap usage in Linux

Step 5: To activate swapfile after reboot, add below entry to /etc/fstab file.

/root/swapfile           swap                   swap    defaults        0 0

Filed Under: CentOS/RHEL, Linux

Some more articles you might also be interested in …

  1. How to interpret Linux martian source messages
  2. iostat: command not found
  3. “cannot install the best update candidate for package” – error on running dnf update
  4. Linux OS Service ‘NetworkManager’
  5. setpci command – configure PCI device
  6. How To Disable MD5-based HMAC Algorithm’s for SSH
  7. ncat Command Examples in Linux
  8. host: command not found
  9. CentOS/RHEL: “id” command doesn’t list the Group Name against GID for LDAP Users
  10. nano: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright