Chapter 5: Linux Filesystem Administration Study Notes

Device Files and the /dev Directory Structure

  • Device File Concept and Role

    • Most physical and virtual hardware devices on a Linux operating system are represented as device files residing in the /dev directory.

    • Device files specify to the operating system the precise mechanisms and protocols required to transfer data to and from the underlying hardware.

    • Linux assigns one unique device file per system device.

  • Device Classifications

    • Block Devices

    • Block devices transfer data in fixed chunks or blocks rather than sequential single bytes.

    • They utilize physical RAM to buffer transfers, resulting in substantially faster throughput than character devices.

    • Storage mediums such as Compact Discs (CDs), Digital Versatile Discs (DVDs), USB flash memory drives, Hard Disk Drives (HDDs), Solid-State Drives (SSDs), and loopback interfaces are classified as block devices.

    • Character Devices

    • Character devices transfer data stream-style, character-by-character (byte-by-byte).

    • They do not buffer transfers through physical memory blocks.

    • Terminal lines, serial ports, mice, parallel ports, and tape drives are classified as character devices.

  • Device File Identification Attributes

    • Major Number

    • A numeric value within the device file metadata that points directly to the corresponding device driver compiled into or loaded by the Linux kernel.

    • Devices of the same general hardware class or driver type share identical major numbers.

    • Minor Number

    • A numeric value that uniquely distinguishes a specific device or sub-device from others utilizing the same driver or major number.

    • Device Identity Triplet

    • A device file's complete physical identity is uniquely established by three parameters: its file type (block b or character c), its major number, and its minor number.

  • Device File Management Tools and Inspection

    • /proc/devices: A pseudo-filesystem file containing the real-time list of all character and block devices currently recognized by the running Linux kernel along with their major numbers.

    • mknod <name> <type> <major> <minor>: Command utilized to recreate missing or corrupted device files manually by specifying the desired path, file type (b or c), major number, and minor number.

    • lsblk: Displays comprehensive hierarchical information about all currently recognized block storage devices.

  • Standard Device File Reference

    • /dev/hda1: First partition on the primary master PATA (IDE) hard disk drive or SSD (Block).

    • /dev/hdb1: First partition on the primary slave PATA hard disk drive or SSD (Block).

    • /dev/hdc1: First partition on the secondary master PATA hard disk drive or SSD (Block).

    • /dev/hdd1: First partition on the secondary slave PATA hard disk drive or SSD (Block).

    • /dev/sda1: First partition on the first SATA, SCSI, or SAS hard disk drive or SSD (Block).

    • /dev/sdb1: First partition on the second SATA, SCSI, or SAS hard disk drive or SSD (Block).

    • /dev/nvme0n1p1 or /dev/nvme0p1: First partition on the first namespace of the first Non-Volatile Memory Express (NVMe) SSD (Block).

    • /dev/nvme1n1p1: First partition on the first namespace of the second NVMe SSD (Block).

    • /dev/sr0: First writable SATA/SCSI CD or DVD optical device on the system (Block).

    • /dev/cdrom: A symbolic link pointing to the primary active optical CD/DVD device file (e.g., /dev/sr0).

    • /dev/loop or /dev/loop0: The primary loopback interface device utilized for mounting file-backed disk images (Block).

    • /dev/tty1: First local virtual terminal console on the system, accessed via keyboard combination Ctrl+Alt+F1 (Character).

    • /dev/tty2: Second local virtual terminal console on the system, accessed via Ctrl+Alt+F2 (Character).

    • /dev/ttyS0: First serial communications port on the system, equivalent to COM1 (Character).

    • /dev/ttyS1: Second serial communications port on the system, equivalent to COM2 (Character).

    • /dev/psaux: Hardware PS/2 auxiliary port typically mapped to a PS/2 mouse (Character).

    • /dev/lp0: First parallel printer port on the system, equivalent to LPT1 (Character).

    • /dev/null: Virtual bit-bucket character device file representing nothingness; all data written to this file is instantly discarded, and reads return an immediate End-Of-File (EOF).

    • /dev/st0: First SCSI magnetic tape storage device on the system (Character).

    • /dev/bus/usb/*: Direct hardware USB controller buses and interface nodes (Character or Block depending on hardware functionality).

Filesystem Architecture and Supported Types

  • Core Architecture of Linux Filesystems

    • A filesystem defines the structural organization, indexing, and allocation methods imposed upon raw physical storage sectors to manage the storage and retrieval of user data.

    • Storage devices or partitions must be formatted with a filesystem prior to operating system usage.

    • All standard Linux filesystems share three fundamental architectural layers:

    • Superblock: Contains comprehensive global filesystem metadata, including filesystem size, block allocation size, total inode counts, free block and inode counts, mount counts, and filesystem status flags.

    • Inode Table: An indexed array of individual Information Nodes (inodes). Each inode stores metadata for a unique file or directory—such as file type, access permissions, user ownership (UID\text{UID}), group ownership (GID\text{GID}), timestamps, file byte size, and pointers to the disk data blocks hosting the file content (excluding the filename).

    • Data Blocks: The actual allocation units of storage on the disk where raw file data payload and directory file lists are stored.

    • Virtual Filesystems (Pseudo-Filesystems): Special in-memory filesystems populated dynamically by the Linux kernel (such as /proc and /sys) designed strictly for exposing kernel parameters, hardware data, and process tracking.

  • Comprehensive Filesystem Implementations

    • ext2 (Second Extended Filesystem)

    • The traditional native Linux filesystem derived from the original extended filesystem (ext), which itself superseded the Minix filesystem.

    • Supports native Linux permissions and POSIX Access Control Lists (ACLs).

    • Does not incorporate journaling; ungraceful shutdowns necessitate lengthy manual filesystem integrity scans.

    • ext3 (Third Extended Filesystem)

    • An evolution of ext2 that introduces a transactional journal.

    • Dramatically accelerates reboot, startup, and recovery times following crashes because uncommitted transactions can be replayed or rolled back without scanning the entire disk.

    • ext4 (Fourth Extended Filesystem)

    • Advanced iteration of the extended filesystem family that expands support for massive storage volumes and single-file sizes.

    • Introduces extents (reducing metadata overhead for large contiguous allocations), multiblock allocation, delayed allocation, and significant speed improvements.

    • btrfs (B-tree File System)

    • Modern copy-on-write (CoW\text{CoW}) filesystem tailored for enterprise-scale storage infrastructures.

    • Natively implements inline data compression, dynamic subvolumes, storage quotas, point-in-time writable snapshots, and multi-device drive pooling/spanning.

    • xfs (X File System)

    • High-performance 64-bit journaling filesystem originally engineered by Silicon Graphics (SGI\text{SGI}) for IRIX UNIX.

    • Highly optimized for parallel input/output processing and rapid creation and deletion of massive numbers of files.

    • zfs (Zettabyte File System)

    • High-capacity filesystem and integrated volume manager developed by Sun Microsystems.

    • Incorporates native protection against silent data corruption (bit rot), continuous integrity checking, storage pooling, snapshots, and scalable architecture for distributed enterprise servers.

    • reiserfs (Reiser Filesystem)

    • An early Linux journaling filesystem that excels in handling, indexing, and packing small files through balanced tree algorithms, making it well-suited for database engines.

    • exFAT (Extended File Allocation Table)

    • Modern proprietary FAT variant engineered to bypass the 4 GB4\,\text{GB} single-file barrier of FAT32.

    • Functions as the industry standard for high-capacity removable media (flash drives, SDXC cards) due to native cross-platform support across Linux, Windows, and macOS.

    • vfat / msdos / fat

    • Legacy DOS/Windows FAT filesystems using 1212, 1616, or 3232-bit allocation tables.

    • vfat introduces support for Long File Names (LFN\text{LFN}) beyond legacy 8.3 character filename structures.

    • ntfs (New Technology File System)

    • Microsoft's proprietary journaling filesystem used natively in modern Windows NT-based operating systems.

    • iso9660

    • Standardized filesystem defined by the International Organization for Standardization (ISO recommendation 9660) used to format CD-ROM and DVD-ROM optical media.

    • udf (Universal Disk Format)

    • Optical filesystem standardized for packet-writing on rewritable media, specifically CD-RW and DVD-RW drives.

    • squashfs

    • Highly compressed, read-only filesystem utilized in embedded Linux devices, Live CD environments, and system rescue media to minimize disk footprint.

    • vxfs (Veritas File System)

    • Commercial enterprise journaling filesystem common across diverse commercial UNIX variants, supporting large files and granular POSIX ACLs.

Filesystem Mounting and Directory Integration

  • Mechanics of Mounting

    • Mounting is the operating system process that links a formatted physical or logical storage device to an existing branch of the logical directory hierarchy, allowing users and processes to navigate and store files on that medium.

    • The target directory within the system hierarchy is designated as the mount point.

    • When a storage device is mounted to a directory containing existing files, the device's root directory overlays and temporarily hides those existing files.

    • Once the device is successfully unmounted, the hidden files reappear intact and accessible.

    • Best administrative practice dictates creating clean, empty dedicated directories to serve as mount points (e.g., within /mnt or /media) to prevent masking critical application or system data.

The directory structure prior to mountingThe directory structure after mounting a USB flash memory drive
  • Root Filesystem

    • During system initialization, the Linux bootloader and kernel mount the primary operating system partition directly to the top-level slash directory (/).

    • The mounted entity is termed the root filesystem and houses foundational system binaries, dynamic libraries, kernel modules, and global configuration assets.

  • Mounting Commands and Diagnostic Tools

    • mount: Invoked without arguments, displays all currently mounted storage filesystems, their corresponding mount points, and their active operational parameters.

    • mount -t <type> <device> <mount_point>: Mounts the partition or device using the explicitly designated filesystem driver (<type>) to the target <mount_point> directory.

    • mount -r <device> <mount_point>: Mounts the targeted storage device in read-only mode.

    • umount <mount_point> or umount <device>: Detaches the mounted filesystem from the logical directory tree.

    • fuser -u <directory>: Scans and reports all active process IDs (PIDs\text{PIDs}) and user identities actively holding open file descriptors or operating working directories within the targeted path.

    • /etc/mtab: A dynamically maintained system file that records the exact list and active options of all mounted filesystems currently tied to the kernel.

    • lsblk --fs: Displays a visual tree of block storage devices accompanied by their filesystem types, labels, and Universally Unique Identifiers (UUIDs\text{UUIDs}).

    • blkid: Queries block storage devices to display their active UUIDs\text{UUIDs}, volume labels, and filesystem signatures.

  • The /etc/fstab Configuration File

    • The /etc/fstab (filesystem table) configuration file dictates which partitions and filesystems are verified, initialized, and mounted automatically during the boot sequence.

    • If a system administrator executes mount or umount providing only a device path or only a mount point, the utility queries /etc/fstab to locate the missing configuration parameters.

Sample /etc/fstab configuration file
  • Structure and Fields of /etc/fstab

    • Field 1: Device to Mount

    • Specifies the physical hardware source using one of several notations:

      • Absolute device node path: e.g., /dev/sda1.

      • Filesystem UUID\text{UUID}: e.g., UUID=9ff25add-035b-4d26-a9d0a6fa3.

      • GPT Partition UUID\text{UUID}: e.g., PARTUUID=ed835873-01.

      • Volume Label: e.g., LABEL=BackupDisk.

    • Field 2: Mount Point

    • The absolute path to the directory where the filesystem will be attached (e.g., /, /boot, /home, or swap).

    • Field 3: Filesystem Type

    • Identifies the filesystem format (e.g., ext4, xfs, vfat, swap, auto).

    • Field 4: Mount Options

    • Comma-separated list governing filesystem operation:

      • defaults: Applies standard parameters: rw (read/write), suid (allow setuid execution), dev (interpret character/block devices), exec (permit binary execution), auto (mount automatically at boot), nouser (prevent regular users from mounting/unmounting), and async (perform asynchronous disk I/O).

      • ro: Mounts the filesystem strictly in read-only mode.

      • rw: Mounts the filesystem explicitly in read-write mode.

      • auto: Causes the filesystem to be mounted automatically when mount -a executes at boot.

      • noauto: Prohibits automatic mounting during system startup; device must be mounted explicitly.

      • usrquota: Enables administrative tracking and enforcement of user-level disk quotas.

      • grpquota: Enables administrative tracking and enforcement of group-level disk quotas.

    • Field 5: Dump Utility Frequency (dump#)

    • Designates whether the legacy filesystem backup utility dump schedules the filesystem for backup:

      • 1: Filesystem requires backup.

      • 0: No automated backup processing is scheduled.

    • Field 6: Filesystem Check Order (fsck#)

    • Controls the sequence in which the fsck utility audits filesystems during system startup:

      • 1: Designates the root filesystem (/); inspected first before any secondary filesystems.

      • 2: Designates all non-root partitions requiring boot-time integrity auditing.

      • 0: Disables boot-time filesystem integrity checking entirely (used for swap, network shares, or removable storage).

Removable Media, Optical Storage, and Image Creation

  • USB Flash Memory Storage Administration

    • USB flash drives are recognized by the modern Linux storage subsystem via SCSI emulation interfaces, typically presenting as /dev/sdX device nodes.

    • Most commercial USB drives are factory pre-formatted with a single MBR partition hosting an exFAT or FAT32 (MS-DOS) filesystem.

    • Dedicated commands for inspecting hardware include lsusb, which enumerates all connected physical USB devices, controllers, and hubs.

  • Creating Filesystems with mkfs

    • The mkfs (make filesystem) front-end command initializes and formats storage partitions.

    • Default Filesystem Execution

    • When executed without specifying a filesystem type via -t, the mkfs utility formats the partition using the ext2 filesystem by default.

    • Filesystem Construction Commands

    • General format: mkfs -t <filesystem_type> <device_partition>.

    • Native ext2 formatting: mkfs.ext2 <device> or mke2fs <device>.

    • Native ext3 formatting: mkfs.ext3 <device> or mke2fs -t ext3 <device>.

    • Native ext4 formatting: mkfs.ext4 <device> or mke2fs -t ext4 <device>.

    • FAT filesystem variants: mkfs.fat <device> or mkfs.vfat <device>.

    • exFAT filesystem creation: mkfs.exfat <device> or mkexfatfs <device>.

    • XFS creation: mkfs.xfs <device>.

    • NTFS creation: mkfs.ntfs <device> or mkntfs <device>.

    • UDF optical formatting: mkfs.udf <device> or mkudffs <device>.

    • ISO image creation: mkisofs.

  • Optical Disc Storage and ISO 9660 Images

    • Commercial software distributions and OS images utilize optical CD-ROM or DVD-ROM formats relying on the iso9660 or udf specifications.

    • When mounted natively in Linux, optical discs are mounted as read-only volumes via mount -r -t iso9660 <device> <mount_point>.

    • Optical discs are mechanically locked into drive trays while active; the drive cannot be physically opened or ejected until the filesystem is fully unmounted via umount.

    • The eject command automatically executes the unmount workflow and signals the mechanical drive tray to open.

    • ISO Image Generation via mkisofs

    • The mkisofs command compiles directory structures into a single ISO 9660 image file suitable for distribution or disc burning.

    • Syntax: mkisofs -RJ -o <output_filename.iso> <source_directory_path>.

    • The -R option applies the Rock Ridge extensions (preserving Linux/UNIX file permissions, ownerships, and long filenames).

    • The -J option generates Joliet extension records, ensuring compatibility with Microsoft Windows systems.

  • Desktop Environment Automounting Behavior

    • Modern graphical desktop interfaces (such as GNOME) execute background monitoring daemons that detect when removable media (USB memory keys, external USB HDDs/SSDs, SD cards, smartphones, media players, digital cameras, and optical discs) are plugged into the system.

    • These media are mounted automatically into subdirectories under /run/media/<username>/ or /media/ without requiring administrator terminal commands.

Hard Disk Architecture, Partitioning Schemes, and Tools

  • Physical Storage Architecture

    • Traditional hard disk platters read and write magnetic information organized into concentric physical rings called tracks.

    • Tracks are subdivided radially into smaller storage divisions called sectors, historically holding 512 bytes512\,\text{bytes} each.

    • Multiple sectors are grouped logically by the operating system into blocks for efficient read/write allocation.

    • A cylinder represents the aligned grouping of identical concentric tracks spanning vertically across all internal rotating metal platters inside a disk chassis.

The physical areas of a hard disk
  • Hard Disk and SSD Drive Naming Interfaces

    • PATA (IDE) Configurations

    • Primary Master: /dev/hda

    • Primary Slave: /dev/hdb

    • Secondary Master: /dev/hdc

    • Secondary Slave: /dev/hdd

    • SATA, SCSI, and Serial Attached SCSI (SAS) Configurations

    • First disk drive: /dev/sda

    • Second disk drive: /dev/sdb

    • Third disk drive: /dev/sdc

    • Fourth disk drive: /dev/sdd

    • Fifth disk drive: /dev/sde

    • Sixth disk drive: /dev/sdf

    • Solid-State Drive (SSD) Technology

    • Modern SSDs utilize non-volatile NAND flash memory arrays with no moving parts, delivering superior read/write performance compared to magnetic platters while presenting standard block device interfaces.

  • Partitioning Principles and Best Practices

    • A partition represents an isolated physical division of a block storage device operating as an independent logical container capable of hosting a unique filesystem.

    • Linux requires at least two partitions. The Ch 5 slides (older edition) name them as root (/) and swap; the Ch 2 slides (Fedora install) name / and /boot, with swap optional. Know both.

    • Enterprise installations utilize multiple distinct partitions to:

    • Segregate volatile or user-modifiable data (e.g., /home, /var, /tmp) from foundational operating system files.

    • Support different filesystem types specialized for specific workloads on a single drive.

    • Prevent localized filesystem corruption or capacity exhaustion in /tmp or /var from crashing or locking up the entire host.

    • Optimize disk head travel and read/write performance across critical database assets.

    • Enforce security isolation through targeted mount restrictions (such as noexec or nosuid).

  • Master Boot Record (MBR) Partitioning Scheme

    • MBR partition metadata is permanently housed within the very first sector (512 bytes512\,\text{bytes}) of the hard disk drive.

    • Limited to a maximum of four primary partitions per drive.

    • To overcome the four-partition limit, one primary partition entry can be designated as an extended partition.

    • The extended partition serves as a master envelope holding unlimited nested logical drives.

    • MBR partition numbering conventions:

    • Partitions 1 through 4 are strictly reserved for primary partitions (and the extended partition envelope).

    • Logical drives inside an extended partition are always numbered sequentially starting at partition 5 (/dev/sda5), regardless of how many primary partitions are physically defined.

A sample MBR partitioning strategy
  • GUID Partition Table (GPT) Scheme

    • Modern partitioning standard associated with Unified Extensible Firmware Interface (UEFI) systems.

    • Replaces legacy MBR on drives larger than 2 TB2\,\text{TB} (2 TiB2\,\text{TiB}), enabling 64-bit logical block addressing.

    • Eliminates the architectural distinction between primary and extended partitions; supports up to 128 independent partitions per drive by default.

    • Stores redundant secondary partition table headers at the physical end of the disk to safeguard against corruption.

  • Partition Device Naming Cross-Reference

    • 1st Primary Partition / GPT Partition 1: PATA /dev/hda1, SATA/SCSI /dev/sda1, NVMe /dev/nvme0p1.

    • 2nd Primary Partition / GPT Partition 2: PATA /dev/hda2, SATA/SCSI /dev/sda2, NVMe /dev/nvme0p2.

    • 3rd Primary Partition / GPT Partition 3: PATA /dev/hda3, SATA/SCSI /dev/sda3, NVMe /dev/nvme0p3.

    • 4th Primary Partition / GPT Partition 4: PATA /dev/hda4, SATA/SCSI /dev/sda4, NVMe /dev/nvme0p4.

    • 1st Logical Drive in Extended / GPT Partition 5: PATA /dev/hda5, SATA/SCSI /dev/sda5, NVMe /dev/nvme0p5.

    • 2nd Logical Drive in Extended / GPT Partition 6: PATA /dev/hda6, SATA/SCSI /dev/sda6, NVMe /dev/nvme0p6.

    • 3rd Logical Drive in Extended / GPT Partition 7: PATA /dev/hda7, SATA/SCSI /dev/sda7, NVMe /dev/nvme0p7.

    • 4th Logical Drive in Extended / GPT Partition 8: PATA /dev/hda8, SATA/SCSI /dev/sda8, NVMe /dev/nvme0p8.

    • 5th Logical Drive in Extended / GPT Partition 9: PATA /dev/hda9, SATA/SCSI /dev/sda9, NVMe /dev/nvme0p9.

    • nth Logical Drive in Extended / GPT Partition n: PATA /dev/hdan, SATA/SCSI /dev/sdan, NVMe /dev/nvme0pn.

  • Partitioning Management Utilities

    • fdisk <device>: Interactive command-line utility used to create, display, modify, and delete MBR and GPT partitions.

    • Procedure to create a partition in fdisk:

      1. Press n to initiate a new partition.

      2. Select partition class: p for a primary partition or e for an extended container.

      3. Enter the starting sector and ending size offset (e.g., +10G).

      4. Press w to write changes to disk and exit.

      5. Reload the modified partition table into memory by executing partprobe or rebooting the host.

    • cfdisk <device>: Interactive, screen-oriented, curses-based partition editing utility providing a menu-driven interface.

    • gdisk <device>: Specialized GPT-only partition utility mirroring the fdisk command syntax.

    • parted <device>: Advanced GNU utility capable of scripting and resizing partitions directly across both MBR and GPT partition formats.

    • partprobe: Informs the Linux kernel of changes made to partition tables without requiring an immediate system reboot.

The cfdisk utility
  • Swap Space Configuration and Management

    • Swap partitions provide virtual memory extension space when physical RAM fills up.

    • mkswap <device>: Initializes and formats a raw partition with swap signatures.

    • swapon <device>: Activates the formatted swap device within kernel virtual memory.

    • swapoff <device>: Deactivates an active swap partition and migrates swapped pages back to physical RAM.

    • Adding swap entries to /etc/fstab (using filesystem type swap) automates activation during system boot.

Logical Volume Manager (LVM)

  • LVM Architecture and Hierarchy

    • The Logical Volume Manager provides dynamic storage virtualization, decoupling administrative directory trees from rigid physical partition sizes.

    • Allows free space across disparate physical hard disks to be aggregated into unified logical pools that can be dynamically expanded or contracted.

    • Consists of three distinct structural layers:

    • Physical Volumes (PVs): Raw physical disks, SSDs, or standard partitions (e.g., /dev/sda1, /dev/sdb2) tagged for LVM usage.

    • Volume Groups (VGs): Storage pools formed by combining one or more Physical Volumes into a single administrative storage reservoir.

    • Logical Volumes (LVs): Virtual block partitions carved out of the available capacity within a Volume Group, formatted with a filesystem, and mounted to directory paths.

    • Physical Extent (PE): The fundamental block allocation increment used by a Volume Group to manage space (defaults commonly to 4 MB4\,\text{MB}).

A sample LVM configuration
  • Physical Volume Management Commands

    • pvcreate <device>: Writes LVM administrative metadata labels to a raw disk or partition, converting it into a Physical Volume.

    • pvdisplay: Outputs detailed physical volume metrics, including PV size, PE sizes, and allocated extents.

    • pvscan: Scans all system block devices for existing Physical Volume signatures and lists them.

    • pvs: Generates a compact, tabular summary report of physical volumes.

    • pvchange: Alters attributes of an existing physical volume.

    • pvremove: Wipes LVM metadata signatures from a physical volume, converting it back to a standard block partition.

  • Volume Group Management Commands

    • vgcreate <group_name> <pv1> [pv2 ...]: Constructs a new Volume Group by aggregating specified Physical Volumes.

    • vgdisplay: Outputs detailed Volume Group operational metrics, including free extents and total storage capacity.

    • vgscan: Audits all storage controllers to rediscover Volume Groups.

    • vgs: Outputs a summarized tabular view of Volume Groups.

    • vgextend <vg_name> <pv>: Incorporates an additional Physical Volume into an active Volume Group to increase its free capacity.

    • vgreduce <vg_name> <pv>: Shrinks a Volume Group by removing an unallocated Physical Volume from its pool.

    • vgchange: Modifies operational parameters of a Volume Group (such as online activation status).

    • vgremove <vg_name>: Deletes an unallocated Volume Group from the operating system.

  • Logical Volume Management Commands

    • lvcreate -L <size> -n <lv_name> <vg_name>: Carves out a new Logical Volume from the available extents in the designated Volume Group.

    • lvdisplay: Details configuration metrics, block sizes, and paths for all Logical Volumes.

    • lvscan: Scans the system and lists all available Logical Volumes.

    • lvs: Produces a concise tabular output detailing Logical Volume allocation.

    • lvextend: Increases the storage capacity allocated to an active Logical Volume (often paired with filesystem resize tools).

    • lvreduce: Reduces the capacity assigned to a Logical Volume.

    • lvresize: Directly expands or shrinks a Logical Volume to a specific absolute size boundary.

    • lvchange: Modifies operational flags and attributes of a Logical Volume.

    • lvremove <lv_path>: Destroys a designated Logical Volume, returning its extents to the parent Volume Group pool.

Storage Capacity and Inode Monitoring

  • Filesystem Monitoring Objectives

    • Periodic administrative monitoring is required to prevent filesystems from exhausting either storage space or inode allocations.

    • Segmenting a system into multiple small filesystems reduces the margin for error, as localized partitions fill up rapidly under high usage loads.

  • Storage Space Auditing Utilities

    • The df (Disk Free) Command

    • Monitors overall disk space usage across all currently mounted filesystems.

    • Filesystems must be actively mounted to be inspected by df.

    • df -h: Formats output capacities into human-readable binary units (e.g., K\text{K}, M\text{M}, G\text{G}, T\text{T}).

    • df -T: Displays the filesystem type alongside mount and utilization statistics.

    • df -hT: Combines human-readable format with explicit filesystem type reporting.

    • df -i: Replaces block allocation reporting with metrics detailing the total, consumed, and free inode quantities.

    • The du (Directory Usage) Command

    • Audits individual directories and their child contents, calculating physical consumption in kilobytes.

    • du -s <directory>: Generates a single summary calculation of total storage consumed by the target directory.

    • du -h <directory>: Converts directory byte sizes into human-readable notation.

    • du -sh <directory>: Delivers a human-readable summary total of an entire directory tree.

    • Superblock Inspection via dumpe2fs

    • dumpe2fs -h <device>: Reads and prints the superblock header data directly from an unmounted ext2, ext3, or ext4 partition, outputting filesystem metrics including total inode counts, free inode counts, block size, and mount statistics.

Filesystem Integrity and Error Correction

  • Filesystem Corruption Vectors

    • Filesystem corruption refers to structural damage within the superblock, inode tables, or allocation bitmaps that prevents the reliable reading, writing, or locating of data.

    • Most commonly triggered by sudden ungraceful power failures, kernel panics, or mechanical drive crashes that interrupt pending I/O.

    • Syncing: The automated kernel process of flushing dirty data buffers held in volatile RAM to physical storage sectors to ensure transactional persistence.

    • Bad Blocks: Physical surface defects on magnetic platters or memory cell failures on SSDs that can no longer retain electrical charge or magnetic polarity.

  • The fsck (Filesystem Check) Utility

    • Acts as a front-end wrapper that identifies the underlying filesystem type and invokes the correct low-level repair driver (e.g., fsck.ext4, fsck.xfs).

    • Critical Operational Rule: A filesystem must always be cleanly unmounted before running fsck; running fsck on an active, mounted read-write filesystem can cause catastrophic data corruption.

    • Common Options for fsck

    • fsck -f <device>: Forces a full, thorough filesystem check even when the superblock clean flag indicates the filesystem is undamaged.

    • fsck -y <device>: Automatically answers yes to all interactive prompts, repairing detected structural inconsistencies without administrator intervention.

    • fsck -A: Scans and checks all filesystems listed in /etc/fstab that have their sixth field set to 1 or 2.

    • fsck -Cf <device>: Executes a forced, comprehensive filesystem check while rendering an active ASCII progress bar line.

    • fsck -AR: Audits all filesystems configured with a 1 or 2 in /etc/fstab while explicitly bypassing the root filesystem (/).

    • fsck -V: Executes with verbose debugging output enabled.

  • Specialized Maintenance Utilities

    • e2fsck -c <device>: Checks an ext2, ext3, or ext4 partition while invoking badblocks to scan the physical surface for damaged storage blocks and map them out of the allocation table.

    • tune2fs -i <interval> <device>: Modifies tunable parameters embedded within the superblock of ext2/ext3/ext4 filesystems, such as setting the maximum elapsed time interval allowed between mandatory system checks.

User and Group Disk Quotas

  • Quota Concepts and Limits

    • Quotas establish administrative ceilings on the volume of disk space (blocks) or the total quantity of files/directories (inodes) that specific non-root users or groups may allocate on a given filesystem.

    • Prevents individual users or processes from consuming all available hard drive space and causing denial-of-service conditions.

    • Soft Limits

    • A flexible usage threshold that users are permitted to exceed temporarily during burst activities.

    • When a user crosses the soft limit, the system initiates a countdown grace period (defaulting to seven days).

    • If the user fails to purge files and reduce consumption below the soft limit before the grace period expires, the soft limit acts as a rigid hard limit, blocking all subsequent file creation.

    • Hard Limits

    • An absolute, unyielding capacity ceiling that a user can never exceed under any circumstances.

  • Step-by-Step Quota Implementation Procedure

    1. Edit /etc/fstab: Locate the target filesystem line and append the usrquota and grpquota keywords to the fourth field (mount options column).

    2. Remount the Filesystem: Apply the updated mount options without rebooting by remounting the target filesystem as read-write:

    • mount -o remount,rw <mount_point>

    1. Generate Quota Database Files: Execute the initial disk inspection and file generation command:

    • quotacheck -mavugf -F vfsv0

    • Initializes the root-level binary tracking files aquota.user and aquota.group on the target partition.

    • Note: Initial warnings concerning missing aquota files during the first run can be safely ignored because they indicate the creation of new quota files.

    1. Activate Quotas: Turn on automated system-wide quota accounting and enforcement:

    • quotaon -avug

    1. Configure User Limits: Open the interactive quota editor to specify soft and hard limits for disk blocks and inodes for target users:

    • edquota -u <username>

    • Edit the values inside the temporary vi editor session, save, and exit.

    1. Modify Grace Periods: Adjust the default seven-day expiration window using:

    • edquota -u -t or edquota -t

    1. Verify and Report: Audit live user allocations and confirm enforcement by generating a comprehensive status report:

    • repquota <filesystem_mount_point>

  • Summary of Quota Commands and Switches

    • quota: Enables standard non-root users to inspect their own quota limits and current block/inode consumption.

    • quota -u <username>: Allows an administrator to inspect the live quota consumption of a designated user.

    • edquota -u <user>: Modifies the block and inode quotas assigned to a specific user.

    • quotaon -avug: Turns on quota enforcement globally across all filesystems configured with quota options.

    • quotaoff: Disables quota enforcement across the system.

    • repquota <filesystem>: Compiles and displays a formatted administrative report detailing block and inode allocations for all users on a partition.

    • quotacheck Options Breakdown

    • -f: Forces the generation and rewriting of new quota database files.

    • -F vfsv0: Explicitly specifies the standard Linux VFS quota file format version 0.

    • -a: Scans and checks all quota-enabled filesystems listed in /etc/fstab.

    • -v: Enables verbose output during filesystem auditing.

    • -u: Checks user quotas.

    • -g: Checks group quotas.

    • -m: The course notes define this as "remount filesystem read-only." On a real system, -m actually tells quotacheck NOT to remount the filesystem read-only, so it can check it while it stays mounted.

Exam Procedures (Midterm/Final Study Guides)

  • Create a new partition with fdisk

    • Run fdisk /dev/sda (the disk, not a partition). Inside fdisk: p prints the partition table, n creates a new partition, then choose p (primary) or e (extended) and enter the size. An extended partition can hold logical drives.

    • When done, w saves and exits; q quits without saving. (The study guide writes these as :p, :n, :w, :q; in fdisk you just type the letter.)

    • Refresh the partition table: reboot or partprobe.

    • Format it: mkfs -t ext4 /dev/sda5

    • Create a mount point and mount it: mkdir /data then mount /dev/sda5 /data

    • Mount it automatically at boot by adding a line to /etc/fstab (e.g., vi /etc/fstab): /dev/sda5 /data ext4 defaults 0 0

    • For disk quotas, add usrquota to the options field: /dev/sdc1 /data ext4 defaults,usrquota 0 2

  • Mount a USB drive and work with files

    • 1. Identify the USB device: lsblk

    • 2. Check free space and filesystem type: df -T

    • 3. Create a mount point: mkdir /mnt/usb

    • 4. Mount it: mount /dev/sdb1 /mnt/usb

    • 5. Copy a file to it: cp ~/myfile.txt /mnt/usb/; create a folder on it: mkdir /mnt/usb/projects

    • 6. Check whether it's in use before unmounting: fuser -m /mnt/usb

    • 7. Unmount (only if nothing is using it): umount /mnt/usb

  • Mounting rules: a mounted device temporarily covers up the existing contents of the mount point. Any existing directory can be a mount point, so use empty directories made specifically for mounting to avoid hiding files.

  • Three common parts of a filesystem: superblock, inode table, data blocks.

Chapter 5 Review (Instructor Answer Key)

  • mount

    • Mount ext4 /dev/sdb1 to /data, specifying the type: mount -t ext4 /dev/sdb1 /data

    • Mount xfs /dev/sdc2 to /backup, specifying the type: mount -t xfs /dev/sdc2 /backup

    • Mount /dev/sdb5 to /newmount: mount /dev/sdb5 /newmount

    • Mount the logical volume /dev/vg01/data to /projects: mount /dev/vg01/data /projects

    • Mount the DVD /dev/cdrom to /mnt: mount /dev/cdrom /mnt

    • Mount vfat /dev/sdd1 to /usb, specifying the type: mount -t vfat /dev/sdd1 /usb

    • Mount ext4 /dev/sdb3 to /archive read-only: mount -o ro -t ext4 /dev/sdb3 /archive

    • Remount the already-mounted /newmount as read-write: mount /newmount -o remount,rw

  • umount and fuser

    • Unmount /data: umount /data

    • Unmount /dev/sdb5: umount /dev/sdb5

    • Unmount the DVD using /dev/cdrom: umount /dev/cdrom

    • Unmount the logical volume /dev/vg01/data: umount /dev/vg01/data

    • Show which users are using /mnt: fuser -u /mnt

  • mkfs

    • ext4 on /dev/sdb1: mkfs -t ext4 /dev/sdb1

    • ext4 on /dev/sdc5: mkfs -t ext4 /dev/sdc5

    • xfs on /dev/sdc2: mkfs -t xfs /dev/sdc2

    • ext4 on the LV /dev/vg01/data: mkfs -t ext4 /dev/vg01/data

    • ext4 on the LV /dev/vg02/logs: mkfs -t ext4 /dev/vg02/logs

    • vfat on /dev/sdd1: mkfs -t vfat /dev/sdd1

  • Physical volumes

    • Initialize /dev/sdb1 as a PV: pvcreate /dev/sdb1

    • Initialize /dev/sdb2 and /dev/sdb3 in one command: pvcreate /dev/sdb2 /dev/sdb3

    • Initialize /dev/sdc1: pvcreate /dev/sdc1

    • Display details of all PVs: pvdisplay

  • Volume groups

    • Create vg01 from /dev/sdb1: vgcreate vg01 /dev/sdb1

    • Create vg02 from /dev/sdb2 and /dev/sdb3: vgcreate vg02 /dev/sdb2 /dev/sdb3

    • Create vgdata from /dev/sdc1: vgcreate vgdata /dev/sdc1

    • Display details of all VGs: vgdisplay

    • Add /dev/sdb4 to vg01: vgextend vg01 /dev/sdb4

    • Add /dev/sdc1 to vg02: vgextend vg02 /dev/sdc1

    • Add /dev/sdb6 and /dev/sdb7 to vgdata: vgextend vgdata /dev/sdb6 /dev/sdb7

  • Logical volumes (the key writes sizes like 2GB; 2G is the standard LVM form)

    • 0.9 GB LV named newdata from vg00: lvcreate -L 0.9GB -n newdata vg00

    • 2 GB LV named web from vg01: lvcreate -L 2GB -n web vg01

    • 500 MB LV named logs from vg02: lvcreate -L 500MB -n logs vg02

    • 1.5 GB LV named projects from vg01: lvcreate -L 1.5GB -n projects vg01

    • 10 GB LV named backup from vgdata: lvcreate -L 10GB -n backup vgdata

    • Display path and size of all LVs: lvdisplay

    • Extend /dev/vg00/newdata BY 0.9 GB and resize its filesystem: lvextend -L +0.9GB -r /dev/vg00/newdata

    • Extend /dev/vg01/web BY 1 GB and resize its filesystem: lvextend -L +1GB -r /dev/vg01/web

    • Make /dev/vg02/logs a TOTAL of 2 GB and resize its filesystem (no + sign): lvextend -L 2GB -r /dev/vg02/logs

    • Grow the ext4 filesystem on /dev/vg01/projects after extending it without -r: resize2fs /dev/vg01/projects

  • /etc/fstab lines (device, mount point, type, options, dump, fsck)

    • ext4 /dev/sdb1 at /data, defaults, no dump, fsck off: /dev/sdb1 /data ext4 defaults 0 0

    • ext4 /dev/sdb2 at /backup, defaults, no dump, fsck after root: /dev/sdb2 /backup ext4 defaults 0 2

    • LV /dev/vg01/projects at /projects, ext4, defaults, fsck off: /dev/vg01/projects /projects ext4 defaults 0 0

    • xfs /dev/sdc1 at /web, defaults, no dump, fsck off: /dev/sdc1 /web xfs defaults 0 0

    • vfat /dev/sdd1 at /usb read-only, no dump, fsck off: /dev/sdd1 /usb vfat defaults,ro 0 0

    • ext4 /dev/sda2 at /home, defaults, dump on, fsck after root: /dev/sda2 /home ext4 defaults 1 2

    • ext4 /dev/sdb5 at /newmount with user and group quotas, fsck off: /dev/sdb5 /newmount ext4 defaults,usrquota,grpquota 0 0

    • Mount everything in /etc/fstab not already mounted (test edits without rebooting): mount -a

  • Device files

    • Character device /dev/tty6, major 4, minor 6: mknod /dev/tty6 c 4 6

    • Character device /dev/tty9, major 4, minor 9: mknod /dev/tty9 c 4 9

    • Block device /dev/mydisk, major 8, minor 16: mknod /dev/mydisk b 8 16

    • View devices and their major numbers via /proc: cat /proc/devices

Questions & Discussion

  • Knowledge Check Activity 1

    • Question: What type of device transfers chunks or blocks of information at a time by using physical memory to buffer the transfer?

    • A. Character device

    • B. Minor device

    • C. Major device

    • D. Block device

    • Answer: D (Block device)

    • Explanation: Block devices use system physical memory (RAM) to buffer transfers of large blocks or chunks of data, resulting in significantly faster data transfer speeds compared to character-by-character transfers.

  • Knowledge Check Activity 2

    • Question: What command is used to unmount a mounted USB flash memory drive from the Linux command line?

    • A. unmount

    • B. mount -u

    • C. umount

    • D. mount -exit

    • Answer: C (umount)

    • Explanation: The correct command to detach a mounted storage device or filesystem from the Linux logical directory tree is umount (without an "n").

  • Knowledge Check Activity 3

    • Question: What device file would be used to reference the PS/2 mouse port on a Linux system?

    • A. /dev/ps2

    • B. /dev/mouse

    • C. /dev/psaux

    • D. /dev/ps_2

    • Answer: C (/dev/psaux)

    • Explanation: The PS/2 mouse auxiliary port interface is mapped character-by-character to the /dev/psaux device file node.

  • Knowledge Check Activity 4

    • Question: By default, what filesystem does Linux use to format a disk when the mkfs command is specified without options?

    • A. ext2

    • B. ext3

    • C. vfat

    • D. msdos

    • Answer: A (ext2)

    • Explanation: Unless a specific filesystem type is designated using the -t switch, mkfs defaults to formatting partitions using the ext2 filesystem driver.

  • Knowledge Check Activity 5

    • Question: Which of the following will Linux consult when a user uses the mount command but does not specify all the required information for the specific device?

    • A. /dev/fd0

    • B. /etc/fstab

    • C. /etc/mtab

    • D. /proc/devices

    • Answer: B (/etc/fstab)

    • Explanation: If only a partial path (device path or mount point) is provided to mount or umount, the utility searches /etc/fstab to locate the missing configuration parameters.

  • Knowledge Check Activity 6

    • Question: After a partition on a storage device is formatted with a filesystem, all partitions on that storage device must use the same filesystem.

    • A. True

    • B. False

    • Answer: B (False)

    • Explanation: Every physical or logical partition on a storage device operates as an independent storage container and can be formatted with a distinct filesystem type.

  • Knowledge Check Activity 7

    • Question: What device file would be associated with the third SCSI hard disk in a Linux system?

    • A. sda

    • B. sdb

    • C. sdc

    • D. sdd

    • Answer: C (sdc)

    • Explanation: SCSI, SATA, and SAS disk drives follow alphabetical ordering, where the first drive is /dev/sda, the second is /dev/sdb, and the third is /dev/sdc.

  • Knowledge Check Activity 8

    • Question: Data stored on hard disks is read off metal platters in concentric circles called _____.

    • A. blocks

    • B. tracks

    • C. sectors

    • D. cylinder

    • Answer: B (tracks)

    • Explanation: Concentric physical circular paths on hard disk platters are called tracks. Sectors are geometric subdivisions of tracks, blocks are combined sectors, and cylinders represent aligned vertical tracks.

  • Knowledge Check Activity 9

    • Question: What utility is used to partition a Linux hard disk after Linux has been installed?

    • A. partinfo

    • B. fdisk

    • C. Disk Druid

    • D. delpart

    • Answer: B (fdisk)

    • Explanation: The standard command-line partition manipulation tool used to create, edit, and delete partitions post-installation is fdisk.

  • Knowledge Check Activity 10

    • Question: What command is used to view the available free space on a Linux partition?

    • A. du

    • B. de

    • C. df

    • D. dt

    • Answer: C (df)

    • Explanation: The df (disk free space) command displays free and consumed space across all mounted filesystems. du measures directory-level space consumption.

  • Knowledge Check Activity 11

    • Question: What command is used to view the total number of inodes and free inodes for an ext2, ext3, or ext4 filesystem?

    • A. dumpe2fs –h

    • B. du /usr

    • C. cat /etc/fstab

    • D. mke2fs –t

    • Answer: A (dumpe2fs –h)

    • Explanation: Executing dumpe2fs -h reads the superblock header of an ext2, ext3, or ext4 partition directly, outputting total and free inode counts.

  • Knowledge Check Activity 12

    • Question: Which of the following commands can only be used to create partitions on a GPT storage device?

    • A. gdisk

    • B. cfdisk

    • C. fdisk

    • D. parted

    • Answer: A (gdisk)

    • Explanation: The gdisk (GPT fdisk) utility is specifically designed to create and manage partitions exclusively on GUID Partition Table storage devices.

  • Knowledge Check Activity 13

    • Question: Which command is used to format a partition on a hard disk drive with the ext4 filesystem?

    • A. e2mkfs –t ext4 device

    • B. makeext4FS device

    • C. format_ext4 device

    • D. ext4mkfs device

    • Answer: A (e2mkfs –t ext4 device)

    • Explanation: "a" is the slide's answer, but the slide has a typo. The real command is mke2fs -t ext4 <device> (or mkfs.ext4 <device> / mkfs -t ext4 <device>). There is no e2mkfs command on Fedora, so type mke2fs on a hands-on question.

  • Self-Assessment Question 1

    • Prompt: What are some important features of current filesystem types?

    • Response: Modern Linux filesystems incorporate journaling (e.g., ext3, ext4, xfs) to log transactions before applying them, enabling rapid recovery without full structural scans after ungraceful shutdowns. Advanced enterprise filesystems like btrfs and zfs provide copy-on-write (CoW\text{CoW}) mechanics, integrated volume management, multi-device spanning, storage pooling, automated checksum verification to protect against bit rot, native compression, POSIX access control lists (ACLs), dynamic subvolumes, and instant read-only or writable snapshots.

  • Self-Assessment Question 2

    • Prompt: Why is it considered good practice to implement disk quotas?

    • Response: Enforcing disk quotas prevents individual non-root users, groups, or runaway processes from monopolizing shared physical storage space. Uncontrolled disk consumption can prevent system services from writing critical operational logs, filling /tmp or /var, and triggering system instability or denial-of-service conditions across the host environment.