Temporary filesystems

There are always some files that have a short lifetime or which have no significance after a reboot. Many such files are put into /tmp, and so it makes sense to keep these files from reaching permanent storage.

The temporary filesystem, tmpfs, is ideal for this purpose. You can create a temporary RAM-based filesystem by simply mounting tmpfs:

# mount -t tmpfs tmp_files /tmp

As with procfs and sysfs, there is no device node associated with tmpfs so you have to supply a place-keeper string, tmp_files in the preceding example.

The amount of memory used will grow and shrink as files are created and deleted. The default maximum size is half the physical RAM. In most cases, it would be a disaster if tmpfs grew that large, so it is a very good idea to cap it with a -o size parameter. The parameter can be given in bytes, KiB (k), MiB (m), or GiB (g), for example:

mount -t tmpfs -o size=1m tmp_files /tmp

In addition to /tmp, some subdirectories of /var contain volatile data and it is good practice to use tmpfs for them as well, either by creating a separate filesystem for each or, more economically, by using symbolic links. Buildroot does it this way:

/var/cache -> /tmp
/var/lock ->  /tmp
/var/log ->   /tmp
/var/run ->   /tmp
/var/spool -> /tmp
/var/tmp ->   /tmp

In the Yocto Project, /run and /var/volatile are tmpfs mounts with symbolic links pointing to them as shown here:

/tmp ->       /var/tmp
/var/lock ->  /run/lock
/var/log ->   /var/volatile/log
/var/run ->   /run
/var/tmp ->   /var/volatile/tmp
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.35.58