Last active
December 27, 2016 23:09
-
-
Save audacioustux/8b2ceb6d60d011329296697eac9c692f to your computer and use it in GitHub Desktop.
make swapfile easily with this simple script
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
#!/bin/sh | |
MEMSIZE=$(free -m | awk 'NR==2{print $2}') | |
if [ $MEMSIZE -gt 4096 ]; then | |
RECMEMSIZE=$MEMSIZE | |
else | |
RECMEMSIZE=$(($MEMSIZE*2)) | |
fi | |
echo "enabling all swap partitions & files" | |
swapon -a | |
SWAPSIZE=$(free -m | awk 'NR==3{print $2}') | |
if [ $SWAPSIZE != 0 ]; then | |
echo "You already have "$SWAPSIZE"mb swap memory." | |
fi | |
while true; do | |
read -p "I'll create "$RECMEMSIZE"mb swapfile in root directory. DO U ACCEPT? (y/n)?" choice | |
case $choice in | |
[Yy]* ) echo "dd..."; dd if=/dev/zero of=/swapfile bs=512 count=$(($RECMEMSIZE*1024)); chown root:root /swapfile; chmod 0600 /swapfile; echo "mkswap..."; mkswap /swapfile; swapon /swapfile; echo "/swapfile none swap sw 0 0" >> /etc/fstab; break;; | |
[Nn]* ) echo "U JUST WASTED MY TIME BRO :/"; exit;; | |
* ) echo "say yes(y) or no(n).";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment