• 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. When to use rescan-scsi-bus.sh -i (LIP flag) in CentOS/RHEL
  2. rm Command Examples in Linux
  3. grub-install Command Options
  4. How to Configure Separate Port For SSH and SFTP On CentOS/RHEL
  5. How to configure VNC Server on CentOS/RHEL 6
  6. After Reboot RAID1 Disk Gets Removed/Out of Sync (CentOS/RHEL)
  7. How to Convert a Directory to Partition in Linux
  8. How to run ssh on multiple ports
  9. CentOS / RHEL : How to find Logical volumes (LVs) contained in Physical Volume (PVs) in LVM
  10. How to use sudo to allow a non-root user run a particular command

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright