KB
Backup & Recovery

RHEL 6 Filesystem Recovery and Root Password Reset

3 min read580 words17 code blocks

At a glance#

  • Purpose: Recover a RHEL 6 system with a corrupted filesystem and reset its root password.
  • Applies to: RHEL and CentOS 6.
  • Risk: High - requires single-user mode, downtime, and filesystem repair.
  • Time: About 1 hour.

Scope#

This document describes how to:

  • Recover a corrupted filesystem after sudden power loss
  • Run fsck safely on an LVM root filesystem
  • Access a root shell without knowing the root password
  • Reset the root password
  • Restore normal boot on Red Hat Enterprise Linux 6

This procedure requires full console access and assumes the system is authorized for recovery.


Environment#

  • OS: Red Hat Enterprise Linux 6
  • Bootloader: GRUB 0.97
  • Storage: LVM (/dev/mapper/vg*-lv_*)
  • Filesystem: ext3/ext4

Problem Description#

After an unclean shutdown:

  • System fails filesystem checks
  • Boot drops to maintenance mode
  • Root password is required but unavailable
  • fsck must be run manually

Solution Overview#

Boot the system without init using:

text
init=/bin/bash

This provides a root shell before password enforcement.


Step 1: Boot into Emergency Root Shell#

  1. Reboot the system
  2. At the GRUB menu, highlight the kernel
  3. Press e to edit
  4. Select the kernel line (starts with module /vmlinuz)
  5. Press e again
  6. Append to the end of the line:

``` init=/bin/bash

```

  1. Press Enter
  2. Press b to boot

Result: You are dropped into a root shell without password checks.


Step 2: Remount Root Filesystem#

Root filesystem is mounted read-only by default.

bash
mount -o remount,rw /

Verify:

bash
mount | grep ' / '

Ensure it shows rw.


Step 3: Run Filesystem Check (fsck)#

Ensure filesystem is not mounted read-write before running fsck.

bash
mount -o remount,ro /

Run fsck on root logical volume:

bash
fsck -f -y /dev/mapper/vg0-lv_root

Repeat for other logical volumes if present:

bash
fsck -f -y /dev/mapper/vg0-lv_var
fsck -f -y /dev/mapper/vg0-lv_home

Expected output:

  • Orphaned inodes fixed
  • Bitmap differences corrected
  • Filesystem marked as modified

Step 4: Prepare Environment for Password Change#

Mount required virtual filesystems:

bash
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev

Verify:

bash
ls /proc/1

Step 5: Reset Root Password#

Ensure root filesystem is writable:

bash
mount -o remount,rw /

Change root password:

bash
passwd

If passwd Fails with:#

text
Authentication token manipulation error

Fallback method:

bash
sed -i 's|^root:[^:]*:|root::|' /etc/shadow

This clears the root password temporarily.

After reboot, log in as root with no password and immediately set a new one:

bash
passwd

Step 6: SELinux Relabel (Critical)#

If SELinux is enabled, run:

bash
touch /.autorelabel

This prevents login failures on next boot.


Step 7: Reboot Normally#

bash
exec /sbin/init

If that fails:

bash
reboot -f

First boot may take longer due to SELinux relabeling.


Post-Recovery Checks (Recommended)#

  • Verify system boots normally
  • Check /lost+found for recovered files
  • Review logs:

```bash dmesg /var/log/messages

```

  • Check disk health:

```bash smartctl -a /dev/sdX

```


To prevent unauthorized recovery access:

  • Set a GRUB password
  • Restrict physical console access
  • Implement regular backups

Summary Command Sequence#

bash
init=/bin/bash
mount -o remount,rw /
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
fsck -f -y /dev/mapper/vg0-lv_root
passwd
touch /.autorelabel
exec /sbin/init

Notes#

  • This procedure is specific to RHEL 6 and GRUB 0.97
  • Newer RHEL versions use different recovery mechanisms
  • Always ensure legal and administrative authorization before performing recovery

End of document.