리눅스 기초 다지기 - 21. SWAP MEMORY

 

스왑 메모리

: 실제 메모리(Ram)가 모두 사용되었을 때 디스크 공간을 이용하여 부족한 메모리를 대체할 수 있는 공간을 의미한다.

 

swapon

: 스왑 영역의 활성화와 스왑 영역 확인에 사용

 

 

swapoff

: 스왑 영역 활성화 해제

 

mkswap

: 스왑 영역 생성

 

스왑 메모리 추가

[root@control ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           3.7Gi       387Mi       3.3Gi       8.0Mi       169Mi       3.3Gi
Swap:          2.0Gi          0B       2.0Gi

[root@control ~]# swapon -s
Filename                                Type            Size            Used            Priority
/dev/dm-1                               partition       2097148         0               -2

 

 

파티션 생성

# 파티션 에디터 사용
[root@control ~]# gdisk /dev/sdb

# 스왑 메모리로 추가할 파티션 생성 (2GB)
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-20971486, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +2GB
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

# 파티션 테이블 출력
Command (? for help): p

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4196351   2.0 GiB     8200  Linux swap

# 저장
Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

# 디바이스/파티션 재인식
partprobe /dev/sdb

 

 

스왑 영역 생성

# 스왑 영역 생성
[root@control ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=d57d2e0f-c4bf-447b-b190-9bc9a6f711bf

# 부팅 시 활성화 될 수 있게 fstab에 등록
[root@control ~]# vi /etc/fstab
UUID=d57d2e0f-c4bf-447b-b190-9bc9a6f711bf    none    swap    defaults        0 0

 

 

스왑 영역 활성화

# 스왑 영역 활성화
[root@control ~]# swapon -a

# 스왑 메모리 확인
[root@control ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           3.7Gi       390Mi       3.3Gi       8.0Mi       171Mi       3.3Gi
Swap:          4.0Gi          0B       4.0Gi

[root@control ~]# swapon -s
Filename                                Type            Size            Used            Priority
/dev/dm-1                               partition       2097148         0               -2
/dev/sdb1                               partition       2097148         0               -3