Kamis, 04 April 2019

How to add swap size on Linux Centos 7

  Tidak ada komentar
Check linux release
[[email protected] ~]$ cat /etc/*ease
CentOS Linux release 7.5.1804 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.5.1804 (Core)
CentOS Linux release 7.5.1804 (Core)
[[email protected] ~]$
Check the system swap
[[email protected] ~]$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 531848  -1
[[email protected] ~]$
[[email protected] ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7821        5906         130          95        1784        1485
Swap:          1023         519         504
[[email protected] ~]$
[[email protected] ~]$
Check the disk size
[[email protected] ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  124G   56G   62G  48% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  394M  3.5G  11% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                497M  208M  290M  42% /boot
/dev/mapper/centos-home   23G   50M   22G   1% /home
tmpfs                    783M   12K  783M   1% /run/user/42
tmpfs                    783M     0  783M   0% /run/user/1000
[[email protected] ~]$
Create swap file
[[email protected] ~]$ sudo fallocate -l 4G /swapfile
[sudo] password for ecpa:
[[email protected] ~]$ 
Check the swap file permission and change the permission
[[email protected] ~]$ ls -lh /swapfile
-rw------- 1 root root 4.0G Apr  5 10:13 /swapfile
[[email protected] ~]$
[[email protected] ~]$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=4e69b945-2896-4d6f-8893-74e8b4225e39
[[email protected] ~]$
Check the swap file and free swap size
[[email protected] ~]$ sudo swapon /swapfile
[[email protected] ~]$
[[email protected] ~]$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 531848  -1
/swapfile                               file    4194300 0       -2
[[email protected] ~]$
[[email protected] ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7821        5910         145          95        1765        1481
Swap:          5119         519        4600
[[email protected] ~]$
Make swap file persistent by register it to fstab configuration file
[[email protected] ~]$ sudo vi /etc/fstab
[[email protected] ~]$
[[email protected] ~]$ cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Jun 25 14:53:15 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       ext4    defaults        1 1
UUID=5ec8ac53-8089-498a-b894-67184ccf3465 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   ext4    defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/swapfile                                       swap    swap    sw  0   0
[[email protected] ~]$
[[email protected] ~]$ cat /proc/sys/vm/swappiness
30
[[email protected] ~]$


Tidak ada komentar :

Posting Komentar