Wednesday, April 24, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 2378  / 1 Year ago, mon, december 12, 2022, 10:39:43

I often stick temporary files that I'm working on in /tmp, so I don't have to delete them once I'm done. However, if the computer crashes, then I'm out of luck, because that directory will be wiped.



Is there a way to prevent /tmp being wiped if the computer is restarting from a crash? If not, is there another solution, such as creating another temporary directory elsewhere and have it automatically deleted on restart if there is no crash.


More From » startup

 Answers
4

/tmp is cleaned at boot by the Upstart script /etc/init/mounted-tmp.conf. If you look at that file, you see that there are no ways to tell it not to do his job. However you are free to modify it.



Here's how I'd proceed:




  1. At the very end of mounted-tmp.conf (just before end script), place the following:



     touch /tmp/.notclean


    This way, every time /tmp is mounted, a file .notclean will be created.


  2. After the following line (which is the line before the script starts removing files)...



     cd "${MOUNTPOINT}" || exit 1


    ...check for the existence of .notclean. If the file exists, it means that the computer did not shutdown cleanly.



     cd "${MOUNTPOINT}" || exit 1
    [ -f .notclean ] && exit 0

  3. Now you need a new Upstart script that removes .notclean on shutdown. Create /etc/init/mark-tmp-clean.conf and place this code:



     description "some useful description"
    start on starting rc
    task
    script
    rm -f /tmp/.notclean
    end script


[#33464] Wednesday, December 14, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brailloni

Total Points: 122
Total Questions: 108
Total Answers: 108

Location: North Korea
Member since Tue, Apr 4, 2023
1 Year ago
brailloni questions
Tue, Jun 21, 22, 21:51, 2 Years ago
Thu, Jul 29, 21, 05:25, 3 Years ago
Sat, Apr 2, 22, 17:32, 2 Years ago
Mon, Oct 31, 22, 21:39, 2 Years ago
;