Linuxのスワップファイルを作成する

スワップファイルのPath: /swapfile
サイズ: 4GB

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

$ ls -l /swapfile 
-rw-r--r-- 1 root root 4294967296  1月 12 11:42 /swapfile

$ sudo chmod 600 /swapfile 

$ ls -l /swapfile 
-rw------- 1 root root 4294967296  1月 12 11:42 /swapfile

$ sudo mkswap /swapfile 

$ free
               total        used        free      shared  buff/cache   available
Mem:         3956396      974904      262152       58020     2719340     2646612
Swap:              0           0           0

$ sudo swapon /swapfile

$ free
               total        used        free      shared  buff/cache   available
Mem:         3956396      983132      252472       56516     2720792     2639888
Swap:        4194300           0     4194300

$ sudo vi /etc/fstab

$ cat /etc/fstab
(省略)
/swapfile       none    swap    defaults        0       0