HomePhorge
Adding swap to a ZFS root system

I'm running Ubuntu on ZFS which I set up using instructions found on the ZFS on Linux site.

I've found that some of my recent activities have been very memory intensive and I quickly run out of memory and swap space, so I decided I would create a new swap file and activate it. The instructions on the Ubuntu website are fine, however they don't account for the file system not supporting swap (which ZFS doesn't on the filesytem) when trying to follow those commands.

Instructions on the Oracle website here and more detailed instructions about swap and dump devices here explain how to create and resize swap devices. The problem is that these instructions are for Oracle Solaris and the commands aren't all available on Ubuntu.

WARNING: Make sure you read the documentation before issuing these commands so you understand what you are doing. But the following should help you add a swap device set up on a ZFS native system.
sudo zfs create poolname/swap -V 2G -b 4K
sudo mkswap -f /dev/zvol/poolname/swap
sudo swapon /dev/zvol/poolname/swap

Obviously, change poolname to match your pool name, you can name swap to something else if you like as well, e.g. myswap. You can create multiple swap files in this way.

Add the entry to your fstab file:

/dev/zvol/poolname/swap  none  swap  sw  0 0
Written by 0xseantasker on Jun 22 2017, 12:01 AM.
User
Projects
None
Subscribers
None

Event Timeline