Ubuntu – Can Swap Files be located in separate partitions, such as an old Swap Partition

swap

Ubuntu is using swap files instead of swap partitions (as of Ubuntu 17.04) , except systems upgrading from 16.04 will retain their swap partitions and reuse them instead of swap files, as discussed in this answer. But, if I am upgrading and decide to use a swap file instead, can I place it in the old swap partition?

I realize this will limit the size of the swap file, but this way I can still make use of that drive space. If I can do this, would I have to format the partition to the same file-system type as Ubuntu? And would I have to keep it permanently mounted?

Best Answer

You can format the partition in "EXT4" and use it as normal partition, and then create a swap file there like in :

https://support.rackspace.com/how-to/create-a-linux-swap-file/

However, you have to mount this new partition at startup by adding it to the fstab file because a partition created after installing ubuntu will not be automatically mounted unless you add it to the fstab partition, so in summary you will mount the new partition then you will mount the swap file into the new partition, which is a very bad idea.

Why don't you just collapse this partition with any other partition and create the swap file into the root partition for example!