Reset a lost root password from the boot loader
Practitioner25 minYour VMRHEL and Debian families
Objective
Regain root access through the console without rescue media, and leave SELinux labels correct.
Requirements
- A disposable VM with console access (Proxmox, KVM, VirtualBox). Take a snapshot first.
- No GRUB password set, or you know it.
Setup
# Optional: make the starting point realistic on the VM
sudo passwd -l root || true
getenforce 2>/dev/null || echo "no SELinux"Steps
- Reboot and interrupt the GRUB menu. Edit the default entry for one boot only.
- RHEL family: append rd.break to the linux line. Debian and Ubuntu: replace "ro quiet splash" with "rw init=/bin/bash".
- Make the real root writable, set a new root password and handle the SELinux context on RHEL.
- Continue the boot and log in as root with the new password.
Verification
sudo -k; su - -c 'id -u'
ls -Z /etc/shadow 2>/dev/null
sudo passwd -S rootShow the solution
RHEL family, after Ctrl-x with rd.break:
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel
exit
exitThe next boot relabels the filesystem and reboots once. ls -Z /etc/shadow then shows shadow_t.
Debian and Ubuntu, after Ctrl-x with init=/bin/bash:
passwd root
sync
exec /sbin/initIf passwd says "Authentication token manipulation error", root is still read-only: run mount -o remount,rw / first.