Can't create swap file: swapon failed: Invalid argument

Ah cheers that’s done the trick! Finished it with running the regular swap file creation commands. In future if someone else hits this problem here’s the full solution:

> cd /swap
> sudo truncate -s 0 ./swapfile
> sudo chattr +C ./swapfile
> sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=4000 status=progress
4011851776 bytes (4.0 GB, 3.7 GiB) copied, 2 s, 2.0 GB/s
4000+0 records in
4000+0 records out
4194304000 bytes (4.2 GB, 3.9 GiB) copied, 2.35927 s, 1.8 GB/s
> sudo chmod 0600 /swap/swapfile
> sudo mkswap -U clear /swap/swapfile
Setting up swapspace version 1, size = 3.9 GiB (4194299904 bytes)
no label, UUID=00000000-0000-0000-0000-000000000000
> sudo swapon /swap/swapfile
> swapon -s

Filename				Type		Size		Used		Priority
/swap/swapfile                          file		4095996		0		-2

For a 16GB machine, is 4GB going to be a large enough swap file to enable suspend?

2 Likes