Kamis, 04 April 2019

How to add swap size on Linux Centos 7

  Tidak ada komentar
Check linux release
[user@galera ~]$ 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)
[user@galera ~]$
Check the system swap
[user@galera ~]$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 531848  -1
[user@galera ~]$
[user@galera ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7821        5906         130          95        1784        1485
Swap:          1023         519         504
[user@galera ~]$
[user@galera ~]$
Check the disk size
[user@galera ~]$ 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
[user@galera ~]$
Create swap file
[user@galera ~]$ sudo fallocate -l 4G /swapfile
[sudo] password for ecpa:
[user@galera ~]$ 
Check the swap file permission and change the permission
[user@galera ~]$ ls -lh /swapfile
-rw------- 1 root root 4.0G Apr  5 10:13 /swapfile
[user@galera ~]$
[user@galera ~]$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=4e69b945-2896-4d6f-8893-74e8b4225e39
[user@galera ~]$
Check the swap file and free swap size
[user@galera ~]$ sudo swapon /swapfile
[user@galera ~]$
[ecpa@galera ~]$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 531848  -1
/swapfile                               file    4194300 0       -2
[user@galera ~]$
[user@galera ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7821        5910         145          95        1765        1481
Swap:          5119         519        4600
[user@galera ~]$
Make swap file persistent by register it to fstab configuration file
[user@galera ~]$ sudo vi /etc/fstab
[user@galera ~]$
[user@galera ~]$ 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
[user@galera ~]$
[user@galera ~]$ cat /proc/sys/vm/swappiness
30
[user@galera ~]$


Tidak ada komentar :

Posting Komentar