I have a 240 GB SSD and 1 TB 5400 rpm HDD. Planning to install 18.04 on SSD and use HDD as /home. My concern is whether to put swap file on SSD or HDD. I have 8 GB RAM and will use 16 GB swap file. Do I have to locate swapfile on root or can I locate it on HDD, if yes how? Thanks.
3 Answers
Usually you want a swap partition and not a swap file.
EDIT: looks like the above is no more valid.
That said, you can easily choose the location during the installation process, and you can certainly change it afterwards.
This official Ubuntu documentation on swap should get you started on deciding what to do and how to do it.

- 3,164
-
I think since Ubuntu 18.04, swap partitions have been replaced in favour of swap files. – Ray Sep 05 '18 at 12:09
-
@Ray I didn't know that, I'll edit my answer accordingly. – Daniele Santi Sep 05 '18 at 12:10
-
I forgot to cite a source -- sorry! It is mentioned in the 18.04 release here. i.e., it says "For new installs, a swap file will be used by default instead of a swap partition". – Ray Sep 06 '18 at 03:54
I don't think there's a problem installing Ubuntu on an SDD. Thus your swap file can be on the SSD with the root file system. If you want it on a hard disk (i.e., with /home, separate from the Ubuntu system), you probably can.
I haven't tried it myself but, for example, I have this in my /etc/fstab:
/swapfile none swap sw 0 0
Thus, I don't see a reason why I couldn't replace /swapfile
with /home/swapfile
, if I really wanted to. You can try installing everything on the SSD, with /home on the hard disk. Then try running your system with the swapfile on either to see if you get any speed improvements.
In my opinion, one of the annoying things of earlier versions of Ubuntu was the swap partition... It made it hard to move it around after the system as installed. I don't have much experience with Ubuntu 18.04's use of a swapfile, but it seems to afford more flexibility, in this regard.
Does this answer your question? You used the phrase "have to" in your question and, in short, I don't think you have to put the swapfile in a particular place.

- 2,071
-
For sensitive things like this that could easily break, posting a tried and tested solution is more helpful than untested theories. – chx101 Dec 31 '21 at 00:49
-
@chx101 I disagree. I don't think there's anything wrong with my answer. After all, I said it fairly directly that I haven't tried my solution before. AskUbuntu allows multiple answers to be posted and for the OP and anyone for that matter to read each answer and decide for him/herself. Anything related to computing could be sensitive, depending on what it's being used for. As an extreme example, you could remove the swap file and the swap partitions and your system would still "function". Does that mean it isn't sensitive? – Ray Jan 02 '22 at 12:21
-
I'm just saying that if you are going to give directions that involve dealing with system files, you have to give a detailed answer. Otherwise someone will interpret your solution the wrong way. – chx101 Jan 02 '22 at 19:46
-
@chx101 I know what you're saying. I'm saying that what you're complaining about is clear in my post. For example, I never said I had tested the solution when in fact I have not. So, anyone can read what is said and judge by him/herself. Moreover, AskUbuntu is looked after by volunteers. They don't always have all the answers and sometimes just give a "best guess" and the OP sometimes figures it out themselves using the hints from the answer. That has happened to me as the OP in other question. My answer, though 3 years ago, did not misinterpret myself at all. – Ray Jan 03 '22 at 15:31
Depends on the usage of either of the drives. If your memory is low but swappiness configuration is set high, what will happen is that system will write data to swap more often to free up actual RAM.
Frequent writes to SSD decrease it's expected life. Personally, I keep swap file on SSD, and haven't experienced any issues so far.
Frequent writes to HDD will prevent it from spinning down and saving power. My personal opinion is that it's perfectly OK to have it on HDD. It may be even more desirable to have it on HDD with high swappiness setting, thus avoiding extra wear on SSD. As for your home directory, just remember to have a backup.
On side note, 16GB of swap would be too much. It would only be useful if you have programs that have lots of temporary data and temporary files open, or lots of data that is loaded initially but rarely used. This is the main purpose of swap. For actually frequently used data you need RAM. So one thing to consider instead of large swap file is to add more RAM for actual performance.

- 105,154
- 20
- 279
- 497