Skip to content

Instantly share code, notes, and snippets.

@felegy
Created January 18, 2022 10:37
Show Gist options
  • Save felegy/6f87582ee5af5a09bf2a6a360ba441c1 to your computer and use it in GitHub Desktop.
Save felegy/6f87582ee5af5a09bf2a6a360ba441c1 to your computer and use it in GitHub Desktop.
#!/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