Swap file for a novice

The fallocate commands needs a filename, but you are providing a block device that corresponds to the external drive that you have connected. If you run ls -l /dev/sdc*, the results come back looking something like this (in my example, it's /dev/sda but it's the same thing):

brw-rw---- 1 root disk 8, 0 Dec  2 10:10 /dev/sda
brw-rw---- 1 root disk 8, 1 Dec  2 10:10 /dev/sda1
^

Pay attention to the first character; it describes the type of file that it is. A b meaning block device, which broadly speaking means a drive. You would need to provide the path to an actual file.

For reference, you can take a look at the default file created as swap, usually located at /swapfile:

-rw------- 1 root root 3376414720 Oct  8 21:53 /swapfile

A single - means this is a regular file. Notice that it was very strict read/write permissions as this will potentially contain sensitive information, including passwords and things like that.

So, you would first create the file at the new drive or partition:

sudo fallocate -l 2G /dev/sdc1/swapfile
sudo chmod 600 /dev/sdc1/swapfile
sudo mkswap /dev/sdc1/swapfile

Then, disable swap and remove the current swapfile:

sudo swapoff /swapfile
sudo rm /swapfile

And, finally, enable swap again but pointing to the newly created file for that purpose.

sudo swapon /dev/sdc1/swapfile

Do note, however, that upon rebooting the system will try to mount the previous swapfile. You need to update that now, as well:

sudoedit /etc/fstab

This will bring up a terminal-based text editor, but you can also use the regular text editor, just remember that you need to edit this file with elevated privileges.

You should see an entry at the bottom that looks something like this:

/swapfile none  swap  sw 0  0

You need to change it to point to the new swapfile in the other drive:

/dev/sdc1/swapfile none  swap  sw 0  0

With all that said, I do not recommend you follow through with this setup.

I mean, I don't really know your exact use case but if you can spare 2 or even 4 GB off of your SSD, that would be much simpler to manage in the long run, and it'll be much faster and efficient.

On the other hand, since you are already making use of another drive, you shouldn't use USB flash drives which are notoriously unreliable. Use a proper drive if you can, and while you're at it use a whole partition to make things simpler.

And even before your commit to one strategy or another, I think it's worth looking into this a bit further to determine whether swap really is going to help. Try using one program at the time to see how the response times vary; after a few days you should have a better sense of whether you're pushing the system's resources a bit too far.