Created
January 18, 2022 16:06
-
-
Save AlexBaranowski/32e28b0a5ca8507bb7aea53e1f48d710 to your computer and use it in GitHub Desktop.
Simple script to check how many swaps can your Linux run.
This file contains hidden or 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 | |
# Author: Alex Baranowski | |
# License: MIT | |
# Max swap files tester | |
# magic number: 33 -> in theory 32 swap file on Linux can be used 33 = 32+1 | |
echo "Deactivating all swaps that are used" | |
sudo swapoff -a | |
echo "Creating and activating tmp swaps" | |
for i in {1..33}; do | |
SWAP_FILE="/swapfile-$i" | |
# status=none == silent dd | |
sudo dd status=none if=/dev/zero of=$SWAP_FILE bs=1M count=10 | |
sudo chmod 600 $SWAP_FILE | |
# make it silent | |
sudo mkswap $SWAP_FILE &> /dev/null | |
sudo swapon $SWAP_FILE &> /dev/null || break | |
done | |
NUMBER_OF_ACTIVE_SWAPS=$(swapon --noheadings | wc -l) | |
echo -e "\n\n System was able to use $NUMBER_OF_ACTIVE_SWAPS\n\n" | |
# Cleanup | |
echo "Deactivating temporary swaps" | |
sudo swapoff -a | |
echo "Removing temp swaps" | |
for i in {1..33}; do | |
SWAP_FILE="/swapfile-$i" | |
# make it silent | |
sudo rm "$SWAP_FILE" &>/dev/null || break | |
done | |
echo "Reactivating swaps (only from /etc/fstab && skipping 'noauto')" | |
sudo swapon -a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment