Adding a SWAP device with ZFS as root filesystem

In the OpenSolaris environment ZFS can now be used as root filesystem.

To add a new SWAP device you need a block device.
ZFS supports the creation of block devices in a pool

zfs create -V 1G -b 8k rpool/swap


this command creates a "virtual" disk:

ewer@squeezy:~$ ls -l /dev/zvol/rdsk/rpool/
total 3
lrwxrwxrwx 1 root root 39 2009-04-11 13:51 dump -> ../../../../devices/pseudo/zfs@0:2c,raw
drwxr-xr-x 3 root root 3 2009-04-11 12:49 ROOT
lrwxrwxrwx 1 root root 39 2009-04-11 13:51 swap -> ../../../../devices/pseudo/zfs@0:1c,raw
ewer@squeezy:~$ ls -l /dev/zvol/dsk/rpool
total 3
lrwxrwxrwx 1 root root 35 2009-04-11 13:51 dump -> ../../../../devices/pseudo/zfs@0:2c
drwxr-xr-x 3 root root 3 2009-04-11 12:49 ROOT
lrwxrwxrwx 1 root root 35 2009-04-11 13:51 swap -> ../../../../devices/pseudo/zfs@0:1c


So you can used

swap -a /dev/zvol/dsk/rpool/swap


to add the new device as swap or add it in the /etc/vfstab:
/dev/zvol/dsk/rpool/swap - - swap - no


Because my system was already installed before ZFS could be used as a root
filesystem, I didn't have such a swap device.
I have also a real disk slice as swap:
ewer@squeezy:~$ swap -l
swapfile dev swaplo blocks free
/dev/dsk/c4d0s1 102,1 8 2096632 1764704
/dev/zvol/dsk/rpool/swap 182,1 8 2097144 1780768

Also a dump device can be created in the same way as above. Just do a

zfs create -V 2G -b 8k rpool/dump
ewer@squeezy:~$ pfexec dumpadm -d /dev/zvol/dsk/rpool/dump
Dump content: kernel pages
Dump device: /dev/zvol/dsk/rpool/dump (dedicated)
Savecore directory: /var/crash/squeezy
Savecore enabled: yes