Operations 5 min read

How to Reset a Forgotten Linux Root Password via Initramfs

This guide explains the Linux boot sequence, the role of GRUB2, initramfs, and systemd, then walks through a step‑by‑step method to break a lost root password by interrupting the boot process, remounting the filesystem, and resetting the password.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Reset a Forgotten Linux Root Password via Initramfs

Linux system boot process:

1. Power‑on self‑test (POST) initializes hardware.

2. The firmware searches for bootable devices (e.g., a disk’s MBR).

3. The bootloader (GRUB2) is loaded and control is handed to it.

4. GRUB2 loads its configuration and displays the boot menu.

5. GRUB2 loads the kernel and the initramfs image into memory.

6. Control is transferred from GRUB2 to the kernel.

7. The kernel searches for drivers in initramfs and starts /sbin/init as PID 1 (in RHEL 7 this is systemd together with the udev daemon).

8. systemd executes all units of initrd.target, which mounts the filesystem to /sysroot.

9. The kernel switches the root filesystem from the initramfs root to the real system root located at /sysroot.

10. systemd looks for the default target and starts all units belonging to that target.

The default target’s units are shown in the following diagram:

Root password reset procedure

The basic idea is to interrupt the boot process after the kernel is loaded, drop into the initramfs environment, remount /sysroot with write permissions, chroot into it, and use passwd to set a new password.

Experimental environment : a RHEL 7 virtual machine installed via KVM.

Set an arbitrary root password to simulate a forgotten password.

Reboot the VM and, at the GRUB menu, press e to edit the boot entry.

In the editor, locate the line beginning with linux16 and replace the ro parameter with rd.break.

Boot with the modified parameters; the system stops in initramfs.

Remount /sysroot as read‑write:

mount -o remount,rw /sysroot

Change root into the real filesystem:

chroot /sysroot

Reset the password: passwd root Then create /.autorelabel to trigger SELinux relabeling.

Exit the chroot twice and reboot the system.

After reboot, log in with the new root password.

LinuxRHEL7systemdRoot password resetInitramfs
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.