Hot answers tagged

49

Linux provides a tmpfs device which any user can use, /dev/shm. It is not mounted to a specific directory by default, but you can still use it as one. Simply create a directory in /dev/shm and then symlink it to wherever you want. You can give the created directory any permissions you choose, so that other users can't access it. This is a RAM backed ...


32

mount -o remount,size=5G /tmp/


26

From the Wikipedia page on the Filesystem Hierarchy Standard: Modern Linux distributions include a /run directory as a temporary filesystem (tmpfs) which stores volatile runtime data, following the FHS version 3.0. According to the FHS version 2.3, this data should be stored in /var/run but this was a problem in some cases because this directory isn't ...


19

You don't have to do all that, you can just mount /tmp as tmpfs by using a line like the following in /etc/fstab: tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0 You can also do it live (but bear in mind stuff that is currently in /tmp on your current filesystem will not be able to be accessed except through the inode and currently open file descriptors, so ...


18

What sets the size of the tmpfs? (On my machine it resides in /dev/shm) I can see its entry in /etc/fstab, but no notation of its size. The kernel documentation covers this underneath the mount options: size: The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs ...


17

/etc/default/tmpfs is for sysvinit, for systemd (Debian default since jessie) you only need to do: systemctl enable tmp.mount and on Debian Stretch cp /usr/share/systemd/tmp.mount /etc/systemd/system/ systemctl enable tmp.mount see changelog on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787542#74


15

You can resolve which filesystem a directory or file is on with the command df, and if you include the -T option, the output will include the filesystem type. $ df -T /tmp Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda3 ext4 38715020 5073600 31674780 14% / In the above example, the /tmp directory is on an ext4 filesystem, ...


14

/dev/shm is insecure ...on systems with active swap! Chances are very high your computer has it enabled. There is a better, secure, standard alternative — ramfs. You may want to use ramfs if you plan to use RAM-backed space to temporary store sensitive data, such as private keys, Bitcoin or Ethereum wallets and such. ramfs is better than tmpfs when ...


13

There is no difference betweem tmpfs and shm. tmpfs is the new name for shm. shm stands for SHaredMemory. See: Linux tmpfs. The main reason tmpfs is even used today is this comment in my /etc/fstab on my gentoo box. BTW Chromium won't build with the line missing: # glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for # POSIX shared memory (...


12

The Linux mount program interprets non-numeric parameters to uid and gid options as user and group names respectively. This applies to all filesystem types. It works both if the options come from the command line and if they come from /etc/fstab. Source: source (old (parse_opt), new (mnt_optstr_fix_gid, mnt_optstr_fix_uid)).


12

In the case of a temporary file, your example in the question would create it, then unlink it from the directory (making it "disappear"), and when the script closes the filedescriptor (probably upon termination), the space taken by the file would be reclaimable by the system. This is a common way to deal with temporary files in languages like C. It is, as ...


10

It's perfectly okay to use some directory in /run as long as you have the appropriate rights on it. In some modern distros, /tmp is already a virtual file system in memory or a symlink to a directory inside /run. If this is your case (you can check that in /etc/fstab, or typing mtab), you could use /tmp as your temporary directory. Also, don't get confused ...


10

Your system may have one already available; recent Linux systems based on Glibc always have a tmpfs mounted on /dev/shm. If your system doesn't have one or it's too small, then a filesystem not mounted by root pretty much means FUSE. On Ubuntu, you need to be in the fuse group to use FUSE. Looking through available FUSE filesystems, I see only Ramfuse, ...


10

It shouldn't be possible. swapon system call requires readpage and bmap (indirectly) calls being implemented by filesystem: http://lxr.free-electrons.com/source/mm/swapfile.c?v=4.0#L2412 if (!mapping->a_ops->readpage) { error = -EINVAL; goto bad_swap; } But none of them are implemented by tmpfs, such an entry is missing from ...


9

Some utilities traditionally used /var/run, other /run to store their process related material. When these were real on disc directories it did not matter too much that these were separate directories. Nowadays /run/ is often implemented as a tmpfs ( mount | fgrep run ) and data in those directories won't survive a reboot (which is a good thing). It makes a ...


9

I get the impression you have a few misconceptions regarding tmpfs. You might find it useful to read the kernel documentation on the topic; I’ll attempt to clarify things for you here. Your question’s title “tmpfs does not overflow to swap” doesn’t seem to reflect the actual contents of your question, but in any case tmpfs does use swap, although arguably ...


8

use ramfs instead of tmpfs. ramfs is a ramdisk (no swap) tmpfs can be both in your /etc/fstab: none /path/to/location ramfs defaults,size=512M 0 0 edit the size parameter to whatever you like but be careful not to exceed your actual amount of ram. NOTE: the use of a ramfs instead of tmpfs is not something i would recommend. you will find ...


8

Issuing # mount -o remount,size=4G,noatime /tmp when you need to do large file operations, adjusting size to fit the task, is one of the correct strategies in your situation, along with being the simplest solution. It will revert to normal on next reboot. More information, including how to make this permanent, can be found here: https://wiki.archlinux.org/...


7

Shared memory is using the 12GB. On your Linux release /dev/shm part of the /dev filesystem (on some releases, it has its own a dedicated file system mounted there). As shown by lsof, the sum is 12 GB: /dev/shm/foo5.44m is 6269616128 bytes /dev/shm/kdfoo.a4o is 6269616128 bytes Neither find nor ls can display theses files because they are unlinked (= ...


7

Technically, you can mount /var/log as tmpfs. You'd need to be sure that /var/log is mounted before syslogd starts, but that's the case by default on most distributions since they support /var on a separate partition. You'll obviously lose all logs, which I guarantee will be a problem one day. Logs are there for a purpose — there're rarely needed, but they'...


7

For all the tmpfs mounts, "Avail" is an artificial limit. The default size for tmpfs mounts is half your RAM. It can be adjusted at mount time. (man mount, scroll to tmpfs). The mounts don't share the same space, in that if you filled the /dev/shm mount, /dev would not show any more "Used", and it would not necessarily stop you from writing data to /dev ...


6

The data on a tmpfs (Temporary Filesystem) will not persist across reboots. If you only care to preserve the mountpoint, that will be dictated by your /etc/fstab definition.


6

If all goes well, your kernel should decide to "do the right thing" all by itself. It uses a lot of fancy heuristics to decide what to swap out and what to keep when there is memory pressure. Those heuristics have been carefully built by really smart people with a lot of experience in memory management and are already good enough that they're pretty hard to ...


6

I figured I could just test it, so I ran: sudo mount -o remount,size=2800M /run Worked like a charm: Filesystem Size Used Avail Use% Mounted on tmpfs 2.8G 45M 2.7G 2% /run So I filled it a bit: fallocate -l 1G /run/test.img fallocate -l 1G /run/test2.img fallocate -l 500M /run/test3.img Result: Filesystem Size Used Avail Use%...


6

Write a shell-function that will be executed when your script if finished. In the example below I call it 'cleanup' and set a trap to be executed on exit levels, like: 0 1 2 3 6 trap cleanup 0 1 2 3 6 cleanup() { [ -d $TMP ] && rm -rf $TMP } See this post for more info.


6

You can chdir into it and then remove it, provided that you don't try to use paths inside it afterwards: #! /bin/sh dir=`mktemp -d` cd "$dir" exec 4>file 3<file rm -fr "$dir" echo yes >&4 # OK cat <&3 # OK cat file # FAIL echo yes > file # FAIL I haven't checked, but it's most probably the same problem when using ...


6

The behavior you are showing seems to depend on the fs.protected_regular Linux kernel parameter, introduced along with fs.protected_fifos by this commit (converged in version 4.19, I believe), with the aim to fix security vulnerabilities. Excerpt of the commit message (emphasis mine): namei: allow restricted O_CREAT of FIFOs and regular files ...


5

You didn't specify the filesystem type - this is required. This is what you need: tmpfs /home/rkmax/Projects/webapp/app/cache tmpfs rw,size=500M,nosuid,uid=1000,gid=100 0 0


5

tmpfs is implemented as cache pages, so a low value for vm.swappiness will make tmpfs files more likely to be swapped out, since the system will favor stealing cache pages over application pages.


5

In general, no, filesystems can only be mounted by root. If you allow a user to place filesystems arbitrarily, that's essentially giving them root. (Easy way: mount one over /etc, put your own passwd and shadow there, su with the new root password you just created, unmount) If you want a tmpfs at a particular location, you could add it to /etc/fstab, with ...


Only top voted, non community-wiki answers of a minimum length are eligible