顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

2008年1月13日 星期日

Linux GRUB 修復

重裝Windows 時把GRUB覆蓋掉,需要恢復GRUB(也稱重裝GRUB)。
在Fedora/RHEL/CentOS 4.x下,有個簡單的辦法。用安裝盤引導,啟動畫面出現後輸入
# linux rescue
進入救援模式,其中會問是否挂載XXX ,選挂載。接著改變根目錄“/ ”,並安裝GRUB,完成後重啟即可。
# chroot /mnt/sysimage # grub-install /dev/hda
(如果你的是SATA,上面的命令參數是/dev/sda)
有時上面的方法可能不奏效。另外,新版的Fedora也用Live CD 了,上面的方法好像不能用。
下面介紹的方法就更通用,對不同的發行版都一樣,也還沒遇到不可行的情況。(tipfoo@gmail_com
用Live CD (Ubuntu的就是Desktop CD或者DVD )啟動,打開終端(Applications→Accessory →Terminal),執行以下代碼(是root用戶就不用加sudo了):
$ sudo grub grub> find /boot/grub/stage1 grub> root (hdX ,Y )
grub> setup (hdX )
grub> quit
注意1 :這裡的grub> 是grub環境的提示符,不用輸入。
注意2 :其中的X 、Y 是執行find /boot/grub/stage1命令後系統提示的。比如下面這種情況,X 就是0 ,Y 就是7.:
grub> find /boot/grub/stage1(hd0 ,7 )
注意3 :如果find命令,沒返回可用的結果,那就是/boot 單獨在一個分區中,用下面的命令可得到:
grub> find /grub/stage1
以上幾條命令的詳細解釋(tipfoo@gmail-com):sudo grub ◆以root用戶身份啟動grub find /boot/grub/stage1 ◆尋找/boot 所在分區root(hdX ,Y )◆設置硬盤hdX 的根文件系統(“/ ”),實際就是設置/boot 所在的分區setup(hdX )◆安裝GRUB到硬盤hdX. quit ◆退出GRUB

HOWTO: Recover root password

A common problem faced by new users ( and sometimes even experienced users ) is not knowing what to do when they lose their password. Even worse, when they lose the password for 'root'. Luckily, there are several solutions to help you recover access to your system.
Root Password - Easy Method:The simplest way to recover from a lost password is to boot into single user mode.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), enter:
Code:linux single
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:
Code:passwd
The instructions for GRUB users are similar. Press 'e' at the GRUB prompt to select boot parameters. Select the line for the kernel you want to boot, and go to the end of it. Add "single" as a separate word, and then press ENTER to exit the edit mode. Once back at the GRUB screen, press "b" to boot into single user mode. Root Password - Not As Easy Method:If for whatever reason, the above solution doesn't work for you, there is another option. Boot using a so called "Live CD" Linux distribution, such as Knoppix. For the purposes of this example, it will be assumed that the user is using Knoppix.After booting up from the Knoppix CD, go to a terminal and su to root (no password is required). After your priviledges have been escalated, issue the following commands (be sure to replace each /hda1 with your own root ('/') partition):
Code:mount -o dev,rw /mnt/hda1 cd /mnt/hda1/etc
Once you are into your system /etc directory, you can use a text-editor (such as 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:
Code:root:$1$aB7mx0Licb$CTbs2RQrfPHkz5Vna0.fnz8H68tB.:/10852:0:99999:7:::
(The '/' indicates a line continuation)
Now, using your favorite editor (I'll use vim) delete the password hash (the green text).
Code:vim shadow
After you've edited this field, it should look like this:
Code:root::10852:0:99999:7:::
Now save the file and change back to the root directory and unmount the system root partition (don't forget to change the /hda1) as follows:
Code:cd / umount /mnt/hda1
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:
Code:
passwd
Forgotten or Lost "User" Password:If a regular user forgets his/her password, the root user can easily reset the user's password. For this example, the username will be "bob".Enter (as root):
Code:passwd bob
This will prompt for a new password for the user "bob".