Last active
March 17, 2021 14:35
-
-
Save raykao/6942031 to your computer and use it in GitHub Desktop.
How to create a swap file on ubuntu 12.04. Summary from: [Digital Ocean](https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Summary from: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04 | |
# 1. Check if swap exists returns single line output if swap doesn't exist | |
$ sudo swapon -s | |
Filename Type Size Used Priority | |
# 2. Check disk space on root (/) with DF command: | |
$ df | |
Filesystem 1K-blocks Used Available Use% Mounted on | |
/dev/sda 20907056 1437188 18421292 8% / | |
udev 121588 4 121584 1% /dev | |
tmpfs 49752 208 49544 1% /run | |
none 5120 0 5120 0% /run/lock | |
none 124372 0 124372 0% /run/shm | |
# 3. Create and enable Swap | |
$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k | |
$ sudo mkswap /swapfile | |
$ sudo swapon /swapfile | |
# 4. Open file | |
$ sudo nano /etc/fstab | |
# 5. Paste/Append: | |
/swapfile none swap sw 0 0 | |
# 6. Configure Swapfile to be used for emergency buffer, prevening out-of-memory crashes | |
$ sudo su - | |
$ echo 0 > /proc/sys/vm/swappiness | |
$ exit | |
#7. Setup proper file permissions | |
$ sudo chown root:root /swapfile | |
$ sudo chmod 0600 /swapfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment