Created
September 18, 2025 03:33
-
-
Save felipealfonsog/dfd98ab42a307f8485b719365ee7f34f to your computer and use it in GitHub Desktop.
Fix Zram disabled and swapfile configured
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
| #!/bin/bash | |
| set -e | |
| echo "ð§ Disabling zram swap..." | |
| # 1. Turn off zram if active | |
| if swapon --summary | grep -q zram0; then | |
| echo "ð Turning off /dev/zram0 swap..." | |
| sudo swapoff /dev/zram0 || echo "â ï¸ Failed to swapoff /dev/zram0" | |
| fi | |
| # 2. Disable the systemd zram setup service | |
| if systemctl list-units --type=service | grep -q "[email protected]"; then | |
| echo "ð« Disabling [email protected]..." | |
| sudo systemctl disable [email protected] || true | |
| fi | |
| # 3. Remove zram-generator config if exists | |
| if [ -f /etc/systemd/zram-generator.conf ]; then | |
| echo "ð§¹ Removing zram-generator configuration..." | |
| sudo rm -f /etc/systemd/zram-generator.conf | |
| fi | |
| # 4. Ensure /swapfile is in use and configured | |
| if [ ! -f /swapfile ]; then | |
| echo "ð¦ Creating 8G /swapfile..." | |
| sudo fallocate -l 8G /swapfile | |
| sudo chmod 600 /swapfile | |
| sudo mkswap /swapfile | |
| sudo swapon /swapfile | |
| else | |
| echo "ð¦ /swapfile already exists." | |
| sudo swapon /swapfile || echo "â ï¸ Swapfile already active or failed to enable" | |
| fi | |
| # 5. Add /swapfile to /etc/fstab if not present | |
| if ! grep -q "/swapfile" /etc/fstab; then | |
| echo "âï¸ Adding /swapfile to /etc/fstab..." | |
| echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab | |
| fi | |
| echo "â Zram disabled and swapfile configured." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment