FS#66921 - [linux] "Swapfile has holes" on Linux 5.7
Attached to Project:
Arch Linux
Opened by Alan Orth (stickyboy) - Saturday, 06 June 2020, 16:59 GMT
Last edited by Tobias Powalowski (tpowa) - Saturday, 02 April 2022, 20:11 GMT
Opened by Alan Orth (stickyboy) - Saturday, 06 June 2020, 16:59 GMT
Last edited by Tobias Powalowski (tpowa) - Saturday, 02 April 2022, 20:11 GMT
|
Details
Description:
Upgrading my system from core/linux 5.6.15.arch1-1 to testing/linux 5.7.arch1-1 and my swapfile doesn't work. At boot systemd shows this message during startup: Jun 06 19:47:05 laptop kernel: swapon: swapfile has holes If I reboot back into Linux 5.6 the swapfile works. Additional info: * 5.7.arch1-1 * Swapfile on ext4 * LVM+LUKS |
This task depends upon
https://bugzilla.kernel.org/show_bug.cgi?id=207585
Just updated to 5.7.2 from core, rebooted and saw error messages on boot:
`[FAILED] Failed to activate swap /swap.`
`[DEPEND] Dependency failed for Swap.`
And another message in the log after logging in:
`swapon: swapfile has holes`.
I'm pretty certain there are no holes in my swap file. I reformatted my swapfile just to make sure.
Swapfile on ext4 SSD LVM (unencrypted).
"Note: dynamic space allocation such as using fallocate is not supported, as it causes problems with some file systems such as F2FS[1] and will likely fail to activate at boot time with error "swapon: swapfile has holes" as of kernel 5.7. Hence, contiguous allocation, such as dd, is the only reliable way to allocate a swap file.[2]"
Commands to create/recreate the swapfile with root privileges:
rm /swapfile #deletes old swapfile
# 2GB swapfile in MiB
dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile # enables the swapfile right now
echo '/swapfile none swap defaults 0 0' | tee --append /etc/fstab # configs the swapfile in startup
But now on one of my server after upgrading 5.7, I get same error that "swapfile has holes".
man for "swapon" does not mention ext4 having any issue. And also kernel bug report says it was regression error introduced in 5.7. So it is likely a kernel bug and not ext4/swapon incompatibility.
I am wondering if I should go ahead and re-create /swapfile on all servers using dd? (which will need a downtime which I am trying to avoid)
OR
I should wait for kernel fix? (if it is really the fix)
Thank you.
(This is to be done before kernel upgrade and reboot. This will make sure that swap setup will not fail after reboot)
(If you have already upgraded and rebooted i.e. swap setup has already failed then @navarroaxel method above is enough)
# STEP 1:
# create new temporary swap file with same size as existing one (e.g. 4GB)
dd if=/dev/zero of=/swapfilenew bs=1M count=4096 status=progress
chmod 600 /swapfilenew && mkswap /swapfilenew && swapon /swapfilenew
# STEP 2:
# turn off existing swapfile
# this will take a while as existing swap data will be migrated to physical RAM and/or new swap file
swapoff /swapfile
# STEP 3:
# re-create /swapfile
rm /swapfile && dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
# STEP 4:
# transfer the swap data back, if necessary and remove temporary swap file
swapoff /swapfilenew && rm /swapfilenew
Note:
You may be able to directly rename (mv) /swapfilenew to /swapfile after STEP 2 and in that case STEP 3 and STEP 4 are not required. But I am sure if renaming a swap file while it is still in use can cause any problem or not.