✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Base Filesystem Layout

Alpine Linux's Base Filesystem Layout organizes core system files for minimal footprint and efficient operation in containers and embedded systems.

Base Filesystem Layout defines the standardized organization and hierarchy of directories and files that form the fundamental structure of an Alpine Linux installation. It provides a minimal and efficient arrangement designed to support system booting, administration, and runtime operations while maintaining simplicity and security consistent with Alpine Linux's lightweight philosophy.

The base filesystem layout includes essential directories, each serving specific purposes related to system configuration, user data, device files, temporary storage, and executable binaries. This layout adheres to the Filesystem Hierarchy Standard (FHS) where applicable but is tailored to Alpine's musl libc and busybox environment to minimize footprint and maximize performance.


Core Directories and Their Roles

  • / (Root directory)
    The top-level directory that contains all other files and directories. It is the starting point of the filesystem hierarchy.

  • /bin
    Contains essential user command binaries needed during boot and for single-user mode, such as sh, ls, cp, and other fundamental utilities. In Alpine, these are typically symlinked or provided by busybox for minimal size.

  • /sbin
    Holds essential system binaries used primarily by the system administrator for maintenance and system repair tasks, for example, fsck and ifconfig.

  • /etc
    Contains system-wide configuration files. This directory is critical for system initialization and service configuration. Alpine stores network setup, package manager configuration, and system initialization scripts here.

  • /lib
    Contains essential shared libraries required by binaries in /bin and /sbin. Because Alpine uses musl libc instead of glibc, this directory contains musl libraries and kernel modules.

  • /libexec
    Used for internal binaries and helper executables that are not intended to be executed directly by users or administrators.

  • /usr
    Contains read-only user utilities and applications. It is further subdivided into:

    • /usr/bin for non-essential user commands.
    • /usr/sbin for non-essential system binaries.
    • /usr/lib for libraries supporting /usr/bin and /usr/sbin.
    • /usr/share for architecture-independent data like documentation and icons.
  • /var
    Contains variable data files such as logs, spool files, caches, and transient runtime data. Examples include /var/log, /var/run, and /var/cache.

  • /tmp
    A directory for temporary files that can be deleted upon reboot. It is typically mounted as a tmpfs (in-memory filesystem) for performance and security.

  • /root
    The home directory for the root user, separate from normal users’ home directories in /home.

  • /home
    Contains user home directories for non-root users.

  • /dev
    Contains device files representing hardware and virtual devices. Alpine often uses devtmpfs to dynamically manage this directory.

  • /proc
    A virtual filesystem that exposes kernel and process information, used for monitoring and interacting with running processes and kernel parameters.

  • /sys
    Another virtual filesystem exposing kernel information, hardware devices, and drivers, providing interfaces to kernel subsystems.

  • /mnt and /media
    Standard mount points for temporarily mounting filesystems and removable media, respectively.


Special Considerations in Alpine Linux

  • Alpine emphasizes a minimal base system, so many directories may initially be empty or contain only essential files.
  • BusyBox provides many standard Unix utilities in a single binary, reducing the number of files under /bin and /sbin.
  • Musl libc replaces glibc, so /lib contains musl-specific libraries, often with a smaller footprint.
  • Configuration management and package handling are simplified; /etc contains Alpine-specific files such as /etc/apk/repositories for package sources.
  • Alpine uses OpenRC for initialization, so relevant scripts and service files are located under /etc/init.d and /etc/conf.d.

Directory Summary Table

DirectoryPurposeNotes
/Root of the filesystemContains all other directories
/binEssential user commandsBusyBox utilities often reside here
/sbinEssential system binaries for adminSystem repair and boot utilities
/etcHost-specific configuration filesAlpine-specific configs included
/libShared libraries and kernel modulesContains musl libc libraries
/libexecInternal helper binariesNot intended for user execution
/usrSecondary hierarchy for user programs and dataRead-only, large software stored
/varVariable data files like logs, spools, cachesPersistent runtime data
/tmpTemporary filesTypically tmpfs mounted
/rootRoot user’s home directorySeparate from regular users
/homeUser home directoriesUser data and personal files
/devDevice nodesManaged dynamically by devtmpfs
/procKernel and process informationVirtual filesystem
/sysKernel subsystem interfaceVirtual filesystem
/mntMount point for temporary mountsFor manual mounting
/mediaMount point for removable mediaRemovable devices like USB drives

Filesystem Mount Points and Initialization

The base filesystem layout is supported by mounting virtual filesystems at boot time:

  • /proc is mounted as a procfs providing process and kernel info.
  • /sys is mounted as sysfs exposing device and kernel interfaces.
  • /dev is mounted as devtmpfs for dynamic device nodes.
  • /tmp is optionally mounted as tmpfs for volatile temporary storage.

These mounts are essential for system functionality and are configured via initialization scripts and /etc/fstab.


Security and Permissions

The base filesystem layout enforces strict permissions on critical directories:

  • /etc and /root are typically restricted to root user only.
  • /tmp and /var/tmp allow broader write access but have sticky bits set to prevent unauthorized deletion of other users’ files.
  • Device files in /dev have permissions managed dynamically to reflect hardware security needs.

Summary

The Base Filesystem Layout in Alpine Linux is a carefully constructed hierarchy that balances minimalism, clarity, and functionality. It provides a solid foundation for the operating system by organizing executables, libraries, configuration files, user data, and system information in a way that supports Alpine's design goals of simplicity, security, and resource efficiency. Understanding this layout is essential for system administrators and developers working with Alpine Linux to manage, customize, and troubleshoot the system effectively.