summaryrefslogtreecommitdiffstats
path: root/content/posts/swap-file-linux.md
diff options
context:
space:
mode:
authorbreadcat2020-06-19 12:23:15 +0100
committerbreadcat2020-06-19 12:23:15 +0100
commit70bb5d5a801428b0fb390abf79f19ffcf5e29c67 (patch)
treeb9fd7990156bd58bc38d58f91829c05933215102 /content/posts/swap-file-linux.md
parent0f9a31348079c0a061bcc194912e75cc1c07bc1f (diff)
downloadblog.minskio.co.uk-70bb5d5a801428b0fb390abf79f19ffcf5e29c67.tar.gz
blog.minskio.co.uk-70bb5d5a801428b0fb390abf79f19ffcf5e29c67.tar.bz2
blog.minskio.co.uk-70bb5d5a801428b0fb390abf79f19ffcf5e29c67.zip
Simple migration of existing posts to hugo format
Diffstat (limited to 'content/posts/swap-file-linux.md')
-rw-r--r--content/posts/swap-file-linux.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/content/posts/swap-file-linux.md b/content/posts/swap-file-linux.md
new file mode 100644
index 0000000..1396adb
--- /dev/null
+++ b/content/posts/swap-file-linux.md
@@ -0,0 +1,39 @@
+---
+title: "Creating a Swap File on Linux"
+date: 2019-06-10T10:03:00
+tags: ["formats", "guides", "linux", "servers", "snippets", "software"]
+---
+
+I've recently moved from a server with more than enough RAM, to a lower spec (and significantly cheaper!) VPS that still does 99% of what I want it to.
+
+The issue however is that with the reduced RAM there's a very real possibility of running out and locking up the system. The easy (and cheap) solution is to add a swap file instead of repartitioning my disk space.
+
+The notes here work with a 1GB swap file, but feel free to change these if need be.
+
+Firstly we're going to create the file, set permissions and enable the swap file:
+```
+sudo fallocate -l 1G /swap
+sudo chmod 600 /swap
+sudo mkswap /swap
+sudo swapon /swap
+```
+
+This can then be mounted on boot by editing your `/etc/fstab` file and adding the following line:
+```
+/swap swap swap defaults 0 0
+```
+
+Now you can check this swap space is working by:
+```
+sudo swapon --show
+```
+
+Now the swap file is up and running, you can decide if you want to alter the *[swappiness](https://en.wikipedia.org/wiki/Paging#Swappiness)* value on your system which dictates how the file should be used. The default value on my system was `60`, but I've altered it to `10` using the below commands:
+```
+cat /proc/sys/vm/swappiness
+sudo sysctl vm.swappiness=10
+```
+To make this change permanent, you'll need to write the value to your `sysctl.conf` file via:
+```
+echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
+```