joshtronic

in Linux #Arch Linux

swapon: swapfile has holes

While I do absolutely adore Arch Linux, it wouldn't be Arch without running an upgrade and having a problem crop up out of no where.

This time around, the issue showed up after a reboot when I saw the following error scroll past before I was presented with the GNOME login screen:

swapon: swapfile has holes

Holes? Like the critically acclaimed kids drama starring America's sweetheart Shia LaBeouf?

Not quite.

Turns out whatever had recently been updated had decided that a swapfile that was created with fallocate was deemed unsuitable for use and thus, has "holes".

So what's the fix? Easy enough, you just need to re-create your swapfile using dd instead of fallocate:

# Turn off and remove your existing swapfile:
swapoff /swapfile
rm /swapfile

# Make a new swapfile with dd (adjust the count to fit your needs): dd if=/dev/zero of=/swapfile bs=1M count=32768 status=progress

# Set the right permissions and make it so: chmod 600 /swapfile mkswap /swapfile swapon /swapfile

Note: Those commands aren't Arch specific, they should work on other Linux distributions as well.

Assuming everything is already setup in your fstab from your hole-filled swapfile and you used the same name and location, you should be off to the races.

To double check things, you can run swapon --show which should show your swapfile listed.

If you happen to use your swapfile for hibernation the way I do, you will need to tweak a few additional things to get the new offset value for your swapfile. Fortunately, I've already outlined these steps in another post.