Linux admin

Preface

  • Introduction to Linux
    • What is Linux?
    • The History of Linux
    • Linux Distributions
    • Getting Started with Linux

Part I: Understanding Linux

  • The Linux Kernel
    • Kernel Architecture
    • Kernel Modules
    • Building and Compiling the Kernel
  • The Linux Filesystem Hierarchy
    • Filesystem Structure
    • File Types and Permissions
    • Manipulating Files and Directories

Part II: Working with Linux

  • The Command Line Interface
    • Basic Commands
    • Shell Scripting Basics
    • Text Editors (vi, nano, emacs)
  • Package Management
    • RPM and YUM (Red Hat-based Systems)
    • APT and DPKG (Debian-based Systems)
    • Other Package Managers

Part III: Linux Internals

  • Process Management
    • Understanding Processes
    • Managing Processes
    • Job Control
  • Memory Management
    • Virtual Memory
    • Swap Space
    • Memory Performance
  • Device Drivers and Management
    • Understanding Device Drivers
    • Installing and Configuring Drivers

Part IV: Core Linux Features

Users and Groups

  • User Management
  • Group Management
  • Advanced User Features

Filesystem Monitoring and inotify

Introduction to Filesystem Monitoring

Inotify is a Linux kernel subsystem that provides a mechanism for monitoring filesystem events. It was merged into the Linux kernel mainline in kernel version 2.6.13, released on August 29, 2005. The inotify API was created by John McCutchan, with contributions from Robert Love, among others.

The primary purpose of inotify is to provide applications with the ability to watch for changes in the filesystem without resorting to resource-intensive techniques like polling. Before inotify, the commonly used method for tracking filesystem changes was through the dnotify system, which had certain limitations, such as one per-directory file descriptor requirement, which was not scalable for applications that needed to monitor many directories.

Inotify was designed to overcome the shortcomings of dnotify by allowing applications to watch for various types of filesystem events on one or more files and directories with a single file descriptor. This made it significantly more efficient and scalable. Applications can be notified about events such as creations, modifications, deletions, and more, allowing them to respond to changes in real-time.

With inotify, each watch that is placed on a file or directory consumes a certain amount of kernel memory, which is why there is a system-wide limit on the number of watches that can be created. This limit can be adjusted by the user if necessary, as mentioned in the context of the KServe deployment.

Inotify has become an integral part of many Linux-based systems and applications, enabling efficient file monitoring for desktop search engines, automatic backup and sync services, integrated development environment (IDE) tools, and server management applications, to name a few.

The introduction of inotify represented a significant advancement in filesystem monitoring capabilities on Linux, contributing to the system’s overall efficiency and responsiveness, particularly in environments where filesystem changes need to be tracked closely and handled promptly.

Using inotify for Filesystem Events

Practical Applications of inotify

Part V: Networking and Security

  • Linux Networking
    • Networking Basics
    • Network Configuration
    • Network Troubleshooting
  • Linux Security
    • Basic Security Concepts
    • Firewalls and Packet Filtering
    • Security Best Practices

Part VI: Advanced Administration

  • System Administration
    • Boot Process and Init Systems
    • System Maintenance
    • Performance Monitoring and Tuning

Storage Management

  • Disk Partitioning

Filesystem Management

XFS

XFS, known for its high performance and scalability, is a 64-bit journaling filesystem. Originally from Silicon Graphics, Inc (SGI) in 1993, it was engineered to support voluminous filesystems and deliver exceptional performance, particularly in environments that require managing large files and facilitating high scalability.

  1. Good I/O Throughput:

XFS’s architecture is optimised for high throughput, making it suitable for handling numerous simultaneous read and write operations. This is very important for VM environments where disk I/O operations are constant and performance is a known bottleneck.

  1. Dynamic Scalability:

The ability to efficiently manage large files and filesystems ensures that VM storage can be scaled dynamically in response to the needs of the system, without compromising on performance.

  1. Robust Journaling:

The journaling mechanism of XFS guarantees the integrity of the filesystem in the event of unexpected shutdowns or system crashes, protecting against data corruption during high I/O periods.

  1. Advanced Management Features:

XFS includes features such as allocation groups for enhanced disk access, online defragmentation to maintain optimal performance, and online resizing to adjust resources dynamically — all of which are beneficial under heavy I/O load.

Preparing a Disk with XFS (Fedora)

Before jumping in on formatting, make sure you back up any existing data on the disk to avoid loss. The following steps will guide you through preparing a disk with XFS for your VM on Fedora.

  1. Install XFS Utilities

Begin by installing the XFS utilities on Fedora (if you don’t have them already):

sudo dnf install xfsprogs
  1. Choose the Target Disk

Use the lsblk command to list all disks and identify the one intended for formatting:

lsblk

Look for the disk through its size or identifier, like /dev/sdX.

  1. Format the Disk

After locating your disk, format it to XFS:

sudo mkfs.xfs /dev/sdX

Replace /dev/sdX with the actual disk path.

  1. Mount the Formatted Disk

Create a mount point and mount the formatted disk:

sudo mkdir /mnt/vm_storage
sudo mount /dev/sdX /mnt/vm_storage
  1. Ensure Automatic Mount at Boot

To mount the disk automatically upon boot, modify the /etc/fstab file:

  1. Identify your disk’s UUID with blkid.
  2. Append the following line to /etc/fstab, substituting your-disk-uuid with the actual UUID:
UUID=your-disk-uuid /mnt/vm_storage xfs defaults 0 0

RAID and LVM

Backup and Recovery

  • Backup Strategies
  • Disaster Recovery
  • Data Archiving

Part VII: Server and Environment Setup

  • Setting Up a Web Server
    • Apache
    • Nginx
    • Server Security
  • Email Server Configuration
    • Postfix
    • Dovecot
    • Spam Control
  • Linux Containers and Virtualization
    • Docker
    • Kubernetes
    • Virtual Machines with KVM/QEMU

Part VIII: Scripting and Automation

  • Advanced Shell Scripting
    • Functions and Libraries
    • Automation Scripts
    • Error Handling and Debugging
  • Sed and Awk
    • Stream Editing with Sed
    • Text Processing with Awk

Part IX: Development on Linux

  • Development Tools
    • Compilers and Interpreters
    • Debugging Tools
    • Version Control Systems
  • Building from Source
    • Configure, Make, and Install
    • Patching Software
    • Creating Packages

Epilogue

  • The Future of Linux
    • Emerging Technologies
    • The Linux Foundation
    • Community and Contributions

Appendix

  • Linux Commands Reference
  • Editing Config Files
  • Glossary of Terms
  • Resources for Further Learning

Index