Linux swapon Failed: Invalid Argument on Btrfs/XFS Swapfile
Swapfile has holes, compression, or Copy-on-Write enabled.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Linux swapon Failed
Platform: Linux
Common Root Causes:
- Swapfile has holes, compression, or Copy-on-Write enabled.
Interactive Diagnostic Checklist
Verified Solutions:
- Disable CoW (`chattr +C`), allocate contiguously with `dd`, `chmod 600`, then `mkswap`.
Safe Diagnostic Command:
lsattr /swapfile
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Swapfile has holes, compression, or Copy-on-Write enabled. Recommended diagnostic: `lsattr /swapfile`. Remediation: Disable CoW (`chattr +C`), allocate contiguously with `dd`, `chmod 600`, then `mkswap`.
Worked Examples
- Run `lsattr /swapfile` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-linux-swapon-fallocate-btrfs · Independently verified: 2026-11-25