Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Surprised if this works. Quoting swapon(8): "truncate(1) create files with holes. These files will be rejected by swapon." I normally use fallocate instead. However: "files created by fallocate(1) may be interpreted as files with holes too depending of the filesystem." Not sure what FSes that's referring to, but it's at least not a problem with ext4. Commented Sep 5, 2022 at 0:26
  • I'm fairly sure I've use truncate for swap files (and for VM image files) in the past, and it worked. On the rare occasion I need them, I use ZFS ZVOLs now. Using dd with reasonable parameters definitely works, so I'll just edit out the truncate stuff. Commented Sep 5, 2022 at 0:32
  • @JoL It is a problem for ext4, but it's mitigated if, for whatever reason, the filesystem is already on a loopback device (e.g. if you're using LVM or LUKS). The reason is that swapon will directly map the blocks as swap, completely bypassing the filesystem, so all the blocks must exist (this is what holes interferes with). If you're using a loopback device, then any access will necessarily not be "direct". Commented Sep 6, 2022 at 22:43