aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-09-11 18:53:28 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-09-11 18:53:28 +0200
commitde78630d8ac5a474768de7f6aaa1843b6195e04b (patch)
tree2b92c5d8bff5d86d76ec894fef37ba903144c91e
parent8de64474ded169db55cdd34be9c020ed13c4e5e7 (diff)
downloadnotes-de78630d8ac5a474768de7f6aaa1843b6195e04b.tar.gz
notes-de78630d8ac5a474768de7f6aaa1843b6195e04b.zip
linux: added swap notes
-rw-r--r--src/SUMMARY.md1
-rw-r--r--src/linux/README.md1
-rw-r--r--src/linux/swap.md50
3 files changed, 52 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md
index d48a4b4..fbe2102 100644
--- a/src/SUMMARY.md
+++ b/src/SUMMARY.md
@@ -55,6 +55,7 @@
- [coredump](./linux/coredump.md)
- [ptrace_scope](./linux/ptrace_scope.md)
- [cryptsetup](./linux/cryptsetup.md)
+ - [swap](./linux/swap.md)
- [Network](./network/README.md)
- [tcpdump](./network/tcpdump.md)
diff --git a/src/linux/README.md b/src/linux/README.md
index b21cc55..00e7e68 100644
--- a/src/linux/README.md
+++ b/src/linux/README.md
@@ -4,3 +4,4 @@
- [coredump](./coredump.md)
- [ptrace_scope](./ptrace_scope.md)
- [cryptsetup](./cryptsetup.md)
+- [swap](./swap.md)
diff --git a/src/linux/swap.md b/src/linux/swap.md
new file mode 100644
index 0000000..1a45883
--- /dev/null
+++ b/src/linux/swap.md
@@ -0,0 +1,50 @@
+# swap
+
+## List active swap areas
+
+```sh
+# procfs
+cat /proc/swaps
+
+# cli tool
+swapon --show
+```
+
+## Manual swapfile setup
+
+```sh
+# One time:
+# Create and initialize swapfile.
+# mkswap will initialize swap area over full filesize by default.
+sudo dd if=/dev/zero of=/swapfile bs=1G count=1
+mkswap /swapfile
+
+# Enable swap file (until next reboot).
+swapon /swapfile
+
+# Persistent setup of swap file.
+echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
+
+# Disable swap file (until next reboot).
+swapoff /swapfile
+```
+> Recommended file permissions `0600` and file owner `uid=0 (root)`.
+
+## Using `dphys-swapfile` service.
+
+Dynamically computes size of swap file based on installed RAM.
+
+```sh
+# Setup and enable swap based on /etc/dphys-swapfile.
+dphys-swapfile setup
+dphys-swapfile swapon
+
+# Disable swap on configured file.
+dphys-swapfile swapoff
+```
+
+> Usually comes with a script to be automatically run at system startup and shutdown.
+> For example as `systemd` service:
+> ```
+> systemctl status dphys-swapfile
+> ```