Linux admin

Preface

Part I: Understanding Linux

Part II: Working with Linux

Part III: The Linux Desktop Environment

wmctrl is a command-line tool that allows you to interact with and control windows in the X Window System. It provides a simple and scriptable interface for tasks such as listing windows, moving and resizing windows, and changing window properties.

Listing Windows

To list all the windows managed by the window manager, use the wmctrl -l command:

wmctrl -l

This command will display a list of windows with their window IDs, desktop numbers, window states, and window titles.

Moving Windows by Title

To move a window to a specific position on the screen based on its title, you can use the wmctrl -r command followed by the window title and the -e option to specify the new position:

wmctrl -r "Terminal" -e 0,100,100,800,600

This command will move the window with the title “Terminal” to the position (100, 100) on the screen and resize it to a width of 800 pixels and a height of 600 pixels.

If the window title contains spaces, you need to surround it with quotes.

You can also use a partial window title to match multiple windows:

wmctrl -r "Firefox" -e 0,50,50,1200,800

This command will move and resize all windows with “Firefox” in their titles.

Other wmctrl Commands

wmctrl -a "Terminal"

This command will bring the window with the title “Terminal” to the foreground and give it focus.

wmctrl -c "Terminal"

This command will close the window with the title “Terminal”.

wmctrl -r "Terminal" -b toggle,fullscreen

This command will toggle the fullscreen state of the window with the title “Terminal”.

These examples demonstrate some of the basic functionalities of wmctrl. You can refer to the wmctrl manual page (man wmctrl) for more advanced usage and options.

Part IV: Linux Internals

Part V: Core Linux Features

Users and Groups

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 VI: Networking and Security

Part VII: Advanced Administration

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 VIII: Server and Environment Setup

Part IX: Scripting and Automation

Part X: Development on Linux

Epilogue

Appendix

Index