5

I am confused about whether my /tmp using tmpfs is respecting the size parameter that I gave to it in /etc/fstab:

My fstab entries now read:

root_pool/var/tmp  /tmp /var/tmp zfs rw,nodev,nosuid 0 0
tmpfs /tmp tmpfs rw,nodev,nosuid,noexec,nr_inodes=5k,size=2G,mode=1777 0 0
tmpfs /dev/shm tmpfs   defaults,nodev,nosuid,nr_inodes=5k,mode=700,size=4G 0 0

But according to du, it is using half of my memory (which I understand is the default) instead of the size I meant to allocate to it.

 ~ df /tmp
Filesystem     1K-blocks  Used Available Use% Mounted on
tmpfs           65921428     0  65921428   0% /tmp

So is the size parameter simply not having any effect? I am working with Ubuntu 20.04

Edit I can mount it manually with

sudo mount -oremount,size=4G /tmp

When I do that /tmp is the expected 20.04 GB.

Edit: systemd status:

● tmp.mount - Temporary Directory (/tmp)
     Loaded: loaded (/etc/systemd/system/tmp.mount; enabled; vendor preset: enabled)
     Active: active (mounted) since Wed 2020-06-17 13:30:35 EDT; 8min ago
      Where: /tmp
       What: tmpfs
       Docs: https://systemd.io/TEMPORARY_DIRECTORIES
             man:file-hierarchy(7)
             https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
      Tasks: 0 (limit: 154317)
     Memory: 76.0K
     CGroup: /system.slice/tmp.mount

Jun 17 13:30:35 virtland systemd[1]: Mounting Temporary Directory (/tmp)... Jun 17 13:30:35 virtland systemd[1]: Mounted Temporary Directory (/tmp).

and journalctl -u tmp.mount

-- Reboot --
Jun 17 13:27:50 virtland systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting an>
Jun 17 13:27:50 virtland systemd[1]: Mounting Temporary Directory (/tmp)...
Jun 17 13:27:50 virtland systemd[1]: Mounted Temporary Directory (/tmp).
Jun 17 13:29:43 virtland systemd[1]: Unmounting Temporary Directory (/tmp)...
Jun 17 13:29:43 virtland systemd[1]: tmp.mount: Succeeded.
Jun 17 13:29:43 virtland systemd[1]: Unmounted Temporary Directory (/tmp).
-- Reboot --
Jun 17 13:30:35 virtland systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting an>
Jun 17 13:30:35 virtland systemd[1]: Mounting Temporary Directory (/tmp)...
Jun 17 13:30:35 virtland systemd[1]: Mounted Temporary Directory (/tmp).

Edit2: Setting the size of tmpfs for /dev/shm is working as expected:

# in fstab
tmpfs /dev/shm tmpfs   defaults,nodev,nosuid,nr_inodes=5k,mode=700,size=4G 0 0
tmpfs                                  13184288       2328   13181960   1% /run
tmpfs                                   4194304      41056    4153248   1% /dev/shm
tmpfs                                      5120          4       5116   1% /run/lock
tmpfs                                  65921432          0   65921432   0% /sys/fs/cgroup
tmpfs                                  65921432          0   65921432   0% /tmp
tmpfs                                  13184284          8   13184276   1% /run/user/1000

Also, it seems that the noexec option, although recommended by many security guides, is problematic because some programs (including apt) need to execute from /tmp. I understand that this can be gotten around, but I don't want to have to figure out every program that needs to be an exception.

1 Answers1

4

In Ubuntu 20.04 the unit tmp.mount originally lives in /usr/share/systemd/tmp.mount.

Modifications done by the system administrator (user) go into /etc/systemd/system/ which is probably why these have higher priority.

I'm not sure why your unit resides in /etc/systemd/system/.

My guess is that your tmp.mount unit in /etc/systemd/system/ is interfering with the entry in fstab.

To confirm this change the following line in /etc/systemd/system/tmp.mount

Options=mode=1777,strictatime,nosuid,nodev

into

Options=mode=1777,strictatime,nosuid,nodev,size=YOURSIZE

To get the behaviour you desire, disable and remove the unit defined in /etc/systemd/system/tmp.mount.

Oxyra
  • 116