14

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
  • 1,151
  • 2
    Engineer999, I can see you rolled back my minor edit. Can you please explain why you don't want the helpful heading shown which is always shown as the first row of the output of df -h? It helps everyone identify what each column means. – Gabriel Staples Oct 20 '21 at 14:27
  • To anyone not intimately familiar with the output of df -h, here are the column headings of the above output: Filesystem Size Used Avail Use% Mounted on. – Gabriel Staples Oct 20 '21 at 14:28

1 Answers1

10

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.

  • Ok 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. – Engineer999 Jun 03 '19 at 20:53
  • @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). – Gilles 'SO- stop being evil' Jun 03 '19 at 20:59
  • 3
    ah ok. I was getting confused. So tmpfs is actually a filesystem type , the same as EXT4 , FAT etc. – Engineer999 Jun 03 '19 at 21:45
  • Since tmpfs stores the data in memory, I assume it would be faster to grep on a tmpfs filesystem than other filesystems, or am I wrong? – Edgar Magallon May 25 '23 at 20:53
  • 1
    @EdgarMagallon tmpfs stores the data in virtual memory, but that can go to swap, and conversely a disk file that's been read recently might still be in the cache. So tmpfs isn't necessarily faster. (I'd expect tmpfs writes to be a little faster, because they don't have to worry about data consistency in case of a power failure.) – Gilles 'SO- stop being evil' May 25 '23 at 21:05