- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
- swapon fails with error “swapon failed: Invalid argument” if swap file created using fallocate
There are 3 resolutions :
- Create the swap file with dd instead of fallocate if using XFS on RHEL6 or RHEL7.
- Create the swap file on ext filesystem if using RHEL6 or RHEL7.
- Can upgrade to RHEL8 as issue is fixed for XFS.
The swap file implementation in the kernel expects to be able to write to the file directly, without the assistance of the filesystem. This is a problem on files with holes. Commands like cp(1) or truncate(1) create files with holes. These files will be rejected by
Preallocated files created by
fallocate(1) may be interpreted as files with holes too depending of the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.
- Try to create the file with fallocate.
- Make the swap on above file.
[roo[email protected] ~]# mkswap /swap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=a830901f-613d-4ed9-bb89-f076eb6d94f7
- Change permission to 600 for swap file.
- Enable the swap to see error.