Other HOWTO share labeled swap between FreeBSD & Linux

The Linux swap partition uses a 4096-byte header that holds the label & UUID. You can see the structure here. FreeBSD doesn't use a header at all.

The problem is thus how to prevent FreeBSD from overwriting the header. It turns out there's a neat way to do just that with GEOM using the gnop(8) tool:

It's as simple as running these commands:

Bash:
sudo gnop create -v -o 4096 /dev/vtbd1s1
sudo swapon /dev/vtbd1s1.nop
...
sudo swapoff /dev/vtbd1s1.nop
sudo gnop destroy /dev/vtbd1s1.nop

But it would be even better if we use a label instead of a device path, like /dev/swaplinux/LABEL

I created a PR to do add Linux swap label support to GEOM label:


GEOM is truly a great piece of software.
 
You can't unless you run mkswap on Linux before using it. If FreeBSD writes to the swap partition the Linux swap metadata will be destroyed or corrupted making it unusable by Linux. To get around this you'll need to create a systemd service to mkswap the swap partition and enable it.

FreeBSD, like all other UNIX/UNIX-like variants except for Linux simply uses swap without swap metadata. Linux needs its swap metadata in order to use swap.
 
You can't unless you run mkswap on Linux before using it. If FreeBSD writes to the swap partition the Linux swap metadata will be destroyed or corrupted making it unusable by Linux. To get around this you'll need to create a systemd service to mkswap the swap partition and enable it.

This is not really needed anymore with this workaround that prevents the metadata from being overwritten.

But even without this patch, swapon calls mkswap if needed as you can see here. Only labeled swap in /etc/fstab would be unusable without this workaround.
 
Actually, the partition marking that Linux does is an excellent idea. FreeBSD should use one, too, and there is no reason to use a different on-disk format than Linux.
 
swapon shall not overwrite the header!

swapon: Do not overwrite Linux swap header

Hope I'm not breaking any rule wrt shameless self-promotion. I just want people to test it lol.
 
Don't put the Linux partition into hibernate while using the FreeBSD partition because Linux writes to swap on hibernate, and FreeBSD would overwrite that.
 
Back
Top