Create swap file in Ubuntu

Create a swap file to let OS use when the physical memory is not big enough. Make the swap file as 1~2x big as your physical memory.

CreateSwap.sh:

#!/usr/bin/env bash

fallocate -l 12G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfil…


This content originally appeared on DEV Community and was authored by Bo

Create a swap file to let OS use when the physical memory is not big enough. Make the swap file as 1~2x big as your physical memory.

CreateSwap.sh:

#!/usr/bin/env bash

fallocate -l 12G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

Then use swapon --show to check current swaps.

If your system already configured other swaps, you can use swapoff to remove it, for example:

swapoff /dev/sdb

Also remember to remove it in the /etc/fstab file such that it won't get used when system rebooted next time.

Reference


This content originally appeared on DEV Community and was authored by Bo


Print Share Comment Cite Upload Translate Updates
APA

Bo | Sciencx (2022-03-25T17:46:03+00:00) Create swap file in Ubuntu. Retrieved from https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/

MLA
" » Create swap file in Ubuntu." Bo | Sciencx - Friday March 25, 2022, https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/
HARVARD
Bo | Sciencx Friday March 25, 2022 » Create swap file in Ubuntu., viewed ,<https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/>
VANCOUVER
Bo | Sciencx - » Create swap file in Ubuntu. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/
CHICAGO
" » Create swap file in Ubuntu." Bo | Sciencx - Accessed . https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/
IEEE
" » Create swap file in Ubuntu." Bo | Sciencx [Online]. Available: https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/. [Accessed: ]
rf:citation
» Create swap file in Ubuntu | Bo | Sciencx | https://www.scien.cx/2022/03/25/create-swap-file-in-ubuntu/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.