LoginSignup
5
6

More than 1 year has passed since last update.

ubuntuのswap sizeの変更

Last updated at Posted at 2021-08-22

注意

swapをssd上に作ると、寿命を摩耗します。
壊してもよいssdにするか、それとも、hddを使いましょう

現在のswapのサイズの確認

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        6.5G        2.7G         29M        6.4G        8.8G
Swap:          2.0G        565M        1.4G

$ sudo swapon --show
NAME      TYPE SIZE   USED PRIO
/swapfile file   2G 565.8M   -2

swapサイズの変更

$ sudo swapoff /swapfile
$ sudo fallocate -l 16G /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ sudo swapon -s
ファイル名             タイプ       サイズ   使用済み    優先順位
/swapfile                               file        16777212    0   -2
$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        7.6G        3.5G         67M        4.5G        7.6G
Swap:           15G          0B         15G

一時的なswapの追加

上は最初から作られていたswapfileなので、/etc/fstabで定常的に有効化されていますが、
一時的に追加する方法

$ sudo fallocate -l 16G /swapfile_tmp
$ sudo mkswap /swapfile_tmp
$ sudo swapon /swapfile_tmp
$ sudo swapon -s

再起動後に、swapon -sしても使われていないはずです。

恒久的に使いたくなったら

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdc1 during installation
UUID=mkswapしたときのuuid /               ext4    errors=remount-ro 0       1
/swapfile_tmp                                 none            swap    sw              0       0

のようにしてみてください

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6