How to create a SWAP partiton?

Platform: ElectricEel-

Hi all, 24.10.0.2

This is my first post as a user of TrueNAS so if it is incomplete please do not roast me :smile:
I am using TrueNAS SCALE 24.10.0.2 as mentioned above and I could understand that the swap space/partition is not created during the initial setup anymore (due to some bug or issue that it created it seems).
I could find some tutorials that apply to Linux in general but nothing that applies to TrueNAS Scale specifically.

Thanks for any guidance here!

The answer, really, is that you don’t need to, and the system won’t use it even if you do.

Hi @dan,

Thanks for the quick reply.
I am a bit short on RAM and I could understand that the Swap would help.
I am using Photoprism as a Docker app.

I have already ordered some RAM but in the meantime, I would like my failing indexing jobs to succeed.
Is my plan going to fail anyways?

Probably, but you could try. I’d suggest a swap file rather than partition, as any changes are easily reversible. To create one, change to whatever directory you want it to live in (hopefully on a SSD pool) and run (as root) truncate -s 16G swapfile (substituting 16G with whatever size you want to make it), followed by mkswap swapfile and then swapon swapfile. You can confirm your system has it available by running free.

The system will stop using the swapfile when you reboot, so if you want to reenable it, you’d run swapon /path/to/swapfile. If you find it isn’t helping, you can disable it with swapoff /path/to/swapfile, and then remove the file with rm /path/to/swapfile.

2 Likes

Thanks for the guidance and tips!
I will try to apply the instructions and let you know if this solved my issue :slightly_smiling_face:

@isso_me Issam:

The chances are that if your system is so low in memory that you think it needs swap, then there will be no memory for ZFS ARC and you will have poor performance at best and an unstable system at worst.

TrueNAS (and ZFS-based systems) need some spare memory for use as a cache, and ZFS gives up that memory when programs needed. So if you get to the point that there is no ARC for ZFS to give up and to free more memory you need to swap, then you probably have simply too little memory to run TrueNAS.

So although you have asked us about swap, actually you might be better off giving us your configuration (MB, CPU, memory, storage controllers, disks) and allow us to advise you on the good and bad points, what you can do with what you have and what your best upgrade options might be.