Difference between revisions of "CentOS 7.x adding swap space using file"

From Notes_Wiki
(Created page with "<yambe:breadcrumb>CentOS_7.x_file_system_management|CentOS 7.x file system management</yambe:breadcrumb> =CentOS 7.x adding swap space using file= In CentOS 7.x swap can be c...")
 
m
 
Line 1: Line 1:
<yambe:breadcrumb>CentOS_7.x_file_system_management|CentOS 7.x file system management</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x system administration|System Administration]] > [[CentOS 7.x file system management|File system management]] > [[CentOS 7.x adding swap space using file]]
=CentOS 7.x adding swap space using file=


In CentOS 7.x swap can be configured via disk partitions.  It can also be configured from file located on any of the existing file-systems.  To create a file and configure it as swap use following steps
In CentOS 7.x swap can be configured via disk partitions.  It can also be configured from file located on any of the existing file-systems.  To create a file and configure it as swap use following steps
Line 37: Line 36:




<yambe:breadcrumb>CentOS_7.x_file_system_management|CentOS 7.x file system management</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x system administration|System Administration]] > [[CentOS 7.x file system management|File system management]] > [[CentOS 7.x adding swap space using file]]

Latest revision as of 06:45, 25 August 2022

Home > CentOS > CentOS 7.x > System Administration > File system management > CentOS 7.x adding swap space using file

In CentOS 7.x swap can be configured via disk partitions. It can also be configured from file located on any of the existing file-systems. To create a file and configure it as swap use following steps

  1. Install qemu-img package to create swap file. We can also create file using dd.
    yum -y install qemu-img
  2. Use qemu-img to create swap file of desired size
    qemu-img create -f raw -o preallocation=full /swap.raw 2G
    The file can be created anywhere instead of /swap.raw suggested in these steps
  3. Set correct file permissions on the swap file
    chmod 0600 /swap.raw
  4. Format file as swap
    mkswap /swap.raw
  5. Add entry in /etc/fstab for the file using following contents
    /swap.raw none swap defaults 0 0
  6. Mount all partitions and enable swap
    mount -a
    swapon -a
  7. Check whether additional swap is visible
    free -m

These steps can be used to add swap to cloud (Amazon AWS or Azure) etc. VMs as they do not come with swap. However, various cloud providers recommend not enabling swap and increasing ram instead.


Home > CentOS > CentOS 7.x > System Administration > File system management > CentOS 7.x adding swap space using file