Skip to content

Instantly share code, notes, and snippets.

@felipealfonsog
Created September 18, 2025 03:33
Show Gist options
  • Save felipealfonsog/dfd98ab42a307f8485b719365ee7f34f to your computer and use it in GitHub Desktop.
Save felipealfonsog/dfd98ab42a307f8485b719365ee7f34f to your computer and use it in GitHub Desktop.
Fix Zram disabled and swapfile configured
#!/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