Linux Filesystem Organization
About the Linux Filesystem
The Linux filesystem organization has evolved over many years from the organization of Unix filesystems into a structure which supports all common cases and most corner cases. Much time and effort has been put into keeping the filesystem organization as simple as possible without sacrificing performance or navigability, or leaving needs unmet.
In order to prevent confusion and promote portability, a standard was created for the organization of the Linux filesystem. To ensure future portability of software created today, promote maintainability of software, and ensure proper utilization of available storage on an embedded machine, this standard should be followed as much as possible. This document covers parts of the standard and gives information about the customizations made to it by EMAC OE to accommodate embedded hardware. A link is provided to the standards document which covers the organization of the Linux filesystem at the end of this document.
Directories for Storing Files on a Machine
The standard ramdisk on an EMAC OE machine, used for storing temporary files of any kind, is located in:
Note that this directory should not be used directly unless none of the directories listed below fits the file type.
/tmp/ directory is the standard location to which temporary files should be written. In EMAC OE, the
/tmp/ directory is symbolically linked to a directory within the
/var/volatile/ RAM disk.
/var/lock directory contains lock files for concurrency between processes. Applications will often create an application-specific directory within this directory for their own use.
/var/log directory is for log files. The system logger on EMAC OE, by default, does not actually log to this directory because the log messages are cached in RAM by Busybox. For logging, an application can choose to either use the system logging facilities, or write to a file within this directory.
Files cached by an application, such as downloaded package files, should be stored in
/var/cache/. In general, this should only be for data the application can download or generate again. This directory is, by default, stored on a RAM disk.
Application State Information:
Files which store application state data should be stored in
/var/lib/. These are files which preserve state between invocations. On EMAC OE, this directory is stored on a RAM disk by default.
Daemons often need to store their process IDs in a location where utilities for starting and stopping a daemon can find them. In Linux, these are located in
/var/run/. This directory is automatically cleared at boot on any normal Linux system. On EMAC OE, this directory is stored on a RAM disk.
There are two different directories commonly used for installing custom written software. The directories listed here are given according to the Filesystem Hierarchy Standard, which is a standard by which most Linux systems conform.
This first directory is the standard location for executables which were written for a specific, individual machine:
The next directory is intended to be used for non-free (Company developed and owned) software:
Since the CompanyName is specific to the company which produced the software, this directory will often also contain some other standard subdirectories:
/opt/CompanyName/etc/ /opt/CompanyName/usr/ /opt/CompanyName/lib/ /opt/CompanyName/var/
Configuration files should either go in:
Or, if a directory in
/opt/ was created, in:
Scripts which are used to automatically start a program on boot and, if needed, stop it on shutdown, should be located here:
The Linux Foundation maintains the standards documents for the FHS, the Filesystem Hierarchy Standard, which dictates the directory layout for Linux and Unix systems. This document can be found on their website here: http://refspecs.linuxfoundation.org/fhs.shtml