freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

swapon: Do not overwrite Linux swap header

Open ricardobranco777 opened this issue 1 year ago • 1 comments

The Linux swap partition uses a 4096-byte header that holds the label & UUID. You can see the structure here.

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 system tool:

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

This PR modifies swapon to automate this process, which also works with /etc/fstab. This will benefit dual-boot installations and also live-CD's.

For automated detection of swap label by GEOM see this PR: https://github.com/freebsd/freebsd-src/pull/1083

Fixes: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221935

ricardobranco777 avatar Jan 26 '24 17:01 ricardobranco777