Created
January 18, 2022 10:37
-
-
Save felegy/6f87582ee5af5a09bf2a6a360ba441c1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
SWAP_SIZE=${SWAP_SIZE-"4G"} | |
SWAP_FILE=${SWAP_FILE-"/swap"} | |
fallocate -l "$SWAP_SIZE" "$SWAP_FILE" | |
chmod 600 "$SWAP_FILE" | |
mkswap "$SWAP_FILE" | |
swapon "$SWAP_FILE" | |
echo "$SWAP_FILE swap swap defaults 0 0" >>/etc/fstab | |
swapon --show | |
grub_file=$(sed "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"/" /etc/default/grub) | |
echo "$grub_file" >/etc/default/grub | |
update-grub 2> /dev/stdout | |
echo 'vm.swappiness=10' >> /etc/sysctl.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment