Scenario
The root password is unknown. You have console access and must regain root by editing the GRUB boot entry. Boot into a rescue shell, ensure SELinux policy is loaded before making changes, reset the root password, trigger an SELinux relabel, and boot back into normal mode.
This workflow is standard for RHEL-like systems. Console and boot loader access are privileged capabilities and must be treated as a security boundary.
Objective
- Interrupt GRUB and enter edit mode.
- Append a kernel argument to boot into a minimal shell.
- Boot the modified entry.
- Load SELinux policy in the rescue shell.
- Remount
/read-write. - Reset the root password.
- Create
/.autorelabelto relabel on next boot. - Continue booting into normal mode.
Concepts
- One-time GRUB edits for recovery without permanently changing boot loader configuration.
-
Init override for minimal rescue access
(
init=/bin/sh). - SELinux policy handling in rescue mode to keep labeling and authentication consistent.
-
Controlled write access by remounting
/read-write (mount -o remount,rw /). -
Password reset workflow (
passwd) and post-change relabel signaling (/.autorelabel). -
Returning to normal boot by replacing the rescue shell with
init (
exec /sbin/init).
Walkthrough
e
This edit is in-memory for the current boot only. Use it for recovery without modifying persistent GRUB configuration.
(GRUB edit screen opens)
init=/bin/sh
Appending init=/bin/sh replaces the init process
for this boot and drops you into a minimal shell. This is a
controlled recovery mode when authentication is blocked.
Ctrl+x
# OR
F10
The system should boot directly into a shell prompt without a normal login sequence.
[ OK ] Started dracut pre-pivot and cleanup hook.
[ OK ] Reached target Switch Root.
Switching root.
/bin/sh: can't access tty; job control turned off
sh-5.1#
If SELinux is enforcing, load policy before modifying authentication state. This reduces the chance of booting back into a mislabeled system.
/usr/sbin/load_policy -i
Loading policy ensures SELinux permission checks behave predictably in the rescue environment.
/usr/sbin/load_policy: done
mount -o remount,rw /
In rescue mode, / is typically mounted read-only.
Remount it read-write before updating account data.
passwd
This updates the root password in-place so normal authentication can succeed after reboot.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
touch /.autorelabel
Creating /.autorelabel forces a relabel on the
next boot. This is a standard recovery step after modifying
authentication state from a rescue shell.
exec /sbin/init
exec /sbin/init replaces the rescue shell with
the normal init process so the system can complete boot. If
relabeling runs, allow it to finish.
system is rebooting...
SELinux relabel may take several minutes.
Common breakpoints
The boot may be too fast or the menu may be hidden. Use the console and reboot again, then press the appropriate key to interrupt boot at the GRUB stage.
If passwd fails to write updates, confirm
mount -o remount,rw / succeeded and retry the
command.
If authentication fails after reboot, the system may have
labeling issues. Ensure /.autorelabel was
created and allow the relabel to complete.
The init=/bin/sh edit is one-time unless you
modified persistent GRUB config. Reboot and confirm you are
booting the normal entry without the override.
Cleanup checklist
This recovery is designed to leave the system in a normal boot state. Confirm the relabel completed and remove the relabel trigger file if it still exists.
ls -l /.autorelabel
rm -f /.autorelabel
The system boots normally, root authentication works, and relabeling completes without repeated AVC failures.
Reference
-
e: Enters GRUB edit mode for the selected boot entry. -
init=/bin/sh: Overrides the init process for a single boot and drops to a minimal shell for recovery. -
Ctrl+x/F10: Boots the modified GRUB entry. -
/usr/sbin/load_policy -i: Loads SELinux policy in rescue mode.-
-i: Initializes the policy load for the current runtime.
-
-
mount -o remount,rw /: Remounts the root filesystem read-write.-
-o: Specifies mount options. -
remount: Changes mount options without unmounting. -
rw: Enables read-write access.
-
-
passwd: Resets the password for the current user (root in this context). -
touch /.autorelabel: Triggers SELinux relabel on the next boot. -
exec /sbin/init: Starts the normal init process to resume standard boot.-
exec: Replaces the current shell with the specified process.
-
-
ls -l /.autorelabel: Confirms whether the relabel trigger file exists.-
-l: Shows long listing output including permissions and timestamps.
-
-
rm -f /.autorelabel: Removes the relabel trigger file if it remains after boot.-
-f: Removes without prompting and ignores missing files.
-