Resizing Solaris swap partition online

A quick and simple trick to resize a Solaris swap partition online.

In this example we will increase the swap partition from 2G to 5G (note our swap partition is under zfs control)

  1. Determine current swap
    # swap -lh
    swapfile                         dev     swaplo   blocks   free
    /dev/zvol/dsk/rpool/swap 124,2       4K          2.0G   2.0G
  2. Remove the current swap file:
    # swap -d /dev/zvol/disk/rpool/swap
  3. Increase the size of swap space
    # zfs set volsize=5G rpool/swap
  4. Finally, re-add the swap space:
    # swap -a /dev/zol/dsk/rpool/swap