Why should I make a separate partition for /tmp?

30,609

Solution 1

One common reason for making it a separate partition is to be able to mount it as nosuid and noexec. This prevents both privilege-escalation and arbitrary script execution from /tmp, respectively. This is particularly useful in multi-user environments (e.g. hosting) where unprivileged users will have access to read/write data to /tmp but should not be able to perform either of these actions.

Another justification would be to limit the amount of temporary data stored (since not everything cleans up after itself) to prevent other more important partitions from filling and causing service interruption and/or data loss.

Solution 2

It also makes sense from the security standpoint. Since many programs write temporaries in /tmp and /tmp is automatically cleared (using insecure file deletion), this means a lot of deleted but recoverable files still reside on the /tmp partition. If you isolate this partition and make it smaller, then it's easier to securely clean it, e.g. using sfill from the secure-delete package.

Solution 3

Also when tmp is on separate partition:

  • You can share tmp between couple of linux distributions on multi boot environment and save disk space
  • tmp can be excluded from RAID setup (RAID disk space is at premium)
  • tmp can reside on faster media than root (i.e. RAM disk, SSD disk)
  • tmp can reside on media less prone to wearing (i.e root on Flash disk, tmp on regular disk or RAM disk)
  • tmp can reside on separate disk drive (to spread workload)
  • tmp can be mounted on different partition/disk if needs to be bigger without affecting the rest of the system simple by editing a line in /etc/fstab
Share:
30,609

Related videos on Youtube

patryk.beza
Author by

patryk.beza

Yet another geek in love with Linux & Open Source. My PGP pubkey: 0x90d32cb0e7e1e565. If you can't explain it simply, you don't understand it well enough. [A.Einstein] It’s a long way by the rules, but short and efficient with examples. [Seneca the Younger] Talk is cheap. Show me the code. [L.Torvalds]

Updated on September 18, 2022

Comments

  • patryk.beza
    patryk.beza over 1 year

    Why should I make separate partitions for /tmp, /var and so on?

    I can see more drawbacks than benefits. One benefit is that I can use ext4 with journaling for /home and ext4 without journaling for other partitions.

    Main drawback is size limit. When I was partitioning my disk I was taught to allocate at least 50MB for /tmp, so I set 1GB /tmp partition. Now I have trouble because it's definitely not enough! Copying DVDs needs more free space. Even caching single YouTube's concert needs more than 1GB of free space on /tmp partition.

    What are the benefits of having a separate /tmp partition?

    • Sampo Sarrala - codidact.org
      Sampo Sarrala - codidact.org almost 12 years
      if you have separate partitions for home, var, tmp, ... then you don't need too much space for /. Good thing if someday you need to restore system/settings from backup image. There is countless reasons why it is good to keep different parts of system on differens partitions.
    • solarc
      solarc almost 12 years
      Nowadays Debian uses tmpfs for /tmp, it can autoresize to accommodate files and can move stuff to the swap if needed.
    • sondra.kinsey
      sondra.kinsey about 5 years
      See also a question on separate partitions generally and questions specific to /boot and /var
  • patryk.beza
    patryk.beza almost 12 years
    But still estimating size of /tmp is difficult. 2 years ago I assumed 1GB is enough and now I can see I need more space for /tmp. It's difficult to judge what is more important safety reasons or inability to work with programs that need more than fixed /tmp size...
  • Garrett
    Garrett almost 12 years
    Use LVMs and leave some free space in your volume group. Allocate it to individual logical volumes (e.g. /tmp) as needed. LVM supports online resizing as do ext3/4.