Is this not how to set up a swap file?
I think you missed a step in between
As for the oxymoromic error...
swapon: /mnt/sda2/swapfile: read swap header failed: Success
What this literally means is there's a bug in the
swapon code, but not necessarily one related to its primary functioning.
C library functions often make use of errno, a global variable that stores an error code. The function itself will return a value indicating an error occurred (any error), and the exact nature of that error will be stored in
errno. The idea is that if you get an indication of an error, you can then check the value of
errno to see exactly what it is.
There's also a
strerror() library function that will take an errno value (they're integers) and return a human language string relating to it. One of those is
Success, which corresponds to an error code of 0 (i.e., no error).
So when you see something like this, it indicates a mistake such as:
- Getting an error, then calling another function (successfully) which resets errno to 0 behind the scenes, then using errno to determine the specifics of the error you got before you called the second function.
strerror() a variable that was supposed to have been assigned the value of errno at some point (to prevent the previous mistake from happening) but wasn't.