202.2 System recovery (weight: 4)

Tech Tutorial: 202.2 System Recovery #

In this tutorial, we will delve into the topic of system recovery for Linux systems. This is a crucial skill for system administrators, as it addresses methods to recover a system from backup data or by repairing problematic issues that prevent the system from starting normally.

Exam Objective #

The objective focuses on understanding the tools and techniques necessary to recover Linux systems from various failures or system issues.

Weight: 4 #

This denotes the importance and the level of detail required for mastering this topic within the scope of Linux administration exams.

Key Knowledge Areas: #

  • Understanding the boot process and recovery mode.
  • Recovery operations using single user mode and rescue media.
  • Using system tools to fix common filesystem issues.

Utilities: #

  • fsck
  • mount
  • umount
  • shutdown
  • reboot

Introduction #

When a Linux system fails to boot, or experiences severe operational issues, having knowledge of recovery techniques is invaluable. This involves understanding the Linux boot process, how to interact with recovery and single-user modes, and how to use various system utilities to diagnose and repair common issues like filesystem corruption.

Step-by-Step Guide #

1. Understanding and Accessing Recovery Mode #

Recovery mode, also known as single-user mode, is a minimal boot environment where only essential services are started. This mode is used to perform system recovery tasks.

Accessing Recovery Mode: #

  1. Restart your Linux system.
  2. Hold down the appropriate key (usually Shift or Esc) during boot to bring up the GRUB menu.
  3. Choose the recovery mode option from the GRUB menu.

2. Common Recovery Tasks #

Checking and Repairing Filesystems with fsck #

fsck (File System Consistency Check) is used to check and repair Linux filesystems. It’s crucial not to run fsck on a mounted filesystem to avoid data corruption.

# To check and repair a filesystem on /dev/sda1
umount /dev/sda1
fsck -y /dev/sda1
  • -y option automatically fixes any errors found.

Mounting and Unmounting Filesystems #

Mounting filesystems is essential for accessing the data on them, and unmounting is equally important for safely detaching filesystems.

# Mount a filesystem
mount /dev/sda1 /mnt

# Unmount a filesystem
umount /mnt

3. Using Rescue Media #

Rescue media, such as a live CD or USB, can be used if the system does not boot at all. Boot from the rescue media and mount the system root filesystem to perform recovery tasks.

# Assuming /dev/sda1 is the root partition and it's mounted on /mnt
mount /dev/sda1 /mnt
chroot /mnt

4. System Reboot and Shutdown #

Understanding how to properly reboot or shutdown the system is crucial especially in a recovery scenario to avoid further damage.

# Reboot the system
reboot

# Shutdown the system
shutdown now

Detailed Code Examples for Every Command #

fsck Example:

# Force a check even if the filesystem seems clean
fsck -f /dev/sda2

mount and umount Example:

# Mount with specific options, e.g., read-only
mount -o ro /dev/sda2 /mnt/data

# Unmount forcefully
umount -f /mnt/data

shutdown and reboot Example:

# Schedule a shutdown for 5 minutes later
shutdown +5 "System going down for maintenance."

# Reboot with a message
reboot --message="Applying important updates."

Conclusion #

Mastering system recovery techniques is essential for every Linux system administrator. This includes not only understanding how to use tools like fsck, mount, and shutdown, but also knowing when and how to use them effectively. Practicing these commands and procedures in a controlled environment will prepare you for unforeseen system emergencies in real-world scenarios.