Swap on Linux will assist if your environment is running short on memory. Usually, during setup, most distributions configure a swap partition. When your Ram is a certain percentage used, the server will start to use the swap partition. SWAP can be of great benefit to users who run an NVMe dedicated server because it provides up to 30GB of additional memory you can use. In this article, we will deal with how to create a ZFS Swap Partition.
ZFS is a filesystem used in Cloud environments, it offers great performance and added benefits over other filesystems like LVM and LVM thin. If you are using Proxmox and installed from ISO to use ZFS then you would need to follow this guide to also enable swap.
Create ZFS Swap Partition
First, create a volume. This will hold the swap data. On most systems you won’t need a large amount of swap so, something like 8GB would be sufficient. We’re using 20GB here. If you need to use different compression, change the compression= statement. Also, rpool/swap is the location of your ZFS pool. If you’re using something different, modify the code. The default should be fine for most users.
zfs create -V 20G -b $(getconf PAGESIZE) -o compression=zle \ -o logbias=throughput -o sync=standard \ -o primarycache=metadata -o secondarycache=none \ -o com.sun:auto-snapshot=false rpool/swap
So now in the console, you will see the ZFS Swap Partition has been created.
Format Swap Partition
Using mkswap, now we format the drive. If you are using a different pool name, just like above, modify the location of the pool.
mkswap -f /dev/zvol/rpool/swap
Mount ZFS Swap Drive
Now, to ensure the drive is mounted on boot we add the following lines to the fstab. Again, if you are using a custom location for the ZFS pool, ensure you modify the code.
nano /etc/fstab /dev/zvol/rpool/swap none swap defaults 0 0
Finally, you can enable the swap. There is no need to reboot after completing this.
More from Dedicated Servers
Enable Mod_RemoteIP – See Visitors Real IP address when using Cloudflare & Apache
If you are using Cloudflare on your Apache server you will always see Cloudflare IPs in your logs and not …
Fix 413 Request Entity Too Large Errors When Using NGINX
Just like Apache, NGINX imposes default limits on the size of files that can be uploaded. A 413 Request Entity …
Cloud-init Modules That Automate and Customize Deployments
Cloud-init is a popular way to automate deployments of instances in a cloud or none cloud environment. To save having …