HOWTO use a zvol as a swap device - atomjack/zfs GitHub Wiki

Current ZoL releases support swapping to a zvol.

Step 1: Create a zvol for use as a swap device.

# zfs create -V 4G -b $(getconf PAGESIZE) \
      -o sync=always -o primarycache=metadata \
      -o com.sun:auto-snapshot=false \
      rpool/swap

You can adjust the size (the 4G part) to your liking.

Step 2: Format the swap device.

# mkswap -f /dev/zvol/rpool/swap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=...

Step 3: Update the /etc/fstab file.

# /etc/fstab: static file system information.
# <file system>  <mount point>  <type>  <options>  <dump>  <pass>
/dev/zvol/rpool/swap  none  swap  defaults  0  0

Remember: Always use long /dev/zvol aliases in configuration files. Never use a short /dev/zdX device name.

Step 4: Enable the swap device.

# swapon --all --verbose
swapon on /dev/zd0
swapon: /dev/zd0: found swap signature: version 1: page-size 4, same byte order
swapon: /dev/zd0: pagesize=4096, swapsize=4294967296, devsize=4294967296
⚠️ **GitHub.com Fallback** ⚠️