Correct way to create swap on an empty device?

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
Can someone explain the correct way to create and enable swap space on my FreeNAS 11.3 box?

I've added a new empty disk, currently assigned ada4.

What do I do now? I haven't done this before so I really need it step by step.

Especially I'm concerned because I routinely add and remove disks. So if I manually add a static line to fstab, referrencing ada4, won't it end up pointing to the wrong device, maybe part of my pool, some time when I reboot? Or will my manual entry conflict/be overwritten by the FreeNAS code, which presumably expects to manage fstab itself? So I'm looking for a way to say, in the GUI, "Use this device/partition as swap". But I can't figure it out, and don't have a clue what to do now.

Help please! Thanks!
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
The right way to handle swap space in FreeNAS is ... not to.

FreeNAS creates swap space on drives added to a pool, but that's intended as a "buffer" when replacing the drive, in case the replacement drive is a hair smaller.

If you are actually using swap, something's very off. You have plenty of RAM, I don't expect you'll never even got close to that hypothetical disaster.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
System->Advanced has a setting for the size of the swap partition to create on new disks. On insertion, FreeNAS will automatically GPT partition a new disk, with the first partition being a swap partition, and the second partition being an empty ZFS data partition, suitable for addition to a pool.

You can check this yourself after inserting a new disk, via gpart list ada4. Note, every partition will have a rawuuid assigned, and FreeNAS will use these as the gptid of the partition. It won't matter what device node the disk moves to, as the gptid doesn't change.

To see what partitions are actually being used as swap, run swapctl -l. If this shows mirror devices, then run gmirror status to see which swap partitions are assigned to which mirrors.
 

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
The right way to handle swap space in FreeNAS is ... not to.

FreeNAS creates swap space on drives added to a pool, but that's intended as a "buffer" when replacing the drive, in case the replacement drive is a hair smaller.

If you are actually using swap, something's very off. You have plenty of RAM, I don't expect you'll never even got close to that hypothetical disaster.
So how do I get a kernel crash dump, or textdump, for jira, without it...?
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
So how do I get a kernel crash dump, or textdump, for jira, without it...?

Look in /data/crash. FreeNAS middlewared takes care of all the dump configuration for you.
 

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
System->Advanced has a setting for the size of the swap partition to create on new disks. On insertion, FreeNAS will automatically GPT partition a new disk, with the first partition being a swap partition, and the second partition being an empty ZFS data partition, suitable for addition to a pool.

You can check this yourself after inserting a new disk, via gpart list ada4. Note, every partition will have a rawuuid assigned, and FreeNAS will use these as the gptid of the partition. It won't matter what device node the disk moves to, as the gptid doesn't change.

To see what partitions are actually being used as swap, run swapctl -l. If this shows mirror devices, then run gmirror status to see which swap partitions are assigned to which mirrors.
This doesn't quite help. I need to create a swap partition on one disk, for crashdump/textdump,to capture the system state after a kernel crash for the devs. I don't know if it'll need to be whole memory or just kernel, but let's assume whole memory for now. (If not, great!). All disks on the system are fully in use, so i cant use any of those. So I need to add a new disk with say 256 GB swap, then wait for the crash to repeat.

I'm not going to add/create 256GB swap on every disk I add, or that's in my pool! So the general "add xx GB swap to every disk" doesnt look helpful. I just need one disk, like a 256 GB SSD, that's pure swap of that size, for that purpose.

Now,what is the correct way to add a single 256GB SSD as swap to my NAS?
 

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
Look in /data/crash. FreeNAS middlewared takes care of all the dump configuration for you.
I tried that. And savecore -Cvv. And sysctl.kdb.panic=1 (user-generated kernel panic).

Reboot,/data/crash is empty.

Apparently the answer is what savecore says, "Dumps not being saved". Its not taking care of it, and I don't know a thing about fixing that.
 
Last edited:

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
  1. Insert the new disk. For the sake of argument, let's say this is ada4. FreeNAS will auto-partition this with a 2 GB swap partition.
  2. gpart destroy -F ada4. This will delete the GPT partition table on ada4.
  3. gpart create -s gpt ada4. Obviously, this creates a blank GPT partition table on ada4.
  4. gpart add -t freebsd-swap -s 256G ada4. Create a 256 GB swap partition on ada4.
  5. swapon /dev/ada4p1. Activate the new swap partition.
  6. dumpon -l to see the current dump device. dumpon /dev/ada4p1 to set the dump device.
 

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
  1. Insert the new disk. For the sake of argument, let's say this is ada4. FreeNAS will auto-partition this with a 2 GB swap partition.
  2. gpart destroy -F ada4. This will delete the GPT partition table on ada4.
  3. gpart create -s gpt ada4. Obviously, this creates a blank GPT partition table on ada4.
  4. gpart add -t freebsd-swap -s 256G ada4. Create a 256 GB swap partition on ada4.
  5. swapon /dev/ada4p1. Activate the new swap partition.
  6. dumpon -l to see the current dump device. dumpon /dev/ada4p1 to set the dump device.
Will the dump device persist over reboots? I think it will need to. Does FreeBSD automatically use any freebsd-swap it finds, on reboot, or does it need to be directed to on reboot? If the latter, how?
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
The middleware prefers the largest swap partition for the dump device, so I believe this will persist. You can check the link ls -l /dev/dumpdev after a reboot to make sure.
 

Stilez

Guru
Joined
Apr 8, 2016
Messages
529
The middleware prefers the largest swap partition for the dump device, so I believe this will persist.
But does it scan disks for swap partitions at boot,which might contain crash dump info,, or does it need to be told, either in the GUI or rc.conf or fstab, or something, in order to recognise they might hold a crashdump after it restarts??

Or put another way, do I just create a huge swap space, and it'll automatically be recognised and used at crash, even after several reboots, and the data on it recovered to /data/crash after more reboots? Or do I need to.do more than just create it the once?
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
If I understand the code in /usr/local/lib/python3.7/site-packages/middlewared/plugins/disks.py, the middleware automatically selects the largest swap partition for dumping, and if a dump does occur, it will go into that partition, and will be visible in /data/crash afterwards. Feel free to look over the code yourself.
 

ByteMan

Dabbler
Joined
Nov 10, 2021
Messages
32
FreeNAS creates swap space on drives added to a pool, but that's intended as a "buffer" when replacing the drive, in case the replacement drive is a hair smaller.

If you are actually using swap, something's very off. You have plenty of RAM, I don't expect you'll never even got close to that hypothetical disaster.

...
swapon /dev/ada4p1. Activate the new swap partition.
...
I see how swapon is used here. Can swapoff be used to disable use of an existing swap partition? For example, to ensure that a hard drive remains in hibernation (in case hibernation is enabled)?

After initial disk insertion and automatic creation of a swap partition, are these the possible options?:
1) Leave swap partition in place and in use (default?)
2) Disable swap partition but leave it in place
3) Disable/Remove the swap partition using steps 2 + 3 of these instructions
  1. Insert the new disk. For the sake of argument, let's say this is ada4. FreeNAS will auto-partition this with a 2 GB swap partition.
  2. gpart destroy -F ada4. This will delete the GPT partition table on ada4.
  3. gpart create -s gpt ada4. Obviously, this creates a blank GPT partition table on ada4.
  4. gpart add -t freebsd-swap -s 256G ada4. Create a 256 GB swap partition on ada4.
  5. swapon /dev/ada4p1. Activate the new swap partition.
  6. dumpon -l to see the current dump device. dumpon /dev/ada4p1 to set the dump device.
 
Top