Add a swap file on Linux and Proxmox without shrinking LVM

Updated: 27 October 2026. This article replaces the old root-LVM shrinking procedure with an additional swap file. The earlier procedure included an incorrect assumption about shrinking XFS and should not be used as an operational guide.

When a suitable local filesystem has enough free space, a swap file can add swap capacity without resizing partitions. This example is for a Linux host, such as Proxmox VE, or an appropriately privileged Linux VM. In an LXC container, memory and swap limits are normally managed by the host administrator; establish that arrangement before attempting changes inside a container.

Will additional swap actually help?

Swap can provide headroom for temporary memory pressure. It does not replace RAM or fix a memory leak or an overloaded database. Sustained paging can make a system less responsive. Check process memory, swap activity and storage load first. On a virtualization host, include guest allocations in the assessment.

1. Check the filesystem, free space and existing swap

The following example creates a 4 GiB file named /swapfile-extra. That is an example size, not a universal recommendation. Leave headroom for the operating system, logs, updates and application data.

  • Local ext4 or modern XFS: confirm swap-file support for the actual system version and use a file without holes.
  • Btrfs: additional requirements apply, including copy-on-write handling. Use the filesystem-specific procedure.
  • ZFS, NFS or another storage arrangement: prepare a separate plan; do not assume any file can be used as swap.

2. Create and activate an additional file

Run the block as root in Bash after checking available space and allowing for disk activity. The guard stops if the path already exists. dd writes allocated data; do not substitute a sparse file created by truncate or a copy operation that preserves holes.

If swapon fails, stop and inspect its diagnostic message and kernel logs. Do not add a failing file to the boot configuration. This procedure does not require disabling existing swap first.

3. Enable the file after reboot

After confirming activation, back up /etc/fstab and add this entry once:

Use findmnt --verify --verbose to check the configuration syntax. That check alone does not prove successful activation at boot; confirm it during a planned restart.

4. Keep or replace the old swap LV?

The old swap area can remain active alongside the file. If you want to replace it, activate and check the new file first, then assess available memory before disabling the specific old area by its verified name. Avoid blanket swapoff -a on a busy host.

Removing an old LV and possibly expanding the root filesystem is a separate storage change requiring its own backup and recovery plan. Neither operation is needed merely to add the file. This guide does not issue LV deletion or root-shrinking commands.

Rollback and verification scope

Before disabling the new swap file, assess whether the system can safely release it. If it replaced an older swap area, arrange sufficient memory headroom and restoration of that area as necessary. Remove only the added fstab entry, then delete the file only after successful deactivation and confirmation with swapon --show.

For this revision, a swap signature was created and detected on a disposable 8 MiB file, and the Bash block was syntax-checked. Swap activation, fstab modifications and LVM operations were not performed on running servers. Test activation on the actual target filesystem in a non-production environment.

Reference: swapon: swap-file requirements and limitations. If memory pressure affects your service, describe the symptoms so the investigation can distinguish capacity, application and storage issues.