Skip to content

Instantly share code, notes, and snippets.

@Benjamin-Wegener
Created November 8, 2025 08:51
Show Gist options
  • Select an option

  • Save Benjamin-Wegener/3a11e0ef10a077126f57702f3042f653 to your computer and use it in GitHub Desktop.

Select an option

Save Benjamin-Wegener/3a11e0ef10a077126f57702f3042f653 to your computer and use it in GitHub Desktop.
Fix BTRFS 'no space left' errors on Ubuntu when df shows available space
#!/bin/bash
#
# BTRFS "No Space Left" Fix for Ubuntu
# Fixes ENOSPC errors when df shows available space
# https://gist.github.com/your-username/gist-id
#
# Usage:
# chmod +x btrfs_fix_ubuntu_no_space.sh
# ./btrfs_fix_ubuntu_no_space.sh
#
set -e
echo "=== BTRFS No Space Left Fix ==="
echo ""
# Check if running on BTRFS
echo "1. Checking filesystem type..."
if ! command -v btrfs &> /dev/null; then
echo "ERROR: btrfs command not found. This script is for BTRFS filesystems only."
exit 1
fi
echo ""
echo "2. Current BTRFS filesystem usage:"
sudo btrfs filesystem usage /
echo ""
echo "3. Running BTRFS balance to reclaim metadata space..."
echo " This may take 2-5 minutes..."
# Balance data chunks with low usage
sudo btrfs balance start -dusage=5 /
# Balance metadata chunks with low usage
sudo btrfs balance start -musage=5 /
echo ""
echo "4. Balance complete. Checking disk space:"
df -h /
echo ""
echo "=== Fix Complete ==="
echo "If you still get ENOSPC errors, run with higher usage values:"
echo " sudo btrfs balance start -dusage=20 /"
echo " sudo btrfs balance start -musage=20 /"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment