Preserving /tmp on reboot

Credit to Chris.C and lesmana From How is the /tmp directory cleaned up?

On ubunutu the cleanup of /tmp is done via the script at /etc/init/mounted-tmp.conf

This cleanup is performed on a file if TMPTIME number of days have elapsed since that file was created or modified. The value for TMPTIME is set in /etc/default/rcS

To stop the default cleanup behavior you can either increase TMPTIME to a sufficient value or comment out the final find lines in mounted-tmp.conf script that are responsible for the actual deletion.

Lastly, it may be that your /tmp filesystem is actually mounted as a tmpfs which generally means the filesystem would be mapped to RAM instead of your hard drive and would not persist after reboots.

This is not the default on ubunutu, but you can check whether this is the case on your system by issuing a mount and looking at the listed filesystem for /tmp (if there is one listed).

To stop the creation of /tmp as a tmpfs, you can remove the entry for /tmp from /etc/fstab


@ssnobody answer solves the problem, but this isn't something you should do. Let /tmp and the initscripts do their work.

From Filesystem Hierarchy Standard 3.0 Chapter 3 Section 18 about /tmp directory:

3.18. /tmp : Temporary files

The /tmp directory must be made available for programs that require temporary files.

Programs must not assume that any files or directories in /tmp are preserved between invocations of the program. […]

Although data stored in /tmp may be deleted in a site-specific manner, it is recommended that files and directories located in /tmp be deleted whenever the system is booted.

FHS added this recommendation on the basis of historical precedent and common practice, but did not make it a requirement because system administration is not within the scope of this standard.

However, FHS defines another directory for this purpose. From Filesystem Hierarchy Standard 3.0 Chapter 5 Section 15 about /var/tmp directory:

5.15. /var/tmp : Temporary files preserved between system reboots

The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Therefore, data stored in /var/tmp is more persistent than data in /tmp.

Files and directories located in /var/tmp must not be deleted when the system is booted. Although data stored in /var/tmp is typically deleted in a site-specific manner, it is recommended that deletions occur at a less frequent interval than /tmp.

This is the perfect place to put temporary files not so valuable but you still don't want to loose after an unexpected shutdown.

Anyway, working with valuable files inside temporary directory is always a bad idea. You should work in your home directory. By the way, you usually have a $HOME/tmp directory too which isn't emptied after a reboot that you can use for your personal temporary files.


One option would be to hook up the hard drive to another computer and pull the files off out of the tmp folder with that computer... Or, if you have a dual-boot system, boot up into the other system, as long as that system supports the disk fornatting of your Ubuntu partition, and then pull down the files.