<SOLVED> Move temp tmp folder and swap file to a different drive

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
tzell
Level 3
Level 3
Posts: 126
Joined: Wed Aug 03, 2022 4:56 pm

<SOLVED> Move temp tmp folder and swap file to a different drive

Post by tzell »

Hi forum,

My main motivation is to move certain things to a spinning disk HDD
in order reduce read/write operations to the main OS linux mint SSD drive.

Is there a way to:
1. move the 'tmp' folder to a different drive.
2. move swap file to a different drive.
3. Any other heavy read/write locations / folders / files I should know of? And if so, is there a way to move those to a different drive?

Thanks!
Last edited by LockBot on Sun Feb 12, 2023 11:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pjotr
Level 23
Level 23
Posts: 19886
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Move temp tmp folder and swap file to a different drive

Post by Pjotr »

I doubt whether that's a good idea. This might cause slowdowns because of the lesser speed of the spinner.

Instead, I recommend to reduce swappiness (making it being used less often) and perhaps to move some temporary files into the RAM. See:
https://easylinuxtipsproject.blogspot.c ... -mint.html
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
AndyMH
Level 21
Level 21
Posts: 13578
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Move temp tmp folder and swap file to a different drive

Post by AndyMH »

This is no longer an issue for SSDs, their life expectancy is at least as good as an HDD if not better. You don't need to do anything.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: Move temp tmp folder and swap file to a different drive

Post by Cosmo. »

As AndyMH said.
The lifespan of an SSD is significantly longer than that of an HDD. While HDDs tend to last around 3-5 years, SSDs can last up to 10 years or more. This is because SSDs have no moving parts, whereas HDDs have spinning disks that can wear down over time.
from https://www.easeus.com/storage-media-re ... espan.html, there exist countless others.
Petermint
Level 9
Level 9
Posts: 2981
Joined: Tue Feb 16, 2016 3:12 am

Re: Move temp tmp folder and swap file to a different drive

Post by Petermint »

You do not mention the SSD or the machine. If the SSD is a good brand and less than about 5 years old, the only problem is heat build up from continuous writes. That is a rare problem with desktops and a good heatsink.

In my notebook, the first SSD has cooling vents and the second does not. I never have heat problems with the main SSD. The second SSD often slows down due to heat. I am removing the second SSD and will double the size of the first SSD.

If you do not have heat roadblocks, I doubt paging or temp could break a modern SSD in less than 10 years. That only happens in servers running 24/7 and after many years.

Writes can be slow if you work on big video files. You might want to reduce writes by moving the tmp into ram, as mentioned in another post. How much memory do you have?
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Move temp tmp folder and swap file to a different drive

Post by Termy »

I also want to chime in here to say SSDs (at least modern ones) usually no longer need constant babysitting to avoid unnecessary writes. You'd have to repeatedly seriously hammer an SSD for it to be a problem. That being said, I get the need to tweak and tinker, so have at it, just know that it's likely going to make a negligible difference. Anecdotally speaking, I have used the same old 128G SSD as my main OS drive for around a decade, with Linux and once upon a time with Windows, through many reinstalls and software changes; it still seems as good as it was when I got it, and it was second hand at the time!

If you have a swap file, you'll need to recreate one where you want, enable it, then update '/etc/fstab' to make it and its new location permanent. There are guides for this out the wazoo on here and elsewhere online, so have a quick search with your favorite search engine. As for moving '/tmp', it's doable, but a bad idea, because some software assumes it's '/tmp' and not elsewhere. Moving it would be a case of setting up a separate partition for it, once again involving '/etc/fstab' and some more advanced knowledge. There'll probably be guides for all that, too.

As others have suggested, if you have enough RAM, I recommend using TMPFS for '/tmp', to store '/tmp' stuff into RAM, but as you have an SSD, there's not too much point in it. I have an SSD with a 6G TMPFS (and 14G of total RAM) for '/tmp' set up, but I'll begrudgingly admit that it's unnecessary. Here's my '/etc/fstab' entry for that:

Code: Select all

none /tmp tmpfs mode=1777,nodev,nosuid,size=6G,relatime 0 0
Feel free to use it, although it is more restrictive than it ordinarily is, due to how I have my system set up, but it should be usable. That's for 6G, so just edit accordingly.
I'm also Terminalforlife on GitHub.
Hoser Rob
Level 20
Level 20
Posts: 11806
Joined: Sat Dec 15, 2012 8:57 am

Re: Move temp tmp folder and swap file to a different drive

Post by Hoser Rob »

I can see this sort fo thing for some users doing seriously high power things like heavy duty NLE use, which is going to generate big temp files. But for the vast majority of us, no, not really.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: Move temp tmp folder and swap file to a different drive

Post by Cosmo. »

Termy wrote: Fri Aug 12, 2022 8:16 am If you have a swap file, you'll need to recreate one where you want, enable it, then update '/etc/fstab' to make it and its new location permanent.
If this should really be judged as needed, it would be enough to create a new swap file, the old one gets automatically overwritten (just as any case of 2 files with the same name). Changing fstab is not needed in this case. But the file should get in any case chmoded, so that only root can read and write (sudo chmod 0600 /swapfile).
User avatar
all41
Level 19
Level 19
Posts: 9498
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Move temp tmp folder and swap file to a different drive

Post by all41 »

Termy wrote: Fri Aug 12, 2022 8:16 am

As others have suggested, if you have enough RAM, I recommend using TMPFS for '/tmp', to store '/tmp' stuff into RAM, but as you have an SSD, there's not too much point in it. I have an SSD with a 6G TMPFS (and 14G of total RAM) for '/tmp' set up, but I'll begrudgingly admit that it's unnecessary. Here's my '/etc/fstab' entry for that:

Code: Select all

none /tmp tmpfs mode=1777,nodev,nosuid,size=6G,relatime 0 0
Feel free to use it, although it is more restrictive than it ordinarily is, due to how I have my system set up, but it should be usable. That's for 6G, so just edit accordingly.
I have been using this for temp to ram:
sudo cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/
sudo systemctl enable tmp.mount
How does using the fstab entry differ?
Everything in life was difficult before it became easy.
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Move temp tmp folder and swap file to a different drive

Post by Termy »

all41 wrote: Fri Aug 12, 2022 9:11 am [...]
I've surprisingly never heard of that method, but from looking at the service file, I see it uses TMPFS and has an Options parameter, where you can specify various mount options for TMPFS.

However, I couldn't find anything in the file regarding size. I assume you can provide the usual size= mount option to specific a size, but if you've not got the size of the RAM drive set, I'd be a little concerned, because the kernel documentation states that it defaults to half of your RAM.

I have a separate '/boot' partition, a separate '/var' partition; a tweaked '/proc', '/run/shm', and '/dev/shm'; a tweaked separate '/home' partition, and of course the '/tmp' entry, so having all that in one place is a bonus for me, as it's simply far more convenient. If you already work with '/etc/fstab', then I'd just go ahead with my approach, but to each their own. I get the convenience of the service file already being present but disabled.

BTW, as the service file already exists, you should be able to forgo the copy and instead simply run:

Code: Select all

sudo systemctl enable --now tmp.mount
That should immediately enable and start the service, unless something changed in more recent versions of Ubuntu/SystemD.

IIRC, SystemD does the copying anyway, so I think you essentially did the same thing twice, but take that with a pinch of salt, as I'm not familiar with the old way of enabling services, short of faffing about with OpenRC in Gentoo that one painful time, and hearing things from fellow nerds.
I'm also Terminalforlife on GitHub.
User avatar
tzell
Level 3
Level 3
Posts: 126
Joined: Wed Aug 03, 2022 4:56 pm

Re: Move temp tmp folder and swap file to a different drive

Post by tzell »

Thank you guys for all the replies,
I'll try to use the RAM disk instead
And basically not worry too much about SSDs, as suggested.
Pjotr wrote: Fri Aug 12, 2022 6:18 am I doubt whether that's a good idea. This might cause slowdowns because of the lesser speed of the spinner.

Instead, I recommend to reduce swappiness (making it being used less often) and perhaps to move some temporary files into the RAM. See:
https://easylinuxtipsproject.blogspot.c ... -mint.html
Thanks yeh you're right I'll reduce swappiness, read that article you sent, quite interesting!
Petermint wrote: Fri Aug 12, 2022 8:01 am How much memory do you have?
I have 32GB RAM, and the SSD is modern not old, so I should probably leave it alone as suggested.

Termy wrote: Fri Aug 12, 2022 8:16 am I have used the same old 128G SSD as my main OS drive for around a decade, with Linux and once upon a time with Windows, through many reinstalls and software changes; it still seems as good as it was when I got it, and it was second hand at the time!

As others have suggested, if you have enough RAM, I recommend using TMPFS for '/tmp', to store '/tmp' stuff into RAM, but as you have an SSD, there's not too much point in it. I have an SSD with a 6G TMPFS (and 14G of total RAM) for '/tmp' set up, but I'll begrudgingly admit that it's unnecessary. Here's my '/etc/fstab' entry for that:

Code: Select all

none /tmp tmpfs mode=1777,nodev,nosuid,size=6G,relatime 0 0
Wow, you've convinced me to never worry about SSDs ever again :)
And thank you I'll try to tinker a bit with the ram tmp.
Locked

Return to “Beginner Questions”