Skip to content
Day 2: File Systems and Lvm

Day 2: File Systems and Lvm

There are 2 meanings of file system under Linux:

1. The Storage Format (The Physical View):

2. The Directory structure (logical view) aka Filesystem Hierarchy Standard

(FHS).

The Filesystem Hierarchy Standard (FHS) is a formal specification that defines the main directories, their locations, and what types of files they should contain on a Linux (or Unix-like) operating system.

The FHS doesn’t just list directories - it specifies what must/may go in each, and sometimes what must not.

DirectoryFHS Rule (simplified)
/The root directory. Must contain /bin, /boot, /dev, /etc, /home, /lib, /media, /mnt, /opt, /proc, /root, /run, /sbin, /srv, /sys, /tmp, /usr, /var.
/binEssential user command binaries (e.g., ls, cp, sh). Must be available in single-user mode. Cannot have subdirectories.
/bootStatic files for the boot loader (kernel, initrd).
/devDevice files. Managed by kernel/devfs or udev.
/etcHost-specific system configuration. No binary executables allowed.
/homeUser home directories (except root). Optional on small systems, but standard.
/libEssential shared libraries and kernel modules for /bin and /sbin.
/mediaMount point for removable media (CD-ROM, USB).
/mntTemporary mount point for file systems (manual mounting).
/optAdd-on application software packages (static, self-contained). Each package gets its own subdirectory (/opt/package/).
/procVirtual file system for process and kernel information.
/rootHome directory for the root user. Must not be under /home.
/runRuntime variable data (since boot). System daemons store PID files, sockets here.
/sbinSystem binaries for administration (e.g., fdisk, mount). Only root uses them typically.
/srvData for services provided by the system (e.g., /srv/www/ for web server, /srv/ftp/).
/sysVirtual file system for kernel objects (devices, drivers).
/tmpTemporary files. Usually cleared on reboot. Sticky bit set.
/usrSecondary hierarchy - read-only, sharable user data. Contains most user commands, libraries, documentation. Historically “user system resources”. Must have /usr/bin, /usr/lib, /usr/local, /usr/share, etc.
/varVariable data - files that change size (logs, spool, cache, lock files).

Linux uses a virtual directory structure. The virtual directory contains a single base directory - root directory /.

mkfs - ("make filesystem") is used to format a storage partition with a specific file system type.

Basic syntax:

mkfs [options] <device>

Common usage:

  • mkfs -t ext4 /dev/sdb1 - formats /dev/sdb1 as ext4.
  • mkfs.ext4 /dev/sdb1 - formats /dev/sdb1 as ext4.
  • mkfs.xfs /dev/sdb1 - formats as XFS.
  • mkfs.vfat /dev/sdb1 - formats as FAT32.
  • mkfs.ntfs /dev/sdb1 - formats as NTFS.

Key points:

  • Destroys all existing data on the target partition - use with extreme caution.
  • Typically run as root (with sudo).
  • The device must be unmounted before formatting.
  • Many distributions provide mkfs as a wrapper for file‑system‑specific commands (mkfs.ext4, mkfs.btrfs, etc.).

Example:

sudo umount /dev/sdb1
sudo mkfs.ext4 /dev/sdb1
sudo mount /dev/sdb1 /mnt/mydrive

mount - attach a file system to the directory tree

Basic syntax:

mount [options] <device> <directory>

Common usage:

  • mount /dev/sdb1 /mnt/usb - mounts /dev/sdb1 at /mnt/usb
  • mount -t ext4 /dev/sda2 /home - explicitly specifies file system type
  • mount -a - mounts all file systems listed in /etc/fstab

Key points:

  • The target directory (mount point) must already exist.
  • Usually run as root (or with sudo).
  • Without arguments, mount lists all currently mounted file systems.
  • Many modern systems auto‑mount removable media (so you rarely need manual mount for USB drives).

Example:

sudo mkdir -p /mnt/data
sudo mount /dev/sdc1 /mnt/data

umount - detach a mounted file system

Basic syntax:

umount <device_or_directory>

Common usage:

  • umount /mnt/usb - unmounts by mount point
  • umount /dev/sdb1 - unmounts by device name

Key points:

  • You cannot unmount a file system that is currently in use (open files, active processes).
  • Use lsof or fuser to find what’s using it.
  • Add -l (lazy unmount) to detach now and clean up later, or -f (force) for stubborn cases.

Example:

sudo umount /mnt/data

/etc/fstab

A system configuration file that defines how and where file systems are automatically mounted at boot time or when mount -a is run.

Format (one line per file system):
<device> <mount_point> <fs_type> <options> <dump> <pass>

Example line:
/dev/sda1 /boot ext4 defaults 0 2

Column meanings:

  1. Device - Partition (e.g., /dev/sda1), UUID (UUID=...), or network share.
  2. Mount point - Directory where it will be attached (must exist).
  3. File system type - ext4, xfs, ntfs, swap, auto.
  4. Options - defaults, ro (read‑only), noauto (don’t auto‑mount), user (allow ordinary users to mount), etc.
  5. Dump - Backup flag (usually 0).
  6. Pass - Boot‑time fsck order (0 = skip, 1 = root, 2 = other file systems).

Key points:

  • Read by mount -a and the init system at boot.
  • Mistakes here can make your system fail to boot.
  • Using UUID= is preferred over device names (/dev/sda1) because device names can change.
  • After editing, run mount -a to test for errors without rebooting.

Example typical entry:

UUID=1234-abcd /home ext4 defaults 0 2

  • df – Reports disk space usage of mounted file systems (e.g., df -h for human‑readable sizes). Shows total, used, free space, and mount points.

  • du – Estimates file and directory space usage (e.g., du -sh /home). Useful for finding large folders. -s = summary, -h = human‑readable.

  • iostat – Reports CPU and I/O statistics for devices and partitions. Helps identify disk bottlenecks. Often used with -x for extended device info.

  • lsblk – Lists information about all available block devices (disks, partitions, LVM). Shows tree‑like output, sizes, mount points, and UUIDs.

  • fsck – Checks and repairs file system consistency (e.g., fsck /dev/sda1). Must usually be run on unmounted file systems. Rarely run manually today because boot‑time checks handle most issues.


Storage alternatives

  • Multipath – Provides redundant physical paths (cables, controllers) between the server and a storage device (e.g., SAN). If one path fails, I/O automatically switches to another. Improves reliability and load‑balancing. Managed by multipathd in Linux.

  • Logical Volume Manager (LVM) – A software layer that abstracts physical disks into flexible storage pools. Lets you create, resize, and move logical volumes without repartitioning. Components: Physical Volumes (PVs) → Volume Group (VG) → Logical Volumes (LVs).

  • RAID (Redundant Array of Independent Disks) – Combines multiple physical disks into one logical unit for redundancy, performance, or both. Common levels: RAID 0 (striping, no redundancy), RAID 1 (mirroring), RAID 5 (striping with parity), RAID 10 (mirrored stripes). Can be hardware‑ or software‑based (e.g., mdadm in Linux).