Step 1: Boot into another Linux system
This can be any other Linux system on your computer. It can be another installed distribution, or a live CD such as RIP (Recovery is Possible) or Knoppix.
Step 2: Open a terminal
If you have booted into a system such as Knoppix or the Ubuntu Live CD, you will need to open a terminal first. Alternatively, you can switch to a virtual terminal by pressing CTRL+ALT+F2. You will need root access on this system to gain access to your system.
Step 3: Mount your root filesystem to be rescued
This will be the filesystem that contains your /bin, /etc and /sbin directories, typically /dev/sda1 or /dev/hda1.
Typing the following can give you a list of partitions with sizes, this might give you a clue as to which partition your root partition is:
To mount your root partition, type:
#mount /dev/hda1 /mnt – (Ubuntu Live CD: #sudo mount /dev/hda1 /mnt)
To gain access to your system, type:
#chroot /mnt – (Ubuntu Live CD: #sudo chroot /mnt)
You will now have full access to your old system. To change your root password, type:
#passwd (username if not root – Ubuntu: it’s mandatory to add the username here)
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
To exit from the chroot, type ‘exit’. You can now reboot (by typing ‘reboot’ and to press enter’) and gain root access to your system again.