• 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. “WARNING: Failed to connect to lvmetad. Falling back to device scanning” – error while running LVM commands
  2. Linux Network File System (NFS) interview questions
  3. “ntpq -pn” command returns with error “Name or service not known”
  4. rpmspec Command Examples in Linux
  5. RPM command examples to query, install, remove and upgrade packages
  6. dig Command Examples in Linux
  7. How to mount USB flash drive in Linux
  8. How to Mirror Swap, Boot and Root Partions in CentOS/RHEL 7 Using mdadm Utility
  9. CentOS/RHEL : Unmounting a Windows Share Fails – “device is busy”
  10. toilet: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • ctags: Generates an index (or tag) file of language objects found in source files for many popular programming languages
  • csvtool: Utility to filter and extract data from CSV formatted sources
  • csvstat: Print descriptive statistics for all columns in a CSV file
  • csvsql: Generate SQL statements for a CSV file or execute those statements directly on a database

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright