I mount /tmp
on tmpfs
using:
sudo systemctl enable tmp.mount
sudo systemctl start tmp.mount
But this way /tmp
takes up all the free RAM:
$ df -h /tmp
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.9G 12K 3.9G 1% /tmp
$
How do I tell systemd tmp.mount to use only 1G? I know I can alternatively not use systemd and manually add an entry to /etc/fstab
and specify the size there. But I don't want to do that. I want to use systemd backed tmpfs.
Best Answer
The systemd way of overriding
tmp.mount
, or extending it, is to add a local override in/etc/systemd/system
. You can either copy the existingtmp.mount
(from/lib/systemd/system
or/usr/share/systemd
probably) and edit the copy, or better yet, add configuration snippets to only change the mount options:/etc/systemd/system/tmp.mount.d
inside that directory, add a file called
options.conf
containingNote that
systemd.mount
still says thatso you may just want to do that. In fact, this is the recommended approach to change mount options for any of systemd’s “API file systems”:
API file systems include the following:
/sys
,/proc
,/dev
,/run
,/tmp
,/sys/fs/cgroup
,/sys/kernel/security
,/sys/kernel/debug
,/sys/kernel/config
,/sys/fs/selinux
,/dev/shm
,/dev/pts
,/proc/sys/fs/binfmt_misc
,/dev/mqueue
,/dev/hugepages
,/sys/fs/fuse/connections
,/sys/firmware/efi/efivars
. systemd ensures they are mounted even if they are not specified in/etc/fstab
or a mount unit.