Skip to content

Reset the Root Password from the Boot Loader

This article provide the screenshot for each step: https://ankitkumarakt746.medium.com/reset-forgotten-red-hat-enterprise-linux-rhel-8-root-password-aeaa8fe17364

The instructions provided cover the steps to manually repair file-system issues during the boot process on a system running Red Hat Enterprise Linux 9. Here is a summarized and streamlined version of the process:

Repair File-system Issues at Boot

  1. Identify the Issue:

    • During boot, if the system encounters file-system issues, it may drop into an emergency shell.
    • Common issues include corrupted file systems, nonexistent devices, or incorrect UUIDs in /etc/fstab.
  2. Accessing the Emergency Shell:

    • If prompted, enter the root password to access the emergency shell.
    • Example error message during boot:
      [*     ] A start job is running for /dev/vda2 (27s / 1min 30s)
      [ TIME ] Timed out waiting for device /dev/vda2.
      [DEPEND] Dependency failed for /mnt/mountfolder
      [DEPEND] Dependency failed for Local File Systems.
      [DEPEND] Dependency failed for Mark need to relabel after reboot.
      [  OK  ] Started Emergency Shell.
      [  OK  ] Reached target Emergency Mode.
      Give root password for maintenance
      (or press Control-D to continue):
      
  3. Repair Steps:

    1. Check Mounted File Systems:

      mount
      

      • Identify if the root file system is mounted as read-only (ro).
    2. Remount Root File System as Read/Write:

      mount -o remount,rw /
      

    3. Edit /etc/fstab if Necessary:

      • Correct any errors in the /etc/fstab file (e.g., incorrect device names, UUIDs, or mount points).
    4. Create Missing Mount Points:

      mkdir -p /mnt/mountfolder
      

    5. Reload systemd Configuration:

      systemctl daemon-reload
      

    6. Attempt to Mount All File Systems:

      mount --all
      

      • This command will skip already mounted file systems and display any errors for others.
  4. Reboot the System:

    systemctl reboot
    

    • Verify that the system boots normally and all file systems are mounted correctly.

Additional Tips:

  • For quick testing, you can use the nofail option in /etc/fstab entries to allow the system to boot even if a file system fails to mount. This should not be used for critical file systems required for applications:
    UUID=xxxx-xxxx-xxxx-xxxx /mnt/mountfolder xfs defaults,nofail 0 0
    

What is /etc/fstab?

The /etc/fstab file in Linux is a system configuration file that contains information about various file systems and how they should be automatically mounted during the boot process. The name stands for "file system table."

Structure of /etc/fstab

Each line in the /etc/fstab file corresponds to a file system and contains the following fields:

  1. File System (Device)
  2. The device or partition to be mounted, specified by its device file (e.g., /dev/sda1), UUID, or label.

  3. Mount Point

  4. The directory where the file system should be mounted (e.g., /, /home, /mnt/data).

  5. File System Type

  6. The type of file system (e.g., ext4, xfs, nfs).

  7. Mount Options

  8. Options for mounting the file system (e.g., defaults, ro, rw, nofail, noatime).

  9. Dump Frequency

  10. A number indicating whether the file system should be backed up by the dump command (0 = no, 1 = yes).

  11. FSCK Order

  12. A number indicating the order in which file systems should be checked at boot time by the fsck command (0 = do not check, 1 = check first, 2 = check later).

Example of /etc/fstab Entries

Here is an example of what the /etc/fstab file might look like:

# <file system> <mount point> <type>  <options>       <dump> <fsck order>
UUID=123e4567-e89b-12d3-a456-426614174000 /            ext4    defaults        1 1
UUID=123e4567-e89b-12d3-a456-426614174001 /home        ext4    defaults        1 2
UUID=123e4567-e89b-12d3-a456-426614174002 swap         swap    defaults        0 0
UUID=123e4567-e89b-12d3-a456-426614174003 /mnt/data    xfs     defaults,nofail 0 0

Field Descriptions

  1. UUID=123e4567-e89b-12d3-a456-426614174000 / ext4 defaults 1 1
  2. Mounts the file system with UUID 123e4567-e89b-12d3-a456-426614174000 at the root directory / using the ext4 file system type with default options, backs it up (1), and checks it first during boot (1).

  3. UUID=123e4567-e89b-12d3-a456-426614174001 /home ext4 defaults 1 2

  4. Mounts the file system with UUID 123e4567-e89b-12d3-a456-426614174001 at /home using the ext4 file system type with default options, backs it up (1), and checks it second during boot (2).

  5. UUID=123e4567-e89b-12d3-a456-426614174002 swap swap defaults 0 0

  6. Uses the file system with UUID 123e4567-e89b-12d3-a456-426614174002 as swap space with default options, does not back it up (0), and does not check it during boot (0).

  7. UUID=123e4567-e89b-12d3-a456-426614174003 /mnt/data xfs defaults,nofail 0 0

  8. Mounts the file system with UUID 123e4567-e89b-12d3-a456-426614174003 at /mnt/data using the xfs file system type with default options and the nofail option, does not back it up (0), and does not check it during boot (0).

Common Mount Options

  • defaults: Uses the default mount options (rw, suid, dev, exec, auto, nouser, and async).
  • ro: Mounts the file system as read-only.
  • rw: Mounts the file system as read/write.
  • nofail: Allows the system to continue booting even if the file system cannot be mounted.
  • noatime: Prevents updating the access time on files (useful for performance).

Usage

The /etc/fstab file is crucial for system booting and for ensuring that all necessary file systems are available for use. It allows for automated and consistent mounting of file systems, which helps maintain system stability and reliability.