14

I have read that I should not mount /var/tmp as a temporary filesystem (e.g., as tmpfs), because files in /var/tmp must not be deleted on reboot. Is that correct?

Suppose I did mount /var/tmp as a tmpfs, so its contents are deleted on every reboot. Would that be bad? If yes, what could go wrong? How bad would it be?

1
  • @JMoore, I'm asking about /var/tmp, not about /tmp. My apologies if this was unclear.
    – D.W.
    Commented Aug 11, 2013 at 1:11

1 Answer 1

18

Files in /var/tmp are expected to be persistent across reboots. From the FHS:

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 in /var/tmp are often cache files or temporary files that should not disappear in the event of a sudden power failure. They cannot be expected to live forever though. It is common to clear old files from /var/tmp on a schedule.

Here are some examples of /var/tmp's usage:

  • Some implementations of vi (e.g. nvi) put their crash recovery files in /var/tmp. If that's a temporary filesystem, you don't get a chance of recovering anything. Vim puts its crash recovery files in the same directory as the file being edited.
  • I use a Firefox plugin that allows me to edit text fields in Vim. To accomplish this, the plugin creates a temporary file in /var/tmp (/tmp is the default though) and passes the file to Vim. If my computer loses power while I am using this feature, my writing will be safe and sound in /var/tmp.
  • Text editing tools such as ex and sudoedit put temporary files in /var/tmp. If /var/tmp was mounted as tmpfs, you would risk losing data to unexpected power failures.
  • The git-archive(1) manpage has the following example.

    git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)
    Create a tar archive that contains the contents of the latest commit on
    the current branch, and extract it in the /var/tmp/junk directory.

    It is possible that the /var/tmp directory was chosen so that the extracted archive contents would not be lost to sudden power failure.

  • Since /var/tmp is cleared periodically but never unexpectedly, it is common to store temporary logs and test databases there. For example, in the arpd manpage, /var/tmp is used as the location of a test database for the sake of some examples.

    arpd -b /var/tmp/arpd.db
    Start arpd to collect gratuitous ARP, but not messing with kernel functionality.

In summary, your system is unlikely to incur severe damage if you mount /var/tmp as a tmpfs. Doing so may be undesirable though as you would risk losing information to power failures and reboots.

2
  • See also: unix.stackexchange.com/questions/30489/…
    – user26112
    Commented Aug 11, 2013 at 0:53
  • 2
    @D.W. Also /var/tmp is likely to be larger than /tmp, so some applications expect to put large temporary files there. If /var/tmp is on tmpfs, your system may run out of memory or start thrashing. Commented Aug 11, 2013 at 19:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .