Live CD — Boot from a livecd as normal.
In terminal become root i.e. su -
Chroot into the partition i.e. : chroot /mnt/hda1 /bin/bash
then change password with passwd command i.e. passwd
this will change the entry in /etc/shadow for the root password.
Conventional Way. Boot with the live-disk then go to a terminal and su to root (no password is required) then issue the following commands (be sure to replace each /sda1 with your own root partition device):
mount -o dev,rw /dev/hda1 /mnt/sda1 cd /mnt/sda1/etc
Once you are into your system /etc directory, you can use a text editor (vim, nano, pico, etc.) to edit the /etc/shadow file where the password is stored. Various information about root and user accounts is kept in this plain-text file but we are only concerned with the password portion.
For example, the /etc/shadow entry for the “root” account may look something like this:
Now, using your favourite editor (I’ll use vim) delete the password hash. For this example, the password is in green text and is all those characters between the 1st and 2nd colons.
After you’ve edited this field, it should look like this:
Now save the file and change back to the root directory and unmount the system root partition (don’t forget to change the /sda1) as follows:
cd / umount /mnt/sda1
Now reboot the computer.
Once the computer has booted and you’re at the login prompt, type “root” and when asked for the password just press ENTER (entering no password). After a successful login, you need to set the new password for root using the following command:
Single User mode
For LILO users:
If you are using LILO, at the LILO boot prompt (graphical LILO users can press Ctrl-x to exit the graphical screen and go to the boot: prompt), and then enter:
This will make you the “root” user without asking for a password. Once the system has booted, you can change the root password using the password command:
For GRUB users:
when the GRUB menu appears, use arrow keys to choose OS to be booted
press letter “e” on the keyboard to enter edit mode
use arrow keys to select the kernel line for kernel to be booted
press “e” to edit line
go to end of line and type “single” (without quotes) as a separate word
press ESC key to exit the edit mode
press “b” to boot into single user mode
then excuate following command
mount -t proc proc /proc
mount -o remount,rw /
2.编辑kernel 那行最后加上S (或者Single）
# mount -t proc proc /proc
# mount -o remount,rw /