Create a Swapfile on BTRFS

Note to self: If you create a swapfile on a BTRFS system, make sure you set the "no copy on write" file attribute. If you do not set this attribute, dd and fallocate will create files "with holes in it," which swapon will not accept.

This is how you create a swapfile on BTRFS:

  $ sudo touch swapfile
  $ sudo chmod 0600 swapfile
  $ sudo chattr +C swapfile
  $ sudo fallocate -l 2G swapfile
  $ sudo mkswap swapfile
  Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
  no label, UUID=e6d9da68-d5bb-4344-a3b4-84d979c80dc4
  $ sudo swapon swapfile

To check what is mounted as swap, you can enter the following:

  $ swapon
  NAME           TYPE SIZE  USED PRIO
  /swap/swapfile file   2G 90.8M   -2

Published: 2022-06-22

=> Back to Gemlog

Proxy Information
Original URL
gemini://tilde.pink/~tarial/gemlog/20220622_create_a_swapfile_on_btrfs.gmi
Status Code
Success (20)
Meta
text/gemini;
Capsule Response Time
20.782073 milliseconds
Gemini-to-HTML Time
0.269691 milliseconds

This content has been proxied by September (ba2dc).