Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "swapon: swapfile has holes" error in Linux kernel 5.7 #436

Merged
merged 1 commit into from
Jul 8, 2020
Merged

Fix "swapon: swapfile has holes" error in Linux kernel 5.7 #436

merged 1 commit into from
Jul 8, 2020

Conversation

mnghsn
Copy link
Contributor

@mnghsn mnghsn commented Jul 8, 2020

When creating a swap file, dynamic space allocation such as using fallocate is not supported now.

swapon(8) says:

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 or on copy-on-write files on filesystems like Btrfs.

Commands like cp(1) or truncate(1) create files with holes. These files will be rejected by swapon.

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.

The most portable solution to create a swap file is to use dd(1) and /dev/zero.

This PR changes the way to create swap file from fallocate to dd.

References:

@helmuthdu helmuthdu merged commit 18ee6a5 into helmuthdu:master Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants