Skip to content

Instantly share code, notes, and snippets.

@earendildev
Last active June 10, 2022 09:59
Show Gist options
  • Save earendildev/727016da258bd110393c8ba50d0a1253 to your computer and use it in GitHub Desktop.
Save earendildev/727016da258bd110393c8ba50d0a1253 to your computer and use it in GitHub Desktop.
Creating a SWAP partition and viewing free space
#!/bin/sh
#########################################################
# To Download and Install/Run
# $ sudo -H su -c "$(curl -fsSL https://gist.githubusercontent.com/earendildev/727016da258bd110393c8ba50d0a1253/raw --output $HOME/create-swap.sh)"
# Created by [email protected]
#########################################################
# List Current Swap Space
swapon --show
printf 'Your Current SWAP Space'
free -h
# Current File System Space
printf 'Checking Current File System Space'
df -h
# Create SWAP
printf 'Creating about 4GB of SWAP'
fallocate -l 4G /swapfile
# Check if it correct
ls -lh /swapfile
printf 'Just checking'
# Grant Permissions to SWAP
printf 'Granting Permissions to the newly created SWAP file'
chmod 600 /swapfile
# Mark file as SWAP
mkswap /swapfile
# Enable SWAP
printf 'Enabling SWAP'
swapon /swapfile
# Verfiy new SWAP - Check memory
printf '\n Verifying the newly created SWAP \n'
swapon --show
printf '\n Show Memory \n'
free -h
printf '\n Perfect.'
# Making SWAP permanent
printf '\n Now lets make the SWAP file permanent'
cp /etc/fstab /etc/fstab.bak
printf '/swapfile none swap sw 0 0' | tee -a /etc/fstab
printf '\n DONE.'
printf '\n Deleting File'
rm $HOME/create-swap.sh
# Exit with Success Code
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment