Change swap size in Ubuntu 18.04 or newer

https://bogdancornianu.com/change-swap-size-in-ubuntu/

Change swap size in Ubuntu 18.04 or newer


[Updated July 26, 2020]: Change swapfile permission; Set swapfile in /etc/fstab.

Swap is a special area on your computer, which the operating system can use as additional RAM.
Starting with Ubuntu 17.04, the swap partition was replaced by a swap file. The main advantage of the swap file is easy resizing.

Note: before running the following commands, please make sure you have a backup of your data!

In the following example, we’ll extend the swap space available in the /swapfile from 4 GB to 8 GB.

  1. Turn off all swap processes
1
sudo swapoff -a

2. Resize the swap

1
sudo dd if=/dev/zero of=/swapfile bs=1G count=8

if = input file
of = output file
bs = block size
count = multiplier of blocks

3. Change permission

1
sudo chmod 600 /swapfile

4. Make the file usable as swap

1
sudo mkswap /swapfile

5. Activate the swap file

1
sudo swapon /swapfile

6. Edit /etc/fstab and add the new swapfile if it isn’t already there

1
/swapfile none swap sw 0 0

7. Check the amount of swap available

1
grep SwapTotal /proc/meminfo

댓글

이 블로그의 인기 게시물

WSL2에서 X window를 세팅하는 법

[도서 목차]Do it! 프로그레시브 웹앱 만들기 반응형 웹 개발부터 하이브리드 앱 배포까지 PWA 완전 정복!

ARIMA or ARMA