File Systems
A file system is a method and data structure that an operating system uses to
control how data is stored and retrieved. Without a file system, information
placed on a storage medium would be one large block of data with no way to tell
where one piece of information ends and the next begins. It organizes files and
directories, keeping track of their locations, sizes, permissions, and other
attributes.
1. File System Typessss
There's a wide variety of file system types, each designed with different goals in
mind (performance, reliability, specific device types, features, etc.). Here are
some of the most common and important ones:
• FAT (File Allocation Table):
o Types: FAT12, FAT16, FAT32.
o Characteristics: One of the oldest file systems. Simple and widely
compatible across many operating systems and devices (e.g., USB
drives, older cameras).
o Limitations: Lacks modern features like journaling, limited file size
(especially FAT16/12), and partition size limits. FAT32 extended
these, but still has a 4GB per-file limit.
o Use Case: Small removable media, bootable disks for older
systems.
• NTFS (New Technology File System):
o Characteristics: The standard file system for modern Windows
operating systems. It's robust, secure, and feature-rich.
o Features: Journaling (for data integrity), file and folder permissions
(ACLs), encryption (EFS), compression, hard links, symbolic links,
large file and partition support.
o Use Case: Windows system drives, large internal/external hard
drives.
• ext (Extended File System):
o Types: ext2, ext3, ext4.
o Characteristics: The standard file system family for Linux. Each
iteration improved upon the last.
o ext2: The original, non-journaling.
o ext3: Added journaling to ext2, significantly improving data
recovery after crashes.
o ext4: The current default for most Linux distributions. Further
improvements in performance, scalability, and features (e.g.,
larger file system limits, delayed allocation).
o Use Case: Linux system drives, servers, general Linux storage.
• XFS:
o Characteristics: A high-performance journaling file system.
Known for its scalability, especially with very large files and file
systems, and excellent parallel I/O capabilities.
o Use Case: High-performance computing, large databases, video
editing systems, often used in enterprise Linux environments.
• Btrfs (B-tree File System):
o Characteristics: A modern "copy-on-write" (CoW) file system for
Linux. Aims to address many limitations of older Linux file systems
and provide advanced features.
o Features: Snapshots (efficient point-in-time copies), checksums
(for data integrity), built-in RAID functionality, subvolumes,
compression.
o Use Case: Linux systems, experimental use, increasing adoption
in servers and desktops.
• APFS (Apple File System):
o Characteristics: The default file system for Apple products
(macOS, iOS, watchOS, tvOS). Optimized for flash/SSD storage.
o Features: Snapshots, space sharing, strong encryption, crash
protection.
o Use Case: Apple devices.
• HFS+ (Hierarchical File System Plus):
o Characteristics: The predecessor to APFS on Apple systems.
o Use Case: Older macOS versions, still seen on some older
external drives.
2. Device Naming and Spacing (Partitioning)
Before a file system can be created on a storage device (like a hard drive or SSD),
the device often needs to be partitioned. Partitioning divides a physical storage
device into one or more logical sections. Each partition can then be formatted
with a specific file system.
• Device Naming (Linux):
o Linux uses a consistent naming scheme for storage devices:
▪ /dev/sdX: For SATA/SCSI/USB drives. X is a letter (a, b, c,
etc.) for each physical drive (e.g., /dev/sda, /dev/sdb).
▪ /dev/sdXY: For partitions on those drives. Y is a number (1,
2, 3, etc.) for each partition on that drive (e.g., /dev/sda1,
/dev/sda2).
▪ Older IDE drives used /dev/hdX (e.g., /dev/hda).
▪ NVMe SSDs use /dev/nvmeXnYpZ (e.g., /dev/nvme0n1p1).
o Example: A system with one hard drive might have /dev/sda1 for
its root file system and /dev/sda2 for its swap space.
• Device Naming (Windows):
o Windows uses drive letters (e.g., C:, D:, E:).
o The primary system partition is typically C:. Other partitions or
drives are assigned subsequent letters.
o Windows also has a concept of hidden partitions (e.g., EFI System
Partition, Recovery Partition) which don't usually get drive letters.
• Spacing (Partitioning Schemes):
o MBR (Master Boot Record): An older partitioning standard.
Supports up to 4 primary partitions or 3 primary + 1 extended
partition (which can contain multiple logical partitions). Limited to
2TB per partition.
o GPT (GUID Partition Table): The modern standard, especially for
UEFI-based systems and drives larger than 2TB. Supports virtually
unlimited partitions (Windows typically limits to 128) and very
large partition sizes.
3. Mounting File Systems
In Linux and Unix-like operating systems, file systems are not directly accessible
by drive letter like in Windows. Instead, they must be mounted onto a specific
point in the existing file system tree (the directory structure). This mount point is
typically an empty directory.
• Concept: When a file system is mounted, its contents become
accessible through the mount point. It's like attaching a separate branch
to the main directory tree.
• Root File System (/): The first file system mounted (usually at boot) is the
"root" file system. All other file systems are then mounted as
subdirectories of the root.
• Automatic Mounting: Most modern operating systems automatically
mount necessary file systems (like the root, /boot, /home) during the boot
process, often configured in files like /etc/fstab (Linux) or by the system's
Plug and Play features (Windows).
• Manual Mounting (Linux):
o mount /dev/sdb1 /mnt/mydrive: Mounts the first partition of
/dev/sdb to the /mnt/mydrive directory.
o umount /mnt/mydrive: Unmounts the file system. It's crucial to
unmount before physically disconnecting removable media to
prevent data corruption.
• Mount Points Examples:
o /boot: Often a separate partition containing boot-related files.
o /home: User home directories.
o /var: Variable data like logs, mail queues.
o /tmp: Temporary files.
4. Monitoring Disk Space
Keeping an eye on disk space is vital for system stability and performance.
Running out of disk space can lead to system crashes, application failures, and
data loss.
• Linux Commands:
o df -h: (Disk Free) Displays free and used disk space for mounted
file systems in a human-readable format.
o du -sh /path/to/directory: (Disk Usage) Summarizes the disk usage
of a specific directory in human-readable format.
o lsblk: Lists block devices (disks and partitions).
o fdisk -l or parted -l: Shows partition tables.
• Windows Tools:
o File Explorer: Right-click on a drive and select "Properties" to see
used/free space.
o Disk Management: (search diskmgmt.msc) Provides a graphical
view of all disks and partitions, their sizes, and free space.
o Storage Sense: In newer Windows versions (Settings > System >
Storage), helps manage disk space by automatically deleting
temporary files.
5. Checking File System Integrity
File system integrity refers to the consistency and correctness of the data
structures that organize files and directories on a disk. Corruption can occur due
to sudden power loss, hardware failures, software bugs, or improper shutdowns.
• Purpose of Checks: To find and repair errors in the file system's metadata
(e.g., inconsistent file sizes, corrupted inode tables, unlinked blocks).
• Journaling: Modern file systems (NTFS, ext3/4, XFS, Btrfs, APFS) use
journaling. A journal is a log of changes that are about to be written to the
file system. In case of a crash, the system can replay the journal to bring
the file system back to a consistent state without a full scan, significantly
reducing recovery time and data loss.
• Tools for Checking/Repairing:
o Linux:
▪ fsck (File System Check): A general command that calls the
appropriate file system checker for the specified type (e.g.,
fsck.ext4, fsck.xfs). Important: File systems usually need to
be unmounted or in read-only mode to perform a safe fsck
operation, especially for write-intensive repairs. This often
means doing it from a live CD/USB or during boot.
▪ e2fsck (for ext2/3/4): The specific tool for ext file systems.
▪ xfs_repair (for XFS).
o Windows:
▪ chkdsk (Check Disk): The primary tool for checking and
repairing file system errors on NTFS and FAT volumes.
▪ chkdsk C: /f /r: /f fixes errors on the disk, /r locates bad
sectors and recovers readable information. Often requires a
reboot to run before Windows fully starts.
▪ You can also access chkdsk through File Explorer: Right-
click drive > Properties > Tools tab > Check button under
"Error checking."
Regular backups are the ultimate defense against data loss, but understanding
and maintaining file system integrity is crucial for day-to-day operation and quick
recovery from minor issues.