18 lines
415 B
Bash
Executable File
18 lines
415 B
Bash
Executable File
#!/bin/sh
|
|
[ -e /swap ] && {
|
|
# for saftey
|
|
swapoff /swap
|
|
rm /swap
|
|
sed -Ei '/\/swap\s*/d' /etc/fstab
|
|
}
|
|
|
|
touch /swap
|
|
size="$(( "$(free -g | awk '/Mem:/ {print $2}')" + 1 ))k"
|
|
dd if=/dev/zero of=/swap bs=1M count="$size" status=progress
|
|
chmod 0600 /swap
|
|
mkswap -U clear /swap
|
|
swapon /swap
|
|
echo '' >> /etc/fstab
|
|
echo '/swap none swap defaults 0 0' >> /etc/fstab
|
|
echo "Created $(echo $size | tr -d 'k') Gb swap file"
|