If the root password is lost, you need to interrupt the boot process and gain access to a chrooted environment.


At grub2 screen, press “e” to edit the configuration.
At the end of the line starting with “linux16”, append the following:

[...]
linux16 /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=[...] ro rd.lvm.lv=centos/swap \  
vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us \  
rhgb quiet LANG=en_US.UTF-8 rd.break enforcing=0
[...]

rd.break” interrupts the boot process.
enforcing=0” sets temporarily SELinux to “Permissive”.

Proceed with Ctrl+x to continue the boot process with the new configuration.


Mount the /sysroot folder with read and write access, and change root (chroot) to set the new root password:

switch_root:/# mount -o rw,remount /sysroot
switch_root:/# chroot /sysroot
sh-4.2# passwd
	Enter new root password:.....
	Confirm new root password:.....
sh-4.2# exit
switch_root:/# logout


The boot process is finished.
Log in as root with the new password, and reset the SELinux context of /etc/shadow :

root@localhost# restorecon -v /etc/shadow
root@localhost# reboot