Create a swap partition on already existing drive with zorin os installed

When installing Zorin I have set the installer to manually install stuff, and followed through the zorin guide except I must have missed creating a swap partition. As such today I noticed Linux can act wonky under heavy load (16gb of ram), and can also behave weirdly after waking the computer on when using the suspend mode. As such, I would like to know how to safely create a swap partition on an already existing drive with zorin without data loss.

Take a look at these threads:


For what it's worth - the swapfile is faster than the partition in terms of 'what you get'.

If you need a larger size, you can resize the swapfile to reflect that size. Just do:

sudo -i (enter password)
swapoff /swapfile
rm /swapfile
touch /swapfile
chmod 600 /swapfile
fallocate -l xG /swapfile (x = the size you prefer, 'G' signifies gigabytes. So, 4G = 4GB file allocation)
mkswap /swapfile
swapon /swapfile


Check with free -h to see your swap status.


But if OP wants to use hibernation, then will need a sawp file rather than swap partition me thinks.

Thanks! I followed this through. I have a question though, what does chmod 600 /swapfile do?.
Also, considering you inserted commands to delete potential old swap files, does that mean I could reuse the same commands in case I wanted to change the swapfile size in the future?

I don't know why the swap file gets unmounted after a while or a reboot. Why isn't it permanent?
Edit: Point 5 of this thread helped me

1 Like

chmod is a command to change the mode, or permissions, of a file. A value of 600 translates to read and write permissions to the owner of the file, and no permissions to everyone else. If you follow the instructions from those threads the owner should be root, a special user present in Linux that controls everything. As this file can contain very sensitive information (encryption keys, etc) it's important that no one else is able to read or write to it.

And yes you should be able to delete this file and re-create it, following the instructions provided. I would recommend not doing this while the system is under heavy load, just to be safe.

I see you got a little further haha I've been out of the loop with work and all..

As @zenzen states - doing the chmod 600 command will allow you to read / write into the swap. Definitely while you're in an idle state haha don't wanna be messing with swap when you've got tons of applications going!

As far as the unmounted status - that's odd but, it should be permanent. Did you change anything in /etc/fstab by chance? Take a look there with cat /etc/fstab and look at the line starting with swap - you should see:

/swapfile none swap sw 0 0

If not, add that in - spacing doesn't really matter.

If you have two swapfiles, that may cause some confusion to the system.. Just remove the one you don't need.

Have been using the new Ubuntu MATE 24.04 distro - uses a swap.img file instead of the standard swapfile.. That's a new one for me! But, apparently isn't handled the same way; I was trying to swapon /swap.img and kept giving me errors about permissions even with su. :thinking:.. But, checked fstab - everything looked gravy so gave it a reboot and kept the changes I made (just a resize).

And yep! You can use those same commands to make / change your swap at any time :+1: