mirror of
https://github.com/darksaid98/ubuntu-server-setup.git
synced 2026-12-01 14:38:58 +00:00
Added function to add swap file
This commit is contained in:
1 parent
9ef673594e
commit
02e48fe201
2 files changed
+42
-3
No files matched your search
@@ -39,4 +39,27 @@ function changeSSHConfig() {
|
||||
function setupUfw() {
|
||||
sudo ufw allow OpenSSH
|
||||
yes y | sudo ufw enable
|
||||
}
|
||||
|
||||
function createSwap() {
|
||||
local swapmem=$(($(getPhysicalMemory) * 2))
|
||||
|
||||
# Anything over 4GB in swap is probably unnecessary as a RAM fallback
|
||||
if [[ ${swapmem} > 4 ]]; then
|
||||
phymem=4
|
||||
fi
|
||||
|
||||
sudo fallocate -l ${swapmem}G /swapfile
|
||||
sudo chmod 600 /swapfile
|
||||
sudo mkswap /swapfile
|
||||
sudo swapon /swapfile
|
||||
}
|
||||
|
||||
function getPhysicalMemory() {
|
||||
local phymem=$(free -g|awk '/^Mem:/{print $2}')
|
||||
if [[ ${phymem} == '0' ]]; then
|
||||
echo 1
|
||||
else
|
||||
echo ${phymem}
|
||||
fi
|
||||
}
|
||||
Reference in new issue
Block a user