RHEL 6 Filesystem Recovery and Root Password Reset
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
fscksafely 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
fsckmust be run manually
Solution Overview#
Boot the system without init using:
init=/bin/bash
This provides a root shell before password enforcement.
Step 1: Boot into Emergency Root Shell#
- Reboot the system
- At the GRUB menu, highlight the kernel
- Press
eto edit - Select the kernel line (starts with
module /vmlinuz) - Press
eagain - Append to the end of the line:
``` init=/bin/bash
```
- Press
Enter - Press
bto 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.
mount -o remount,rw /
Verify:
mount | grep ' / '
Ensure it shows rw.
Step 3: Run Filesystem Check (fsck)#
Ensure filesystem is not mounted read-write before running fsck.
mount -o remount,ro /
Run fsck on root logical volume:
fsck -f -y /dev/mapper/vg0-lv_root
Repeat for other logical volumes if present:
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:
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
Verify:
ls /proc/1
Step 5: Reset Root Password#
Ensure root filesystem is writable:
mount -o remount,rw /
Change root password:
passwd
If passwd Fails with:#
Authentication token manipulation error
Fallback method:
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:
passwd
Step 6: SELinux Relabel (Critical)#
If SELinux is enabled, run:
touch /.autorelabel
This prevents login failures on next boot.
Step 7: Reboot Normally#
exec /sbin/init
If that fails:
reboot -f
First boot may take longer due to SELinux relabeling.
Post-Recovery Checks (Recommended)#
- Verify system boots normally
- Check
/lost+foundfor recovered files - Review logs:
```bash dmesg /var/log/messages
```
- Check disk health:
```bash smartctl -a /dev/sdX
```
Security Hardening (Recommended)#
To prevent unauthorized recovery access:
- Set a GRUB password
- Restrict physical console access
- Implement regular backups
Summary Command Sequence#
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.