93 lines
3.4 KiB
Markdown
93 lines
3.4 KiB
Markdown
|
# SWAP Management
|
||
|
|
||
|
Two Bash scripts...
|
||
|
|
||
|
- one to add more SWAP without rebooting.
|
||
|
- one to remove unneeded SWAP without rebooting.
|
||
|
|
||
|
|
||
|
## addswap.sh
|
||
|
|
||
|
Usage:
|
||
|
|
||
|
### as root
|
||
|
|
||
|
```
|
||
|
./addswap.sh {size-in-gigaytes}
|
||
|
```
|
||
|
|
||
|
### with sudo
|
||
|
|
||
|
```
|
||
|
sudo ./addswap.sh {size-in-gigaytes}
|
||
|
```
|
||
|
|
||
|
{size-in-gigabytes} is optional. If you leave it out then the size will default to 4GB.
|
||
|
|
||
|
The script will quickly create a SWAP file, activate it and add it to /etc/fstab
|
||
|
|
||
|
## remswap.sh
|
||
|
|
||
|
Usage:
|
||
|
|
||
|
### as root
|
||
|
|
||
|
```
|
||
|
./remswap.sh {/swapfile.0xx}
|
||
|
```
|
||
|
|
||
|
### with sudo
|
||
|
|
||
|
```
|
||
|
sudo remswap.sh {/swapfile.0xx}
|
||
|
```
|
||
|
|
||
|
{/swapfile.0xx} is optional. The 0xx extension is a range of numbers from 001 to 024. If you leave it out then the last file in the sequence will be removed.
|
||
|
|
||
|
The script will quickly deactivate a SWAP file, removed it and remove it from /etc/fstab
|
||
|
|
||
|
## Notes:
|
||
|
|
||
|
It is important that you have addswap.sh and remswap.sh in the same folder and set the permissions to 700 and the owner and group to root. Do not try and run either script with out root or sudo privelages.
|
||
|
|
||
|
A log file can be found at /var/log/swapmanagement.log
|
||
|
|
||
|
## Why did I make these two scripts?
|
||
|
|
||
|
I use Debian as my daily driver (I've been using Linux in some for or the other as my daily driver since 2006). I also us Debian for all my servers. I also running a webhosting business (https://www.zaks.web.za) and in my 20+ years in the game, I have learned that... 1. VPS's do not come with SWAP, but sometimes you need a bit of SWAP to handle heavy load. 2. SWAP files can be added and removed on the fly (no reboot required), however a SWAP partition, not so simple.
|
||
|
|
||
|
On my daily driver machine, I also create a lot of digital artwork. I recently found myself rendering a finished artfile that was 9.5GB (24000px by 13700px) in Gimp, and half way through I started running out of RAM and SWAP. So I quickly created the needed SWAP file, and Gimp was able to finish the render without crashing.
|
||
|
|
||
|
## Plans for the future:
|
||
|
|
||
|
I am planning to make a configurable service file that can be run in the background to automatically create more SWAP files when your server/computer is under load, and remove excess SWAP files when the server/computer is no longer under load.
|
||
|
|
||
|
## Do you have a script idea?
|
||
|
|
||
|
If you have an idea for a useful server script for selfhost/homelab environments, please start a chat with me on Reddit /u/thisiszeev and share your idea. I might just make it a reality, and give you credit in the relevant README.md file.
|
||
|
|
||
|
# Donations
|
||
|
|
||
|
Please consider making me small donation. Even though my scripts are open source and free to use, I still need to eat. And the occasional bottle of wine also goes down well.
|
||
|
|
||
|
- $5 buys me a cup of coffee
|
||
|
- $10 buys me a nice burger
|
||
|
- $20 buys me a bottle of wine
|
||
|
- Anything above that will be awesome as well.
|
||
|
|
||
|
You can send me a donation via Paypal https://www.paypal.com/paypalme/thisiszeev
|
||
|
|
||
|
Drop me a message on Reddit if you do make a donation. u/thisiszeev
|
||
|
|
||
|
Support is only offered freely to those who donate $20 or more.
|
||
|
|
||
|
Your donation contributes to further development.
|
||
|
|
||
|
If you need a custom script, contact me on Reddit for pricing.
|
||
|
|
||
|
# Get notified when there are updates to this repo...
|
||
|
|
||
|
https://nca.zaks.web.za/index.php/apps/forms/s/8fDpCRzkKRMaBRakNtfyigcQ
|
||
|
|
||
|
Your email address will not be used for any other purpose than to be notifed, not more than once a week, of updates to this or any of the other repos I have on this server. You can also ask me to remove you from the list at anytime, and I will comply.
|