I have recently installed Ubuntu 20.04 with ZFS as the file system. I check my RAM / swap and it is as follows:

qallaf89@desktop:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           31Gi        22Gi       4.1Gi       1.9Gi       4.2Gi       6.0Gi
Swap:         2.0Gi          0B       2.0Gi

Now if I want to increase my swap space normally I follow this tutorial from digital ocean and it works perfectly. However, since I have ZFS I am having some issues:

qallaf89@desktop:~$ sudo fallocate -l 100G /swapfile
fallocate: fallocate failed: Operation not supported

I looked around and indeed there seems to be a problem with ZFS / fallocate().

I also came across this documentation from oracle but it is of no use to me as well:

qallaf89@desktop:~$ swap -l

Command 'swap' not found, did you mean:

  command 'stap' from deb systemtap (4.2-3)
  command 'szap' from deb dvb-apps (1.1.1+rev1500-1.2)
  command 'soap' from deb soapaligner (2.20-3)
  command 'sway' from deb sway (1.4-2)
  command 'smap' from deb slurm-client (19.05.5-1)
  command 'sswap' from deb secure-delete (3.1-6ubuntu2)
  command 'snap' from deb snapd (2.44.3+20.04)
  command 'swarp' from deb suckless-tools (44-1)
  command 'swab' from deb odin (2.0.3-2build1)

Try: sudo apt install <deb name>

qallaf89@desktop:~$ sudo apt show swap
N: Unable to locate package swap
N: Unable to locate package swap
E: No packages found

Could someone with knowledge on the matter please help me increase my swap space?


3 Answers 3


This from the ArchWiki https://wiki.archlinux.org/index.php/ZFS#Swap_volume:

  1. What do 'getconf PAGESIZE', ie the memory system's preferred memory page size ?
  2. create a zfs volume for swap
  3. prepare as swap
  4. start the swap
  5. mark it up as swap in etc/fstab (it is entirely possible that that is done automatically due to zfs properties.)


zfs create -V 8G -b $(getconf PAGESIZE) \
          -o logbias=throughput -o sync=always\
          -o primarycache=metadata \
          -o com.sun:auto-snapshot=false rpool/swap
mkswap -f /dev/zvol/rpool/swap
swapon /dev/zvol/rpool/swap

I'm unsure about that logbias=thr.., primarycache=meta and '-o com.sun...' will do in your case, especially as the disk itself is an SSD. Either way, this will create a 8GB large zfs volume.

in etc/fstab:

/dev/zvol/rpool/swap none swap discard 0 0

With regards to ZFS: you should think and look for more disks, to gain availability for the setup, you need to think about how to add mirroring. If you loose the 1TB samsung ssd, the whole pool is toast.

With regards to sda5: The zpool administration section in FreeBSD's manual describes how to change an vdev into a mirroring pair.

In this case:

  1. swapoff sda5
  2. eventually clear the lable
  3. reattach the vdev
  4. wait for the resilver
  5. add boot program


swapoff /dev/sda5
zpool attach bpool sda5 sda6

And wait for the resilver.

  • I know I'm not using it properly at the moment, this is the first time. I need to gain more experience with it in order to benefit from its potential. Jun 20, 2020 at 12:00
  • I followed the steps and everything seems good (dropbox.com/s/a15ue8ewvnmcxze/…). But what about the old 2 GB partition, can I swapoff then delete or should I just keep it? Jun 20, 2020 at 12:00
  • 1
    dev/sda5 ? You could test adding it to bpool ie turn bpool's vdev into a mirroring configuration. The other disk's in the system, can you scrunge a 2 GiB partition somewhere there (preferably so that the vdev itself gets 3 partions.) Jun 20, 2020 at 12:11
  • 1
    The FreeBSD handbook says a fair freebsd.org/doc/handbook/zfs-zpool.html Jun 20, 2020 at 12:18
  • 2
    Instead of "sync=always" better use "sync=standard" because there is an unsolved bug that causes hangs on swap zvols!
    – PePa
    Nov 16, 2020 at 15:31

I haven't tried it on a ZFS file system but on numerous others like ext3, ext3,ext4, XFS. Boot from a live USB stick, choose "Try Ubuntu without installing" and once up and running use gparted to resize partitions. You need to shrink one in order to free up space enough to enlarge the swap partition. This guide is quite helpful, scroll down to "Using GParted". If you need a more comprehensive manual to gparted you find one here. Scroll down to "Resizing a Partition"

  • Looks kind of risky with ZFS, will try it as a last resort. Jun 20, 2020 at 10:42
  • sda7, the zfs pool partition needs to be moved in that case - i don't trust gparted to do that correctly. Jun 20, 2020 at 11:44

I have previously used the systemd-swap package with some success (on arch only so far) - this can dynamically allocate swap files inside a directory as and when needed, so you don't need to reserve a large ZVOL inside your pool that will eat away at available space. I'm not sure how it does performance-wise, someone else could possibly provide more info than I could here, however, I've created a new filesystem and set the com.sun:auto-snapshot property to false as in the above - this prevents some utilities from creating snapshots, but only today I've realised that I still have snapshots from manual creation using snapshot -r, so I shall be looking for a better way to do this shortly! However in general you'll want to prevent any snapshot creation for this dataset, and tune it according to your scenario for speed and space tradeoff, if relevant. You'll then want to point the systemd-swap config file towards the mountpoint for this dataset.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .