Where does tmpfs come from and how is it mounted
They're all different filesystems. What they have in common is the filesystem type: they use the tmpfs
driver, which stores the data in memory¹. There's no ”super-tmpfs“ that they're all part of: all the instances are independent.
The “device column” shows tmpfs
because many configurations are unimaginative and use the same string for the device name as for the filesystem type. The tmpfs driver ignores the “device name” since it doesn't load data from anywhere.
These filesystems are created by mounting them and are destroyed by unmounting them. For example, the following command creates a tmpfs filesystem whose contents is just the root directory (all tmpfs filesystems start out this way), owned by root and with permissions rwxrwxrwt
, and whose maximum size is 100MB:
mount -t tmpfs -o size=100Mi,mode=1777 some_arbitrary_name /mnt
The mount calls are done in boot scripts. In the old days, you could find calls to the mount
command in shell scripts executed during startup. /var/lib
is unusual as a tmpfs mount point and may be configured via /etc/fstab
. These days, most if not all of them are mounted by systemd.
¹ That's virtual memory: RAM or swap.
Related videos on Youtube
Engineer999
Updated on September 18, 2022Comments
-
Engineer999 over 1 year
I am using a BeagleBone board with Linux.
When i type command "df -h" , I see tmpfs is mounted a few times.
Does this mean that all these entries get mounted at the same place, or at a different part of the tmpfs?
It brings me to another thing I don't quite understand. Where is this tmpfs file system actually created in the first place? I guess it happens when Linux boots. Should I be able to find a script which creates this filesystem ?
tmpfs 242.4M 0 242.4M 0% /dev/shm tmpfs 242.4M 8.3M 234.2M 3% /run tmpfs 242.4M 0 242.4M 0% /sys/fs/cgroup tmpfs 242.4M 36.0K 242.4M 0% /tmp tmpfs 242.4M 16.0K 242.4M 0% /var/volatile tmpfs 242.4M 16.0K 242.4M 0% /var/lib
-
Engineer999 almost 5 yearsOk thanks, but how does Linux know about the tmpfs to begin with? Not what gets mounted to it. I guess that with a partition in flash, Linux detects this from a partition table, but as tmpfs will be in RAM, I don't understand how Linux sets this up.
-
Gilles 'SO- stop being evil' almost 5 years@Engineer999 What do you mean by “know about the tmpfs”? There's nothing to know about until the instance is mounted. When the instance is mounted, the kernel knows everything there is to know about it: its mount point, its contents (which is nothing but the root directory, with permissions and ownership specified via mount options), and a little information about memory management such as the maximum size (again, passed via mount options).
-
Engineer999 almost 5 yearsah ok. I was getting confused. So tmpfs is actually a filesystem type , the same as EXT4 , FAT etc.