Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to install Arch Linux (from the 2014-04-01 snapshot). I've made a swap file and tried to swapon it, but I got an error(?) message I don't understand.

I've executed

fallocate -l 512M /mnt/sda2/swapfile
chmod 600 /mnt/sda2/swapfile
swapon /mnt/sda2/swapfile

and the output is

swapon: /mnt/sda2/swapfile: read swap header failed: Success

and I have :( at the end of my command line. So did it succeed or fail? Is this not how to set up a swap file?

share|improve this question
up vote 18 down vote accepted

Is this not how to set up a swap file?

I think you missed a step in between chmod and swapon:

mkswap /mnt/sda2/swapfile

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.


  • Passing 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.
share|improve this answer
You get two upvotes if I could - the mkswap and errno. – Aaron D. Marasco Apr 13 '14 at 22:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.