Skip to content

Menu

  • Home
  • Sysadmin
  • Debian
  • Security
  • Docker

Blog by Constantin Herold | Theme by ThemeinProgress | Proudly powered by WordPress

Spaaacesysadmin & dev stuff

Create SWAP on ZFS ZVOL

February 23, 2021Debian, Proxmox, Sysadmin Standard
Read time < 1 minute

ZFS with it’s default options is not great for SWAP usage.

If you run “Root on ZFS” you want to create a ZVOL with the right options.

This means limiting arc to metadata, disabling l2arc, forcing sync writes, setting logbias to throughput and disabling autosnapshots.

Adjust 8G to the swap size you want. Adjust rpool if your pool has a different name.

zfs create -V 8G -b $(getconf PAGESIZE) -o compression=zle \
  -o primarycache=metadata -o secondarycache=none
  -o sync=always -o logbias=throughput \
  -o com.sun:auto-snapshot=false rpool/swap

Initiate SWAP on the ZVOL.

mkswap -f /dev/zvol/rpool/swap

Set SWAP to enable at boot.

cat << 'EOF' >> /etc/fstab
/dev/zvol/rpool/swap none swap defaults 0 0
EOF

Enable SWAP.

swapon -av

Comments

Nico April 3, 2021 at 19:43 - Reply

Why is ZFS (with default configs) not great for swap? Just curious

    Constantin April 4, 2021 at 00:41 - Reply

    ZFS makes heavy use of ram for caching, since swap is meant to flush ram to disk this fires back. ZFS would just load the swap back into ram (arc).

Write a Reply or Comment Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Create SWAP on ZFS ZVOL
  • Raspberry Pi Grafana Kiosk
  • Proxmox Grafana Dashboard
  • Proxmox Full Disk Encryption with SSH Remote Unlock
  • Login Mail Alert Using Rsyslog

Categories

  • Debian
  • Docker
  • Monitoring
  • Personal
  • Proxmox
  • Raspberry Pi
  • Security
  • Sysadmin