- 论坛徽章:
- 0
|
Overview
The basic idea behind this is to boot from the LiveCD, chroot into your system, and run the passwd program to change the root password. Because you are 'inside' the Gentoo environment on your hard drive, your password on your hard drive will be the one that is updated.
Note: If possible, it is much simpler to append "single" to the kernel options in your bootloader. The system will start up in a minimal runlevel, dropping you off at a shell as root without prompting for a password. The passwd command can then be used to change the forgotten password as below.
[edit]
Procedure
Boot from the LiveCD. Any of them will do, as long as it matches your architecture. From the LiveCD prompt, you want to mount your Linux partitions. You will probably want to mount every partition that would otherwise be mounted if you booted normally. Consider the following partition table (this is the default partition table in the gentoo 2005.1 handbook):
Partition Mount Point
/dev/hda1 /boot
/dev/hda2 swap
/dev/hda3 /
In this case, nothing more than hda3 is necessary. However, when in doubt, mount it. Here is how you would go about that:
mount /dev/hda3 /mnt/gentoo
mount /dev/hda1 /mnt/gentoo/boot
mount -t proc none /mnt/gentoo/proc
The last mount command mounts the special /proc directory, because certain programs will request access to it. Remember: order matters! /boot and /proc are all inside /, which is why they are mounted AFTER / itself! Also, for such a small excursion into your system, you probably will not need to activate your swap.
Now that your system is mounted, the next step is to chroot into it. This step is easy enough; simply run the following command:
chroot /mnt/gentoo /bin/bash
Your prompt will change slightly to reflect the transition from the LiveCD environment to your computer. As far as the programs know, you have just logged into the root account on your hard drive. So change your password:
passwd
Type exit to exit the chroot, and reboot to reboot the machine. Take out the LiveCD before the boot process starts, and you should now be able to log into your machine as root with the password you just set. |
|