|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
The first thing to try is to boot to single user mode. This MIGHT not
work for you, because your system might be configured to still ask for a root
password to get to single user mode. If that's the case, we'll use another trick
that replaces init with /bin/bash.
You can try single user mode it it is not password protected. .In GRUB, hit 'e", then
select the "kernel" line, hit "e" again, and add " single" (or just " 1") to the
end of the line. Press ENTER, and then "b" to boot.
You should get a fairly normal looking boot sequence except that it terminates a
little early at a bash prompt. If you get a "Give root password for system
maintenance", this isn't going to work and you need to use init=/bin/bash tric
descibed below
If you do get the prompt, the / filesystem may not be mounted rw (although
"mount" may say it is). Do
mount -o remount,rw /
If that doesn't work (it might not), just type "mount" to find out where "/" is
mounted. Let's say it is on /dev/sda2. You'd then type:
mount -o remount,rw /dev/sda2
On many distros the 'single' or 'rescue' boot will still ask for a password.
You can get around this by starting linux without starting initd, just launch a
shell instead; and it's blindingly fast.
'e' to edit the boot entry, select the kernel line and press 'e' again, then
type "init=/bin/bash", enter, press 'b' to boot it. You end up at a root prompt
with / mounted read-only. (depending on the distro, you might need /bin/sh
instead)
# mount / -o remount,rw
# passwd
<change your root password here>
# mount / -o remount,ro
<three-finger salute or hit the reset button>
It's also useful for fixing up boot problems, if you're silly enough to have put
commands in various init scripts that don't actually exit or daemonize...
The Linux and Unix Menagerie Using Grub To Change RedHat Linux's Root Password
08/06/2008 - Thanks for this Additional Useful Information From zcat:
On many distros the 'single' or 'rescue' boot will still ask for a password. You can get around this by starting linux without starting initd, just launch a shell instead; and it's blindingly fast.
'e' to edit the boot entry, select the kernel line and press 'e' again, then type "init=/bin/bash", enter, press 'b' to boot it. You end up at a root prompt with / mounted read-only. (depending on the distro, you might need /bin/sh instead)
# mount / -o remount,rw
# passwd
<change your root password here>
# mount / -o remount,ro
<three-finger salute or hit the reset button>
It's also useful for fixing up boot problems, if you're silly enough to have put commands in various init scripts that don't actually exit or daemonize...
By the way, when you do init=/bin/sh (or bash), it isn't strictly necessary to reboot afterwards (well, depending on what you change I suppose), you can just do an 'exec /sbin/init' to continue the boot process. Make sure the state of the system is as it would normally be though (e.g. umount /usr, make / readonly again etc).
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: August 20, 2008