Solved

Curious about tmpfs filesystem

Posted on 2010-11-21
10
1,449 Views
Last Modified: 2012-05-10
Hello,

Please look at the below details of a RHEL 5.3 server. I wish to know about this 'tmpfs' filesystem. Why do a Linux server have this filesystem and it mounted on /dev/shm?  When I checked in /dev/shm, nothing is there?  Please explain in detail. Thanks.

[root@pmclsb01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       51G  7.8G   40G  17% /
/dev/xvda1             99M   19M   75M  21% /boot
tmpfs                 3.1G     0  3.1G   0% /dev/shm                   <------ ?
[root@pmclsb01 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          6144       4561       1582          0        179       4174
-/+ buffers/cache:        207       5936
Swap:         8159          0       8159
[root@pmclsb01 ~]# cd /dev/shm
[root@pmclsb01 shm]# ls
[root@pmclsb01 shm]# du -sh .
0       .
[root@pmclsb01 shm]#
[root@pmclsb01 shm]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
[root@pmclsb01 shm]#
0
Comment
Question by:ashsysad
  • 6
  • 3
10 Comments
 
LVL 35

Accepted Solution

by:
torimar earned 500 total points
Comment Utility
Tmpfs is a filesystem for temporary storage which does not reside on the physical disk, but in the computer's memory (RAM).
In the Linux device system it is often bound to /dev/shm simply because its name once used to be SHMFS (=Shared Memory File System).

More here: http://en.wikipedia.org/wiki/Tmpfs
0
 

Author Comment

by:ashsysad
Comment Utility
Thanks Torimar. I did a small testing on 'tmpfs' filesystem and looks like even a normal user can create files in /tmp or /dev/shm filesystem. If thats being the case, can't a hacker or a normal user (who has an account in the server) simply do continous write on thise filesystem and crash the server by filling the entire RAM space ?
0
 

Author Comment

by:ashsysad
Comment Utility
I checked the size of tmpfs in few servers and noticed the value various in each servers.

[adevaraju@orallm06-tx ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      810G  545G  224G  71% /
/dev/sda1              99M   16M   79M  17% /boot
tmpfs                  17G     0   17G   0% /dev/shm

[adevaraju@sysllm01 shm]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      130G   51G   73G  42% /
/dev/sda1              99M   42M   53M  45% /boot
tmpfs                 4.0G  0     4.0G  0% /dev/shm


I created files more than 4 GB in the second server and made it full. But still the server runs fine.

[adevaraju@sysllm01 tmp]$ mv testfile /dev/shm/
mv: writing `/dev/shm/testfile': No space left on device
[adevaraju@sysllm01 tmp]$ free -m
             total       used       free     shared    buffers     cached
Mem:          8116       7832        284          0         93       6905
-/+ buffers/cache:        832       7283
Swap:         1983          0       1983
[adevaraju@sysllm01 tmp]$
[adevaraju@sysllm01 shm]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      130G   51G   73G  42% /
/dev/sda1              99M   42M   53M  45% /boot
tmpfs                 4.0G  4.0G     0 100% /dev/shm                   <-- Its full but server is running.


My simple question is, Is it advisable to save files in /tmp or /dev/shm filesystem?  In my organization, many users are habitual to store the file under /tmp.
0
 
LVL 35

Expert Comment

by:torimar
Comment Utility
No.
The size of tmpfs may dynamically grow or shrink according to requirements, but for normal users it cannot grow beyond the size specified in fstab (which in your case is 3.1 GB). Only root is able to increase that limit via a mount order.

0
 
LVL 35

Expert Comment

by:torimar
Comment Utility
The above comment answers your first question.

As to the next question:
The size of tmpfs may vary depending on the amount of RAM on a server. Once full, swap space is used to accommodate for additional needs.

You should never save (or let users save) anything of importance in the /tmp folder. It is not meant for persistent storage in any way.
If your /tmp folder is set to use the tmpfs filesystem or the /dev/shm device, you not only should not, but simply cannot use it for "saving" anything. Reboot, and all will be lost.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:ashsysad
Comment Utility
Can I know how can I make the /tmp folder to use the tmpfs filesystem or /dev/shm device?
0
 

Author Comment

by:ashsysad
Comment Utility
Please ignore my last question. I guess i got the answer. So in fstab if we mount tmpfs filesystem on /tmp, then /tmp will use RAM space for saving the files, which isn't acceptable.
0
 

Author Closing Comment

by:ashsysad
Comment Utility
Thanks for clarifying me about tmpfs filesystem.
0
 
LVL 9

Expert Comment

by:expert_tanmay
Comment Utility
You might have also come across a line as given below
none                 1004M     0 1004M   0% /dev/shm
this is the partition where Linux keeps the swap(virtual memory) file system. For every device on Linux a interface is created like /dev/... They allow software to interact with a device driver using standard input/output  system calls, which simplifies many tasks.

Similarly
tmpfs                 3.1G     0  3.1G   0% /dev/shm
/dev/shm is the device interface for reading or writing tmp files. Tmpfs does not use traditional non-volatile media to store file data; instead, tmpfs files exist solely in virtual memory maintained by the Linux kernel. Because tmpfs file systems do not use dedicated physical memory for file data but instead use VM system resources and facilities, they can take advantage of kernel resource management policies.

regards
0
 

Author Comment

by:ashsysad
Comment Utility
Thanks Tanmay !
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now