filesystem, formerly known as
, is a filesystem
keeping all files in virtual memory.
Everything in tmpfs is temporary in the sense that no files will be
created on any device. If you unmount a tmpfs instance,
everything stored therein is lost.
tmpfs puts everything into the kernel internal caches and grows and
shrinks to accommodate the files it contains and is able to swap
unneeded pages out to swap space. It has maximum size limits which can
be adjusted on the fly via
'mount -o remount ...'
If you compare it to
(which was the template to create
you gain swapping and limit checking. Another similar thing is the RAM
), which simulates a fixed size hard disk in physical
RAM, where you have to create an ordinary filesystem on top. Ramdisks
cannot swap and you do not have the possibility to resize them.
tmpfs has a couple of 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 instances the machine will deadlock
since the OOM handler will not be able to free that memory.
nr_blocks: The same as size, but in blocks of PAGECACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default
is half of the number of your physical RAM pages.
These parameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount.
To specify the initial root directory you can use the following mount
mode: The permissions as an octal number
uid: The user id
gid: The group id
These options do not have any effect on remount. You can change these
on a mounted
So the following mount command will give you a tmpfs instance on
which can allocate 12MB of RAM/SWAP and it is only accessible
mount -t tmpfs -o size=12M,mode=700 tmpfs /mytmpfs
In order to use a
option has to be
enabled for your kernel configuration. It can be found in the
configuration group. You can simply check if a running
by searching the contents of /proc/fileysystems
# grep tmpfs /proc/filesystems
In embedded systems
is very well suited to provide read and write
space (e.g. /tmp
) for a read-only root file system such
described in section
9.1.4. Compressed ROM Filesystem
One way to achieve this is to use symbolic links. The following code
could be part of the startup file /etc/rc.sh
of the read-only ramdisk:
# mkdir /tmpfs
mount -t tmpfs tmpfs /tmpfs
mkdir /tmpfs/tmp /tmpfs/var
# ln -sf /tmpfs/tmp /tmpfs/var /
The commented out sections will of course fail on a read-only root filesystem,
so you have to create the
mount-point and the symbolic links in your root
filesystem beforehand in order to successfully use this setup.