-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
Title: Adding SWAP to a Debian Machine | ||
Description: Guide to remind myself how to add swap to Debian machines. | ||
Tags: | ||
- sysadmin | ||
|
||
--- | ||
|
||
So for SWAP, we usually have two choices. A swapfile, and a swap partition. | ||
|
||
A swapfile is a lot more flexible since it lives on your filesystem. However, it | ||
does have an added overhead of the filesystem. | ||
|
||
Another reason why you may want to use a swap partition is that in case you have | ||
more than one linux distro installed, they can share the same swap partition. | ||
|
||
People also [encrypts their swap | ||
partition](https://askubuntu.com/questions/313564/why-encrypt-the-swap-partition) | ||
|
||
1. First we create the swapfile with 4G \ | ||
`fallocate -l 4G /swapfile` | ||
|
||
2. Then, we set the correct permission for the swapfile \ | ||
`chmod 600 /swapfile` | ||
|
||
3. We now run this to setup the swapfile with the correct headers. \ | ||
`mkswap /swapfile` | ||
|
||
4. We will now run this to enable the swap partition, please note that this is a | ||
transient operation and will not persist if you reboot the system. \ | ||
`swapon /swapfile` | ||
|
||
5. Lastly, we will add the swapfile to our fstab so it will automatically enable | ||
the swapfile on boot. \ | ||
`echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab` | ||
|
||
There are also two sysctl options that you can tweak, either via the sysctl | ||
command (transient), or `/etc/sysctl.conf` (persistent). | ||
|
||
`vm.swappiness` \ | ||
`vm.vfs_cache_pressure` | ||
|
||
Further reading: [kernel Memory Management | ||
docs](https://docs.kernel.org/admin-guide/mm/index.html) | ||
|
||
Adapted from the [DigitalOcean SWAP space | ||
guide](https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04) |