OpenWrt swap 화일생성/포멧/마운트/언마운트

swap은 메모리(ram)의 용량이 가득 차게될 경우 보조적으로 하드드라이브나 usb저장장치를 메모리 대용으로 사용하는 *nixlike 운영체제 메모리 관리 기술로 OpenWrt 라우터에서 usb 저장장치의 화일을 swap 공간으로 만들는 방법을 설명합니다.

swap은 하드드라이브 또는 usb 저장장치 상에 위치하기 때문에 물리적 메모리에 접근하는 것보다 접근속도가 훨씬 느리며 소량의 ram을 사용하는 라우터는 도움이 되지만 256M 이상의 ram를 가진 라우터는 일반적인 경우 swap이 필요 없습니다.

swap-utils 설치

opkg update
opkg install swap-utils

swap 화일생성/포멧/마운트

128메가의 swapfile을 생성/포멧/마운트하는 예시입니다.

mkdir /mnt/sda1/swap
dd if=/dev/zero of=/mnt/sda1/swap/swapfile bs=1M count=128
chmod 600 /mnt/sda1/swap/swapfile
mkswap /mnt/sda1/swap/swapfile
swapon /mnt/sda1/swap/swapfile

[email protected]:~# mkdir /mnt/sda1/swap
[email protected]:~# dd if=/dev/zero of=/mnt/sda1/swap/swapfile bs=1M count=128
128+0 records in
128+0 records out
[email protected]:~# chmod 600 /mnt/sda1/swap/swapfile
[email protected]:~# mkswap /mnt/sda1/swap/swapfile
Setting up swapspace version 1, size = 128 MiB (134213632 bytes)
no label, UUID=5d50e542-7712-4af6-9d4e-e05b5f9c1a7d
[email protected]:~# swapon /mnt/sda1/swap/swapfile
[email protected]:~# free
              total        used        free      shared  buff/cache   available
Mem:         478396      129952       27608        1748      320836      334908
Swap:        131068           0      131068
[email protected]:~#

부팅시 자동마운트

방법(1)

부팅시 swapfile이 자동으로 마운트되도록 /etc/rc.local 에 추가합니다.

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

# turn on swap space
swapon /mnt/sda1/swap/swapfile

exit 0

방법(2)

부팅시 swapfile이 자동으로 마운트되도록 /etc/config/fstab 을 수정합니다.

config global
        option anon_swap '1'
...

config swap
        option enabled '1'
        option device '/mnt/sda1/swap/swapfile'
        option uuid '5d50e542-7712-4af6-9d4e-e05b5f9c1a7d'
        option label 'foobar'

swap 화일 언마운트

스왑메모리 사용을 해제하려면 swapoff 명령으로 다음과 같이 입력합니다.

swapoff /mnt/sda1/swap/swapfile

[email protected]:~# free
              total        used        free      shared  buff/cache   available
Mem:         478396      128252       29304        1748      320840      336620
Swap:        131068           0      131068
[email protected]:~#
[email protected]:~# swapoff /mnt/sda1/swap/swapfile
[email protected]:~# free
              total        used        free      shared  buff/cache   available
Mem:         478396      128476       29080        1748      320840      336396
Swap:             0           0           0
[email protected]:~#

Comments

No comments yet. Why don’t you start the discussion?

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

45  ⁄  5  =