avatarKarthick Dk

Summary

The provided web content offers an in-depth guide to the Linux filesystem, detailing its structure, key directories, and management tools in accordance with the Filesystem Hierarchy Standard (FHS).

Abstract

The article "Day 3: Understanding the Linux Filesystem" is part of a 90-day DevOps series aimed at elucidating the intricacies of the Linux filesystem. It emphasizes the importance of the FHS, which dictates a consistent directory layout across all Linux distributions. The guide meticulously explains the root directory, essential user and system binaries, configuration files, device files, shared libraries, user home directories, variable data files, temporary files, boot loader files, optional software, mount points for external devices, process and kernel information, runtime data, and different types of filesystems like ext4, XFS, Btrfs, NFS, and Swap. It also introduces tools such as df and du for managing and interacting with filesystems, highlighting their practical applications through command-line examples. The conclusion underscores the necessity of understanding the filesystem for effective system management, configuration, and troubleshooting.

Opinions

  • The Linux filesystem is crucial for the consistent operation of applications and user interactions across various distributions.
  • The single unified directory tree in Linux, starting from the root directory (/), is superior to the drive letter system used in Windows for its simplicity and coherence.
  • The FHS ensures that all Linux distributions follow a standard directory structure, which is essential for user and application compatibility.
  • The article suggests that knowledge of the filesystem is not just beneficial but indispensable for system administrators and developers working with Linux.
  • The use of real-world command examples with df and du indicates that hands-on practice is encouraged for a deeper understanding of the filesystem.
  • The mention of advanced filesystem features in Btrfs, such as snapshots and subvolumes, implies that Linux continues to evolve and offer cutting-edge solutions for data management.

Day 3: Understanding the Linux Filesystem

Hi Mate !👋 Welcome to Day-3 of 90 days DevOps — series, in this blog we will discuss about file system of linux.

The Linux filesystem is one of the most crucial aspects of the operating system. It provides the structure that Linux uses to store and manage files, directories, and data. The Linux filesystem follows the Filesystem Hierarchy Standard (FHS), which defines a standard directory layout that all Linux distributions adhere to. This ensures that users and applications can interact with files in a consistent manner across various distributions.

In this guide, we’ll delve deep into the structure, components, and important directories of the Linux filesystem, providing a clear understanding of how data is organized and accessed.

1. Filesystem Basics ⁉️

A filesystem in Linux refers to how files are named, stored, and retrieved. It defines:

  • File: A collection of data, which could be plain text, code, images, or other data types.
  • Directory (or Folder): A container for files and other directories.
  • Mounting: The process of making a filesystem accessible at a certain point in the directory tree (a “mount point”).

Unlike Windows, which uses drive letters like C:, Linux doesn’t use letters to designate drives. Instead, all drives and partitions are mounted into a single unified directory tree, starting from the root directory (/).

2. The Root Directory (/)🧠

The root directory (/) is the top-most directory of the filesystem hierarchy. Everything on your Linux system is located under this directory, including files, programs, system libraries, and user data.

From here, a series of standard directories branch off, each serving a specific purpose. Below is a breakdown of the most important directories under the root.

3. Important Directories in the Linux Filesystem

/bin – Essential User Binaries

  • Contains essential command binaries (programs) that are needed for the system to boot and run in single-user mode. These binaries are available to all users.
  • Examples: ls, cat, mkdir, bash.

/sbin – System Binaries

  • Contains essential binaries for system administration. These are programs typically used by the root user for system maintenance and repair.
  • Examples: iptables, reboot, shutdown, mount, fsck.

/etc – Configuration Files

  • This directory contains all system-wide configuration files and shell scripts for starting or stopping system services.
  • Examples: /etc/passwd (user account information), /etc/fstab (filesystems and mount points).

/dev – Device Files

  • Contains device files that represent hardware and virtual devices on your system. In Linux, devices like hard drives, USBs, and terminals are treated as files.
  • Examples: /dev/sda1 (first partition on the first hard drive), /dev/tty1 (terminal device).

/lib – Essential Shared Libraries

  • Contains shared libraries needed by the binaries in /bin and /sbin. These libraries are somewhat similar to DLL files in Windows.
  • Example: /lib/x86_64-linux-gnu/libc.so.6 (standard C library).

/usr – User Binaries and Read-Only Data

  • /usr stands for user system resources. It contains most user binaries, libraries, documentation, and other resources not needed for booting or system repair.
  • /usr/bin: Non-essential user command binaries (e.g., applications like git, python).
  • /usr/sbin: Non-essential system binaries used by administrators.
  • /usr/lib: Libraries for /usr/bin and /usr/sbin binaries.
  • /usr/share: Architecture-independent data like icons, documentation, and locales.

/home – User Home Directories

  • This directory holds the personal directories for all users. Each user gets their own folder under /home, where they can store files, documents, and configuration settings.
  • Example: /home/username/ (the home directory for the user username).

/var – Variable Data Files

  • /var stands for variable. It contains files that are expected to grow in size, such as logs, caches, and temporary files.
  • /var/log: Log files from services such as syslog, auth.log.
  • /var/lib: Persistent data for applications (like databases).
  • /var/cache: Cache data for applications.
  • /var/tmp: Temporary files preserved between reboots.

/tmp – Temporary Files

  • This directory is used for storing temporary files that are created by programs and processes. The contents of /tmp are often cleared upon reboot.
  • Example: Applications might store temporary data in /tmp during operation.

/boot – Boot Loader Files🧩

  • Contains all the files required for the boot process, including the Linux kernel, initial RAM disk image (initrd), and the bootloader (like GRUB).
  • Example: /boot/vmlinuz (the Linux kernel image).

/opt – Optional Software

  • This directory is used for installing optional software packages. It’s often used for third-party or add-on software that doesn’t conform to the standard filesystem hierarchy.
  • Example: /opt/google (Google Chrome installation).

/root – Root User’s Home Directory

  • This is the home directory for the root (superuser) account. It’s different from the /home directory, which contains user-specific directories for non-root users.

/mnt and /media – Mount Points for External Devices

  • /mnt is used to temporarily mount filesystems, such as external hard drives or network shares.
  • /media is used to mount removable media such as USB drives, CDs, or DVDs.
  • Example: /media/usb (automatically created when a USB drive is mounted).

/proc – Process and Kernel Information

  • This directory contains information about the running system and processes. It’s a virtual filesystem that provides an interface to the kernel.
  • Example: /proc/cpuinfo (information about the CPU), /proc/meminfo (information about system memory).

/sys – Kernel and System Information

  • Like /proc, /sys is a virtual filesystem that provides information about the system and allows interaction with kernel devices.
  • Example: /sys/class/net/ (network device information).

/run – Runtime Data

  • Contains information about the running system, such as information for currently running services and daemons.
  • Example: /run/sshd.pid (stores the process ID of the SSH daemon).

4. Linux Filesystem Types🗃️

In Linux, several types of filesystems can be used depending on the specific use case:

  1. ext4 (Fourth Extended Filesystem):
  • This is the most common filesystem in Linux today, providing good performance and reliability.
  • Extends features from ext3 such as larger file sizes, better performance, and journaling (which helps in data recovery).

2. XFS:

  • A high-performance filesystem used in enterprise environments. Known for scaling to large storage systems.

3. Btrfs:

  • A modern filesystem that provides features like snapshots, subvolumes, and dynamic space allocation. It’s designed for scalability and advanced data management.

4. NFS (Network File System):

  • Used for accessing files over a network. It allows different machines to share files as though they were on the local filesystem.

5. Swap:

  • Not exactly a filesystem, but an area on the disk that Linux uses as virtual memory when the system’s RAM is fully utilized.

7. Filesystem Tools

Linux provides various tools for managing and interacting with filesystems:

  • df: Displays disk space usage.
# View the filesystem in Human readble format
df -hT

# Veiw the directory structure
tree 

# List the largest files in the directory
du -sh /var/log | sort -h
  • The -h flag displays disk space in a human-readable format.
  • du: Shows the disk usage of files and directories.

Conclusion

Understanding the Linux filesystem is essential for effectively managing a Linux system. By mastering the structure and key directories, you can confidently navigate, configure, and manage both system-level and user-level files. Whether you’re administering a server, managing storage, or troubleshooting system issues, a strong grasp of the filesystem ensures you’re well-equipped to handle your Linux environment.

Devopsin90days
AWS
DevOps
Linux
Filesystem
Recommended from ReadMedium