Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: tmpfiles Question (Read 424 times) previous topic - next topic
0 Members and 4 Guests are viewing this topic.

tmpfiles Question

Hello, looks like I cannot make the system clean /tmp contents on shutdown/reboot (or I'm doing something wrong).

I've copied the file /usr/lib/tmpfiles.d/tmp.conf into /etc/tmpfiles.d and changed its contents to:

Code: [Select]
D! /tmp 1777 root root 0
D! /var/tmp 1777 root root 0

Now these dirs should be cleaned. But they are not...

Any ideas?

 

Re: tmpfiles Question

Reply #1
Do you have tmpfs mounted in /etc/fstab ? Something like this should do it, the exact mount options might vary according to what guides you follow and the intended security level:
Code: [Select]
tmpfs           /tmp            tmpfs   defaults,nosuid,nodev                                   0 0

https://wiki.archlinux.org/title/Tmpfs


Re: tmpfiles Question

Reply #3
No, unless you want to remove /tmp contents on shutdown/reboot.


Re: tmpfiles Question

Reply #5
tmpfs is a RAM based virtual drive, it is used for /tmp because it is both inherently temporary, not surviving a reboot, and faster and more efficient than writing temporary files to your hard drive. It also saves wear and tear to your hard drive. Before this system was commonly deployed in Linux, going back to the 32 bit era when RAM was often in short supply, there was a system to delete the contents of /tmp during boot. You can research on how to resurrect this older method of managing /tmp if you want, but for a modern setup, adjust your /etc/fstab and afterwards run:
Code: [Select]
# mkinitcpio -P 

There is usually very little in terms of file size that goes in /tmp so it isn't a big drain on RAM. The only common snag is if you use an AUR helper that builds in /tmp by default to make use of faster write times, a big build like the kernel or something will usually fail due to lack of space and RAM, so for large packages you need to specify it builds somewhere else in a regular directory backed by the hard drive. Unless you have vast quantities of RAM, of course.


Re: tmpfiles Question

Reply #7
tmpfs can swap to disk if full, right? So small size not a big deal?
No. if something is using /tmp (as tmpfs) and it's gets full things break/crash.
However I think, but am not sure, that if you set tmpfs to be bigger than your installed ram then it might swap some out to disk if it actually exceeds the installed ram size ? I'm not sure if I've read that or if I am guessing ?

I have only ever had issues with such crashes when compiling huge programs such as chromium but I suppose video editing could be another candidate ?

Re: tmpfiles Question

Reply #8
thank you. still sipping coffee. I meant to say it can be bigger than ram and will swap to disk

Re: tmpfiles Question

Reply #9
...but for a modern setup, adjust your /etc/fstab and afterwards run:
Code: [Select]
# mkinitcpio -P 

There is usually very little in terms of file size that goes in /tmp so it isn't a big drain on RAM.

Thank you very much for the explanation! Now I'm happy. Cheers!