Expand swap partition or add swap

PmUserZFS

Well-Known Member
Feb 2, 2018
77
2
48
Im booting PM on zfs 2x400GB ssds.

got a swap partition /sda/zd96

~ swapon
NAME TYPE SIZE USED PRIO
/dev/zd96 partition 8G 2.8G -2



Disk /dev/zd96: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Im running into issues and Im gonna try and up the swap from 8GB to 16-32GB

I googled for some guides, but only found how to setup swap from scratch.

Anyy ideas?
 
You can use zfs set volsize= to resize a zvol (you might have to rerun mkswap). Or just zfs destroy the current swap zvol (be sure to pick the correct one!) and create a new swap zvol "from scratch". Make sure to do a swapoff -a in either case. I'd advice against using /dev/zd96 (is that actually in your /etc/fstab?) and use a human-readable/logical path instead such as /dev/zvol/rpool/swap.
 
Last edited:
  • Like
Reactions: PmUserZFS
I had to check, you are right it is not. it is:

~ cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/zvol/rpool/swap none swap sw 0 0
proc /proc proc defaults 0 0
#UUID=13312118216475446581 /data auto defaults 0 0
 
resize2fs didnt want to resize the partition.

~ resize2fs /dev/zd96
resize2fs 1.44.5 (15-Dec-2018)
resize2fs: Bad magic number in super-block while trying to open /dev/zd96
Couldn't find valid filesystem superblock.
 
resize2fs didnt want to resize the partition.

~ resize2fs /dev/zd96
resize2fs 1.44.5 (15-Dec-2018)
resize2fs: Bad magic number in super-block while trying to open /dev/zd96
Couldn't find valid filesystem superblock.
resize2fs is for ext2, ext3 and ext4 partitions and cannot be used on a ZFS zvol. For a zvol you change the volsize property using the zfs command and you pass it the ZFS path rpool/swap and not the zd device. If you are uncomfortable with resizing, please use zfs destroy rpool/swap (make sure you type it correctly) and create a new swap zvol as suggested in my first reply.
 
May I ask what the intention behind using swap is?
After a standard install I didn't have any swap space and from what I've read during the last months using swap with PVE is kind of discouraged.
Did you find any benefits with swap?
 
This is a homeserver for labbing.
My swap usage was full which casued issues, so I thought I ought to increase it. I only have 128GB, running eve-ng with 96GB then a handfull of small containers. Sometimes I spin up other labb VMs

Swap is currently used, can I just destroy it while VMs are running ?
 
I just restarted my labb VM

1620556569505.png
When I was running the labb VM swap was "red" 100% utilized.
 
Last edited:
From the PVE docs:

3.8.8. SWAP on ZFS​


Swap-space created on a zvol may generate some troubles, like blocking the server or generating a high IO load, often seen when starting a Backup to an external Storage.
If I overcommit the memory and need reliable swap, I always create real swap partitions on the host with mkswap, not on zfs.
 
Not ext3/4, swap has it's own partition type, so mkswap formats a dev with hex type 82 (LINUX_SWAP).
But your disk needs room for that swap partition (for example at the end of the drive).
If your drives are now fully partitioned for zfs, you probably need to make room for that swap partition. This is easier when installing PVE and specifying a smaller used size for zfs. The remaining free space could then be partitioned for swap.
If you want to keep the current system intact the easiest way is to add a fast small disk and format that as swap.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!