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: | ||
[[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]] | |||
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: | ||
[[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
- Install qemu-img package to create swap file. We can also create file using dd.
- yum -y install qemu-img
- 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
- Set correct file permissions on the swap file
- chmod 0600 /swap.raw
- Format file as swap
- mkswap /swap.raw
- Add entry in /etc/fstab for the file using following contents
- /swap.raw none swap defaults 0 0
- Mount all partitions and enable swap
- mount -a
- swapon -a
- 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