Gentoo Linux - Restoring the root password

October 2016

If you lose your root password the easiest way to recover it is to use the LiveCD
  • Boot with the LiveCD
  • Launch the fdisk command and then use the p option for the device on your boot partition and root.

# fdisk  /dev/sda

The number of cylinders for this disk is set to 9726.  
There is nothing wrong with that, but this is larger than 1024,  
and could in certain setups cause problems with:  
1) software that runs at boot time (e.g., old versions of LILO)  
2) booting and partitioning software from other OSs  
   (e.g., DOS FDISK, OS/2 FDISK)  

Command (m for help): p  

Disk /dev/sda: 80.0 GB, 80000000000 bytes  
255 heads, 63 sectors/track, 9726 cylinders  
Units = cylinders of 16065 * 512 = 8225280 bytes  
Disk identifier: 0xa08da08d  

   Device Boot      Start         End      Blocks   Id  System  
/dev/sda1   *           1          13      104391   83  Linux  
/dev/sda2              14         256     1951897+  82  Linux swap / Solaris  
/dev/sda3             257        9726    76067775   83  Linux  
  • Mount the sda3 partition (or equivalent)

# mount /dev/sda3 /mnt/gentoo  
  • Use chroot command in the mounted environment

# chroot /mnt/gentoo /bin/bash  
# env-update  
>> Regenerating /etc/  
# source /etc/profile  
# export PS1="(chroot) $PS1"  
  • Change the root password

  • Reboot without Live CD

If you do not have a LiveCD, you must reboot the system in single user mode to reset the user password.
At Kernel level the following changes must be made init=/bin/sh (via bootloader menu).
When the system starts, it will launch a root shell, the drive will be mounted as read-only mode and you ,ust set it to write/read mode, in the following command ROOT must be replaced by root partition.

mount -o rw,remount /dev/ROOT

Then edit etc/shadow and remove the encrypted password. Reset the root password with the passwd command and reboot the system.

Related :

This document entitled « Gentoo Linux - Restoring the root password » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.