Post

Week 2 Learning Journal

SSH and File System Mount Information

SSH

  • SSH Layers:
    • SSH operates on three layers:
      1. Transport layer
      2. Authentication layer
      3. Communication layer
  • CLI Usage:
    • SSH is commonly used via the command-line interface (CLI) for secure remote access to servers.
  • Key-Based Authentication:
    • SSH authentication often involves the use of key pairs, consisting of a private key and a corresponding public key.
  • Sudo User and Package Management:
    • In Linux, the sudo command is used to execute commands with superuser privileges.
    • Package management commands like dnf, yum, and apt are often used with sudo to install, remove, or update software packages.

Docker, Vagrant, and Containers

  • Learning About:
    • Docker and Vagrant are tools used for containerization and virtualization, respectively.
    • Containers provide a lightweight and portable way to package and deploy applications.

Chapter 2: Displaying File System Mount Information

  • Command Usage:
    • Various commands can be used to display information about file system mounts and storage devices.
  • Commands:
    1. man mount: Displays the manual page for the mount command, providing detailed information on its usage and options.
    2. mount | grep nvme: Filters mount information to display only entries related to NVMe devices.
    3. blkid: Prints block device attributes like UUID and file system type.
    4. lsblk: Lists information about block devices and their relationships.
    5. df: Displays disk space usage of file systems.
    6. df -h: Displays disk space usage in a human-readable format.
    7. vim /etc/mtab: Opens the mount table file /etc/mtab for editing using the Vim text editor.

Day 2: Linux Filesystems

Commands and Tools

  • mount Command:
    • Used to mount filesystems and displays information about mounted filesystems.
    • Use man mount to access the manual page for detailed information on the mount command.
  • /etc/mtab File:
    • Stores information about currently mounted filesystems.
    • Use mount | grep nvme or cat /etc/mtab | grep nvme to filter and display information about NVMe devices.
  • /proc/mounts:
    • Another file used to show information about mounted filesystems.
  • blkid Command:
    • Prints block device attributes like UUID and filesystem type.
  • lsblk Command:
    • Lists information about block devices, their partitions, and other details.
    • Use lsblk -f to display additional information.
  • fuser Command:
    • Identifies processes using a specified file or filesystem.
    • Use fuser /mnt/backup or fuser -v /mnt/backup to check processes using a specific directory.
  • lsof Command:
    • Lists open files and the processes that opened them.
    • Use lsof | head to display the first few lines of output or lsof | grep /mnt/backup to filter output for processes related to a specific directory.
  • mount -a Command:
    • Mounts all filesystems listed in /etc/fstab.
  • df -h Command:
    • Displays disk space usage in a human-readable format.
  • Editing /etc/mtab:
    • Use vim /etc/mtab to open the /etc/mtab file for editing using the Vim text editor.

Day 3: Chapter 2 - Videos 2 to 6

Video 2

  • Manually Mounting Filesystems:
    • Use umount /mnt/data to unmount a filesystem.
    • Use fuser and lsof commands to identify processes preventing a filesystem from being unmounted.
    • fuser -v provides more detailed information.
    • lsof | head and lsof | grep /mnt/backup are used to list open files related to a specific directory.
    • Use fuser -k mnt/backup to kill processes using a filesystem.

Video 3

  • Automatic Mounting at Boot:
    • When the system boots, it doesn’t automatically add entries into fstab, so drives are not auto-mounted.
    • Use mount -a command to read fstab and mount filesystems listed there.
    • Use lsblk -l to list block devices.
  • sync Command:
    • sync flushes filesystem buffers.

Video 4

  • Swap Space:
    • Swap space is used as virtual memory when physical RAM is full.
    • Typically, swap space is twice the amount of RAM.
    • Use commands like swapon -s, swapon --show, or cat /proc/swaps to view swap usage.
    • free command displays memory usage.
  • Systemd Mount Units:
    • Systemd automatically creates mount units based on fstab information.
    • Explore systemd mount units in /run/systemd/generator.

Video 6 (Lab 1 of Chapter 2)

Learning Objectives:

  1. Create and enable a swap partition using /dev/xvdg1.
  2. Add an entry to /etc/fstab to ensure the swap partition persists through a reboot (use the UUID).
  3. Create and enable a 1 GB swap file in the root directory called “extraswap”.
  4. Add an entry to /etc/fstab to ensure the swap file persists through a reboot (use the full path to the file name).

Lab: Working with Swap Space

Task 1: Creating and Enabling a Swap Partition

  • Designating Swap Disk:
    • Used lsblk command to identify the swap disk.
    • Created swap space using mkswap /dev/xvdg1.
    • Enabled swap space using sudo swapon /dev/xvdg1.
    • Verified swap space using swapon --show.
  • Adding Entry to /etc/fstab:
    • Edited /etc/fstab using vim /etc/fstab.
    • Added the UUID entry for swap partition and saved the file.

Task 2: Creating and Enabling a Swap File

  • Creating Swap File:
    • Created a 1 GB swap file using dd if=/dev/zero of=/extraswap bs=1M count=1024.
    • Checked file size using ll -h /extraswap.
    • Restricted read access for others and granted only root write access using chmod 600 /extraswap.
    • Designated the file as swap using mkswap /extraswap.
    • Enabled the swap file using swapon /extraswap.
    • Verified the swap file using swapon --show.
  • Adding Entry to /etc/fstab:
    • Added the swap file entry to /etc/fstab to ensure persistence through reboot.

Lab: Working with Systemd Mount Units

Task 1: Creating a Unit File for Data Mount

  • Creating Unit File:
    • Used lsblk -f to grab UUID for the data mount.
    • Created a unit file mnt-data.mount in /etc/systemd/system with appropriate configuration.
    • Reloaded systemd using systemctl daemon-reload.
    • Enabled and started the mount unit using systemctl enable mnt-data.mount --now.

Task 2: Creating a Unit File for Backup Mount

  • Creating Unit File:
    • Similar steps as Task 1 for creating a unit file mnt-backup.mount.

Task 3: Creating an Automount Unit File for Backup Mount

  • Creating Automount Unit File:
    • Created an automount unit file mnt-backup.automount based on provided instructions.
    • Enabled and started the automount unit using appropriate systemctl commands.

Chapter 4: Automatically Mounting File Systems with Autofs

Lesson 1: Introduction to Autofs

  • Installation:
    • Installed autofs package using yum install -y autofs.
    • Enabled and started autofs service using systemctl enable autofs --now.
    • Checked the status of autofs service using systemctl status autofs.
  • Configuration Files:
    1. /etc/sysconfig/autofs: Global options for all mounts.
    2. /etc/auto.master: Main configuration file with entries for mounts.
  • Mount Points:
    • Created mount points using mkdir.
    • Configured indirect and direct mounts in /etc/auto.master.
    • Created map files for indirect mounts.

Lesson 2: File System Types and Extensions

  • File System Types:
    • Discussed various file system types like ISO 9660, UDF, HFS.
    • Explained ISO 9660 extensions: Rock Ridge, Joliet, El Torito.

Lesson 3: Data Encryption

  • Installation:
    • Installed cryptsetup package using yum install -y cryptsetup.

Lab: Working with Autofs

Learning Objectives:

  • Install the autofs Package and Start and Enable the autofs Service
  • Create an Indirect Mount at /mnt/marketing
  • Create a Direct Mount at /mnt/admin/data
  • Create a Direct Mount at /mnt/user/data

Performing the Lab:

  • Installation and Configuration:
    • Installed autofs package and started/enabled the service.
    • Created mount points for marketing, admin, and user data.
    • Edited /etc/auto.master to include entries for mounts.
  • Indirect Mount:
    • Created an indirect mount for marketing data.
    • Configured /etc/auto.marketing file with mount options.
  • Direct Mounts:
    • Configured direct mounts for admin and user data.
    • Edited /etc/auto.admin and /etc/auto.user accordingly.
  • Verification:
    • Restarted autofs service and checked mount points using df -h and ll.

Additional Activities

Mounting and Formatting External Hard Drive

Identification and Confirmation

  • Identifying Drive Name:
    • Used lsblk command to identify the name of the external hard drive.
    • Confirmed using sudo blkid /dev/sdc1.

Formatting Process

  • Formatting External Hard Drive:
    • Used sudo mkfs.fat -F 32 -n extdrive /dev/sdc1 command to format the drive as FAT32 with label “extdrive”.
    • Verified the formatting using sudo blkid /dev/sdc1.

Result

  • Successful Formatting:
    • Successfully formatted the external drive from NTFS to FAT32 file system.

Considerations

  • File System Choice:
    • Opted for FAT32 file system for compatibility with both Linux and Windows.
    • Mentioned other file system options like exFAT, NTFS, or ext4 based on specific requirements.
  • Alternative Tools:
    • Mentioned the availability of GUI tools like Gparted for more flexibility, similar to Disk Manager in Windows. Screenshot1 Screenshot2 Screenshot3

Special Recognition:

Let’s give a warm round of applause to my colleague, who’s been sharing insightful blogs on our favorite topics! 🌟

Take a peek at his Medium blog, where you’ll find engaging content covering similar themes:

Explore Mudassir Waheed’s Medium Blog

Get ready to dive into a world of knowledge and inspiration! 📚✨

This post is licensed under CC BY 4.0 by the author.