OS/Linux

How To Add Swap on CentOS 7

Temporary backups 2021. 3. 24. 00:35
반응형

Creating a Swap File

Step 1: Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 1024MB/1GB swap file is 1048576.

Step 2: At a shell prompt as root, type the following command with count being equal to the desired block size: dd if=/dev/zero of=/swapfile bs=1024 count=1048576

Step 3: Setup the swap file with the command: mkswap /swapfile

Step 4: To enable the swap file immediately but not automatically at boot time: swapon /swapfile

Step 5: To enable it at boot time, edit /etc/fstab by nano or vi to include the following entry: /swapfile swap swap defaults 0 0

The next time the system boots, it enables the new swap file.

 

Removing a Swap File

Step 1: At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file): swapoff -v /swapfile

Step 2: Remove its entry from the /etc/fstab file by nano or vi.

Step 3: Remove the actual file rm /swapfile

반응형