18
#sudo dd if=/dev/zero of=/swapspacefile bs=1M count=2048k

  0+0 records in
  0+0 records out
  0 bytes (0 B) copied, 0.000417928 s, 0.0 kB/s

#chmod 600 /swapspacefile

   mkswap: error: swap area needs to be at least 40 KiB

   Usage:
     mkswap [options] device [size]

   Options:
     -c, --check               check bad blocks before creating the swap area
     -f, --force               allow swap size area be larger than device
     -p, --pagesize SIZE       specify page size in bytes
     -L, --label LABEL         specify label
     -v, --swapversion NUM     specify swap-space version number
     -U, --uuid UUID           specify the uuid to use
     -V, --version             output version information and exit
     -h, --help                display this help and exit


#sudo mkswap /swapspacefile

but it throws below when I excute the,

  swapon: /swapfile: insecure permissions 0644, 0600 suggested.
  swapon: /swapfile: read swap header failed: Invalid argument
ganesh
  • 181
  • 1
  • 1
  • 3
  • 3
    bs=1M count=2048k - that translates to 2 TB of swap... really ? dd output is quite clear: 0 bytes (0 B) copied and if you needed confirmation, mkswap says: swap area needs to be at least 40 KiB. Do it again, this time without k: dd if=/dev/zero of=/swapspacefile bs=1M count=2048 – don_crissti Dec 06 '14 at 07:43
  • Please past what you did, not an interpretation of it. – ctrl-alt-delor Dec 27 '18 at 10:10

1 Answers1

38

I read this from the comments, but I thought I would be visible as an answer.

# mkswap /swapfile

You should run this command to prepare the file to be used as a swap space.

  • That is in the question, and there is no edit history. – ctrl-alt-delor Dec 27 '18 at 10:13
  • 3
    still a great solution, worked for me ppl will come to this question because they got the same error from not preparing swap, (and they will get the same error as in the title) – Nick Bailuc Jul 15 '21 at 18:22
  • Facing problems in Xubuntu no way to recognize swap (I thought it would be a problem with the partition, fstab and so on). Your answer saved my day! – tdmsoares Aug 01 '21 at 22:52